Class: Common

Common


new Common()

Commonly required things. Helper functions and constants.
Source:

Members


<static> fmtDAPIErr

Format a Discord API error.
Source:

<static, constant> guildSaveDir :string

The root file directory for finding saved data related to individual guilds.
Type:
  • string
Source:

<static, constant> logChannel :string

The channel id for the channel to send general log messages to.
Type:
  • string
Source:

<static> mention

Creates formatted string for mentioning the author of msg.
Source:

<static, constant> spikeyId :string

SpikeyRobot's Discord ID.
Type:
  • string
Source:

<static, constant> testChannel :string

The channel id for the channel to reserve for only unit testing in.
Type:
  • string
Default Value:
  • 439642818084995074
Source:

<static, constant> trustedIds :Array.<string>

Trusted IDs.
Type:
  • Array.<string>
Source:
See:
  • Common.prototype.trustedIds

<static, constant> ua :string

The User-Agent to send in http request headers.
Type:
  • string
Source:

<static, constant> userSaveDir :string

The root file directory for finding saved data related to individual users.
Type:
  • string
Source:

<static, constant> webHelp :string

The website full URL for commands help page.
Type:
  • string
Source:

<static, constant> webPath :string

The website path for more help and documentation.
Type:
  • string
Source:

<static, constant> webURL :string

The website base URL for pointing to for more help and documentation.
Type:
  • string
Source:

<constant> guildSaveDir :string

The root file directory for finding saved data related to individual guilds.
Type:
  • string
Default Value:
  • ./save/guilds/
Source:

isRelease :boolean

Whether this should be shown as a release version, or a debug version in the log.
Type:
  • boolean
Source:

isTest :boolean

Whether this current instance is running as a unit test.
Type:
  • boolean
Source:

<constant> logChannel :string

The channel id for the channel to send general log messages to.
Type:
  • string
Default Value:
  • 473935520821673991
Source:

<constant> spikeyId :string

SpikeyRobot's Discord ID. If you are self-hosting SpikeyBot, change this to your account ID to be able to give yourself full access to all features of the bot.
Type:
  • string
Default Value:
  • 124733888177111041
Source:

<constant> trustedIds :Array.<string>

Discord IDs that are allowed to reboot the bot, and are overall trusted individuals/accounts.
Type:
  • Array.<string>
Source:

<constant> userSaveDir :string

The root file directory for finding saved data related to individual users.
Type:
  • string
Default Value:
  • ./save/users/
Source:

<constant> webHelp :string

The website full URL for commands help page.
Type:
  • string
Source:

<constant> webPath :string

The website path for more help and documentation.
Type:
  • string
Default Value:
  • help/
Source:

<constant> webURL :string

The website base URL for pointing to for more help and documentation.
Type:
  • string
Default Value:
  • https://www.spikeybot.com/
Source:

<private, inner, constant> app :string

The script's filename to show in the log.
Type:
  • string
Source:

<private, inner> mycolor :number

The color code to prefix log messages with for this script.
Type:
  • number
Source:

<private, inner, constant> prefixLength :number

The number of characters reserved for the filename of the script.
Type:
  • number
Default Value:
  • 14
Source:

<private, inner> title :string

The final formatted filename for logging.
Type:
  • string
Source:

Methods


<private, static> camelToSpaces(str)

Convert a string in camelcase to a human readable spaces format. (helloWorld --> Hello World).
Parameters:
Name Type Description
str string The input.
Source:
Returns:
The output.
Type
string

<static> connectSQL( [force])

Create initial connection with sql server. The connection is injected into the global scope as sqlCon. If a connection still exists, calling this function just returns the current reference.
Parameters:
Name Type Argument Default Description
force boolean <optional>
false Force a new connection to be established.
Source:
Returns:
Current sql connection object.
Type
sql.ConnectionConfig

<static> deepFreeze(object)

Recursively freeze all elements of an object.
Parameters:
Name Type Description
object object The object to deep freeze.
Source:
Returns:
The frozen object.
Type
object

<static> mkAndWrite(filename, dir, data [, cb])

Write data to a file and make sure the directory exists or create it if it doesn't. Async.
Parameters:
Name Type Argument Description
filename string The name of the file including the directory.
dir string The directory path without the file's name.
data string | object The data to write to the file.
cb function <optional>
Callback to fire on completion. Only parameter is optional error.
Source:
See:
  • Common~mkAndWriteSync

<static> mkAndWriteSync(filename, dir, data)

Write data to a file and make sure the directory exists or create it if it doesn't. Synchronous.
Parameters:
Name Type Description
filename string The name of the file including the directory.
dir string The directory path without the file's name.
data string The data to write to the file.
Source:
See:
  • Common~mkAndWrite

begin(isTest, isRelease)

Initialize variables and settings for logging properly.
Parameters:
Name Type Description
isTest boolean Is this running as a test.
isRelease boolean Is this a release version, or a development version of the app running.
Source:

error(message, ip [, traceIncrease])

Format an error message to be logged.
Parameters:
Name Type Argument Default Description
message string The message to display.
ip string The IP address or unique identifier of the client that caused this event to happen.
traceIncrease number <optional>
0 Increase the distance up the stack to show the in the log.
Source:

fmtDAPIErr(e)

Format a Discord API error.
Parameters:
Name Type Description
e Discord~DiscordAPIError DiscordAPIError to format into a string.
Source:
Returns:
Error formatted as single line string.
Type
string

getIPName(ip)

Formats a given IP address by padding with zeroes, or completely replacing with a human readable alias if the address is a known location.
Parameters:
Name Type Description
ip string The ip address to format.
Source:
Returns:
The formmatted address.
Type
string

log(message, ip [, traceIncrease])

Format a log message to be logged.
Parameters:
Name Type Argument Default Description
message string The message to display.
ip string The IP address or unique identifier of the client that caused this event to happen.
traceIncrease number <optional>
0 Increase the distance up the stack to show the in the log.
Source:

logDebug(message, ip [, traceIncrease])

Format a log message to be logged. Prefixed with DBG.
Parameters:
Name Type Argument Default Description
message string The message to display.
ip string The IP address or unique identifier of the client that caused this event to happen.
traceIncrease number <optional>
0 Increase the distance up the stack to show the in the log.
Source:

logWarning(message, ip [, traceIncrease])

Format a log message to be logged. Prefixed with WRN.
Parameters:
Name Type Argument Default Description
message string The message to display.
ip string The IP address or unique identifier of the client that caused this event to happen.
traceIncrease number <optional>
0 Increase the distance up the stack to show the in the log.
Source:

mention(msg)

Creates formatted string for mentioning the author of msg.
Parameters:
Name Type Description
msg Discord~Message | Discord~UserResolvable Message to format a mention for the author of.
Source:
Returns:
Formatted mention string.
Type
string

padIp(str)

Pad an IP address with zeroes.
Parameters:
Name Type Description
str number The ipv4 address as a string to format.
Source:
Returns:
The padded address.
Type
string

reply(msg, text [, post])

Replies to the author and channel of msg with the given message.
Parameters:
Name Type Argument Description
msg Discord~Message Message to reply to.
text string The main body of the message.
post string <optional>
The footer of the message.
Source:
Returns:
Promise of Discord~Message that we attempted to send, or null if error occurred before attempting to send.
Type
Promise

updatePrefix(ip)

Format a prefix for a log message or error. Includes the ip before the message.
Parameters:
Name Type Description
ip string The ip to include in the prefix.
Source:
Returns:
The formatted prefix for a log message.
Type
string

<private, inner> __filename( [inc])

Gets the name of the file that called a log function.
Parameters:
Name Type Argument Default Description
inc number <optional>
0 Increase distance up the stack to returns.
Source:
Returns:
Filename in call stack.
Type
string

<private, inner> __line( [inc])

Gets the line number of the function that called a log function.
Parameters:
Name Type Argument Default Description
inc number <optional>
0 Increase distance up the stack to returns.
Source:
Returns:
Line number of call in stack.
Type
number

<private, inner> getTrace( [traceIncrease])

Gets the name and line number of the current function stack.
Parameters:
Name Type Argument Default Description
traceIncrease number <optional>
0 Increase the distance up the stack to show the in the log.
Source:
Returns:
Formatted string with length 24.
Type
string

<private, inner> write(prefix, message, ip [, traceIncrease])

Write the final portion of the log message.
Parameters:
Name Type Argument Default Description
prefix string The first characters on the line.
message string The message to display.
ip string The IP address or unique identifier of the client that caused this event to happen.
traceIncrease number <optional>
0 Increase the distance up the stack to show the in the log.
Source: