new Common()
Commonly required things. Helper functions and constants.
- Source:
Members
-
<static, constant> avatarURL :string
-
The website base URL for pointing to for avatar files.
Type:
- string
- Source:
-
<static, constant> encryptAvatars :boolean
-
Whether to use the encryption specified in auth.js to encrypt users' avatars. Could make it more difficult to serve the images if enabled.
Type:
- boolean
- Source:
-
<static> fileFetchDelay :number
-
Cooldown after fetching a file from other shards before requesting the new version again.
Type:
- number
- Default Value:
-
- 30 seconds
- Source:
-
<static> fileFetchHist :object.<number>
-
Filenames and the timestamp they were last fetched from or sent to other shards.
Type:
- object.<number>
- Default Value:
-
- {}
- Source:
-
<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> shardConfigRegex :RegExp
-
Regular expression the name of the config file will match for a shard configuration.
Type:
- RegExp
- 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> avatarURL :string
-
The website base URL for pointing to for avatar files.
Type:
- string
- Default Value:
-
- https://kamino.spikeybot.com/
- Source:
-
<constant> encryptAvatars :boolean
-
Whether to use the encryption specified in auth.js to encrypt users' avatars. Could make it more difficult to serve the images if enabled.
Type:
- boolean
- Source:
-
<constant> guildSaveDir :string
-
The root file directory for finding saved data related to individual guilds.
Type:
- string
- Default Value:
-
- ./save/guilds/
- Source:
-
isMaster :boolean
-
Is this a shard that is being managed by our sharding system, and is the master that all children (siblings) will be connecting to. If this is true, webservers should attempt to become the master, and not fallback to a client sibling. This is specified using the `SHARDING_MASTER` environment variable.
Type:
- boolean
- Default Value:
-
- false
- Source:
-
isRelease :boolean
-
Whether this should be shown as a release version, or a debug version in the log.
Type:
- boolean
- Source:
-
isSlave :boolean
-
Is this a shard that is being managed by our sharding system. If this is true, webservers should not attempt to become the master, and instead attempt to connect to the sharding master server. This is specified using the `SHARDING_SLAVE` environment variable.
Type:
- boolean
- Default Value:
-
- false
- 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:
-
<private, nullable> masterHost :object
-
The network host information where the master node is located for connecting sibling sockets to. This will be populated if `isSlave` is true.
Type:
- object
- Source:
-
<constant> shardConfigRegex :RegExp
-
Regular expression the name of the config file will match for a shard configuration.
Type:
- RegExp
- Default Value:
-
- /^shard_[a-z]+_config\.json$/
- 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 strstring 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 forceboolean <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 objectobject The object to deep freeze. - Source:
Returns:
The frozen object.- Type
- object
-
<static> mkAndWrite(filename, dir, data [, cb], encrypt)
-
Write data to a file and make sure the directory exists or create it if it doesn't. Async.
Parameters:
Name Type Argument Description filenamestring The name of the file including the directory. dirstring The directory path without the file's name. datastring | object The data to write to the file. cbfunction <optional>
Callback to fire on completion. Only parameter is optional error. encryptboolean Encrypt and append ".crypt" to filename if true - 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 filenamestring The name of the file including the directory. dirstring The directory path without the file's name. datastring The data to write to the file. - Source:
- See:
-
- Common~mkAndWrite
-
<static> parse(str [, cb])
-
Parse a JSON string.
Parameters:
Name Type Argument Description strstring String to parse. cbfunction <optional>
Callback once completed, with optional error parameter, and parameter of parsed data. - Source:
-
<static> readAndParse(filename [, cb])
-
Read a file's contents, checks other shards for newer version first, and parse the file's contents info from JSON to objects. This does not have a synchronous version as the whole point of this is to potentially fetch a newer file from another server.
Parameters:
Name Type Argument Description filenamestring The name of the file to read and parse. cbfunction <optional>
Callback once completed, with optional error parameter, and parameter of parsed contents. - Source:
-
<static> readFile(filename [, cb] [, encrypt])
-
Read a file's contents, checks other shards for newer version first. This does not have a synchronous version as the whole point of this is to potentially fetch a newer file from another server.
Parameters:
Name Type Argument Default Description filenamestring The name of the file to read. cbfunction <optional>
Callback once completed, with optional error parameter, and parameter of file contents from `fs.readFile`. encryptboolean <optional>
true Enable encryption. - Source:
-
<static> unlink(filename [, cb])
-
Delete data from file, and mark it for deletion from other shards.
Parameters:
Name Type Argument Description filenamestring The name of the file to remove. cbfunction <optional>
Callback once completed, with optional error parameter. - Source:
-
<static> unlinkSync(filename)
-
Delete data from file, and mark it for deletion from other shards. Synchronous.
Parameters:
Name Type Description filenamestring The name of the file to remove. - Source:
-
begin(isTest, isRelease)
-
Initialize variables and settings for logging properly.
Parameters:
Name Type Description isTestboolean Is this running as a test. isReleaseboolean 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 messagestring The message to display. ipstring The IP address or unique identifier of the client that caused this event to happen. traceIncreasenumber <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 eDiscord~DiscordAPIError DiscordAPIError to format into a string. - Source:
Returns:
Error formatted as single line string.- Type
- string
-
getFile(filename, cb)
-
Request that the ShardingSlave fetches a file from the ShardingMaster.
Parameters:
Name Type Description filenamestring The name of the file to fetch with path relative to project directory. cbfunction Callback with optional error. - Source:
-
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 ipstring 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 messagestring The message to display. ipstring The IP address or unique identifier of the client that caused this event to happen. traceIncreasenumber <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 messagestring The message to display. ipstring The IP address or unique identifier of the client that caused this event to happen. traceIncreasenumber <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 messagestring The message to display. ipstring The IP address or unique identifier of the client that caused this event to happen. traceIncreasenumber <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 msgDiscord~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 strnumber 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 msgDiscord~Message Message to reply to. textstring The main body of the message. poststring <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
-
sendFile(filename, cb)
-
Request that the ShardingSlave sends a file to the ShardingMaster.
Parameters:
Name Type Description filenamestring The name of the file to send with path relative to project directory. cbfunction Callback with optional error. - Source:
-
sendSQL(query, cb)
-
Send an SQL query to the master database through our open websocket.
Parameters:
Name Type Description querystring SQL query to send directly to the database. cbfunction Callback with optional error, otherwise returned rows. - Source:
-
updatePrefix(ip)
-
Format a prefix for a log message or error. Includes the ip before the message.
Parameters:
Name Type Description ipstring 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 incnumber <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 incnumber <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 traceIncreasenumber <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 prefixstring The first characters on the line. messagestring The message to display. ipstring The IP address or unique identifier of the client that caused this event to happen. traceIncreasenumber <optional>
0 Increase the distance up the stack to show the in the log. - Source: