Class: Main

Main

Basic commands and features for the bot.

new Main()

Source:
Listens to Events:
  • Discord~Client#event:guildCreate
  • Discord~Client#event:guildDelete
  • Discord~Client#event:guildBanAdd
  • Discord~Client#event:message
  • Command#event:addMe
  • Command#event:invite
  • Command#event:add
  • Command#event:simplify
  • Command#event:solve
  • Command#event:eval
  • Command#event:evaluate
  • Command#event:graph
  • Command#event:derive
  • Command#event:remind
  • Command#event:reminder
  • Command#event:reminders
  • Command#event:createDate
  • Command#event:joinDate
  • Command#event:server
  • Command#event:serverInfo
  • Command#event:pmMe
  • Command#event:dmMe
  • Command#event:pmSpikey
  • Command#event:dmSpikey
  • Command#event:thotPm
  • Command#event:pmUser
  • Command#event:flip
  • Command#event:coin
  • Command#event:flipcoin
  • Command#event:coinflip
  • Command#event:purge
  • Command#event:prune
  • Command#event:fuckYou
  • Command#event:ban
  • Command#event:profile
  • Command#event:avatar
  • Command#event:ping
  • Command#event:uptime
  • Command#event:game
  • Command#event:version
  • Command#event:roll
  • Command#event:dice
  • Command#event:die
  • Command#event:d
  • Command#event:toggleMute
  • Command#event:toggleBanMessages
  • Command#event:toggleRigged
  • Command#event:toggleDad
  • Command#event:perms
  • Command#event:stats
  • Command#event:lookup
  • Command#event:sendto
  • Command#event:thanks
  • Command#event:thx
  • Command#event:thank
  • Command#event:thankyou
  • Command#event:listCommands
  • Command#event:getPrefix
  • Command#event:git
  • Command#event:gettime
  • Command#event:update
  • Command#event:bans
  • Command#event:listbans

Extends

Members


<nullable> bot :SpikeyBot

The parent SpikeyBot instance. Defaults to required cache value for autocompletion, updates to current reference at init.
Type:
Inherited From:
Source:

client :Discord~Client

The current bot client. Defaults to require cache value for editor autocompletion, updates to current reference at init.
Type:
  • Discord~Client
Inherited From:
Source:

command :Command

The command object for registering command listeners. Defaults to require cache value for editor autocompletion, updates to current reference at init.
Type:
Inherited From:
Source:

<constant> commit :string

The commit at HEAD at the time this module was loaded. Essentially the version of this submodule.
Type:
  • string
Inherited From:
Source:

common :Common

The common object. Defaults to require cache value for editor autocompletion, updates to current reference at init.
Type:
Inherited From:
Source:

Discord :Discord

The current Discord object instance of the bot. Defaults to require cache value for editor autocompletion, updates to current reference at init.
Type:
  • Discord
Inherited From:
Source:

helpMessage :undefined|string|Discord~EmbedBuilder

The help message to show the user in the main help message.
Type:
  • undefined | string | Discord~EmbedBuilder
Inherited From:
Overrides:
Source:

<protected, readonly> initialized :boolean

Has this subModule been initialized yet (Has begin() been called).
Type:
  • boolean
Inherited From:
Source:

<constant> loadTime :number

The time at which this module was loaded for use in checking if the module needs to be reloaded because the file has been modified since loading.
Type:
  • number
Inherited From:
Source:

<protected> myName :string

The name of this submodule. Used for differentiating in the log. Should be defined before begin().
Type:
  • string
Inherited From:
Overrides:
Source:

<abstract> postPrefix :string

The postfix for the global prefix for this subModule. Must be defined before begin(), otherwise it is ignored.
Type:
  • string
Inherited From:
Source:

<private, inner, constant> addmessage :string

The message with instructions of how to add the bot to a server.
Type:
  • string
Source:

<private, inner, constant> adminHelpObject

The object that stores all data to be formatted into the help message for admin commands.
Source:

<private, inner, constant> banListCache :object.<Array.<string>>

Cache storing data about requested user ban information. Mapped by user ID, then array of guild IDs where the user is banned.
Type:
  • object.<Array.<string>>
Source:

<private, inner, constant> banListRequests :object.<{total: number, done: number, callbacks: Array.<function()>}>

Data about number of responses expected and completed for a user from all shards.
Type:
  • object.<{total: number, done: number, callbacks: Array.<function()>}>
Source:

<private, inner, constant> banMsgs :Array.<string>

All of the possible messages to show when using the ban command.
Type:
  • Array.<string>
Source:

<private, inner, constant> blockedmessage :string

The message sent to the channel where the user asked to be DM'd, but we were unable to deliver the DM.
Type:
  • string
Source:

<private, inner> commit :string

The current commit hash at HEAD.
Type:
  • string
Source:

<private, inner, constant> disabledAutoSmite :object.<boolean>

All guilds that have disabled the auto-smite feature.
Type:
  • object.<boolean>
Source:

<private, inner, constant> disabledBanMessage :object.<boolean>

All guilds that have disabled sending messages when someone is banned.
Type:
  • object.<boolean>
Source:

<private, inner, constant> disabledDadBot :object.<boolean>

The guilds that have disabled the Dad Bot messages.
Type:
  • object.<boolean>
Source:

<private, inner, constant> disabledRiggedCounter :object.<boolean>

The guilds that have disabled the rigged messages.
Type:
  • object.<boolean>
Source:

<private, inner, constant> helpObject

The object that stores all data to be formatted into the help message.
Source:

<private, inner, constant> introduction :string

The introduction message the bots sends when pmme is used.
Type:
  • string
Source:

<private, inner, constant> mentionAccumulator :object.<object.<string>>

The guilds with auto-smite enabled, and members who have mentioned "@everyone", and the timestamps of these mentions.
Type:
  • object.<object.<string>>
Source:

<private, inner, constant> oldestPing :number

Oldest ping value to store.
Type:
  • number
Default Value:
  • 24 hours
Source:

<private, inner> pingHistory :Array.<{time: number, delta: number}>

Previous ping values and their associated timestamps. Stores up to the previous oldestPing worth of pings since a reboot.
Type:
  • Array.<{time: number, delta: number}>
Default Value:
  • []
Source:

<private, inner, constant> settingsUpdated :object.<boolean>

All guilds that have updated their settings since the last time we saved data.
Type:
  • object.<boolean>
Source:

<private, inner> version :string

The current bot version parsed from package.json.
Type:
  • string
Source:

Methods


begin(Discord, client, command, common, bot)

Initialize this submodule.
Parameters:
Name Type Description
Discord Discord The Discord object for the API library.
client Discord~Client The client that represents this bot.
command Command The command instance in which to register command listeners.
common Common Class storing common functions.
bot SpikeyBot The parent SpikeyBot instance.
Inherited From:
Source:

<protected> debug(msg)

Log using common.logDebug, but automatically set name.
Parameters:
Name Type Description
msg string The message to log.
Inherited From:
Source:

end()

Trigger subModule to shutdown and get ready for process terminating.
Inherited From:
Source:

<protected> error(msg)

Log using common.error, but automatically set name.
Parameters:
Name Type Description
msg string The message to log.
Inherited From:
Source:

<protected> initialize()

The function called at the end of begin() for further initialization specific to the subModule. Must be defined before begin() is called.
Inherited From:
Overrides:
Source:

<protected> log(msg)

Log using common.log, but automatically set name.
Parameters:
Name Type Description
msg string The message to log.
Inherited From:
Source:

<abstract> reloadable()

Check if this module is in a state that is ready to be reloaded. If false is returned, this module should not be unloaded and doing such may risk putting the module into an uncontrollable state. This is different from unloadable, which checks if this module can be stopped completely, this checks if the module can be stopped and restarted.
Inherited From:
Source:
See:
  • SubModule~unloadable
Returns:
True if can be reloaded, false if cannot.
Type
boolean

save( [opt])

Saves all data to files necessary for saving current state.
Parameters:
Name Type Argument Default Description
opt string <optional>
'sync' Can be 'async', otherwise defaults to synchronous.
Inherited From:
Overrides:
Source:

<protected> shutdown()

Shutdown and disable this submodule. Removes all event listeners.
Inherited From:
Overrides:
Source:

<abstract> unloadable()

Check if this module is in a state that is ready to be unloaded. If false is returned, this module should not be unloaded and doing such may risk putting the module into an uncontrollable state.
Inherited From:
Source:
See:
  • SubModule~reloadable
Returns:
True if can be unloaded, false if cannot.
Type
boolean

<protected> warn(msg)

Log using common.logWarning, but automatically set name.
Parameters:
Name Type Description
msg string The message to log.
Inherited From:
Source:

<private, inner> banListResponse(userId, res)

Fired when shard sends the ban list response data.
Parameters:
Name Type Description
userId string The ID of the user this data is for.
res object.<string> The response data from a shard.
Source:

<private, inner> broadcastBanList(userId, numReq)

Fetch the list of guilds the user has been banned from. Responds through a broadcastEval to all shards with an object mapped by guild ID and the value is the ban reason as a string.
Parameters:
Name Type Description
userId string The ID of the user to fetch.
numReq number The number of additional responses from other shards should be expected.
Source:

<private, inner> checkSimilarity(s1, s2)

Returns the percentage of how similar the two given strings are.
Parameters:
Name Type Description
s1 string First string.
s2 string Second string to compare.
Source:
Returns:
Number from 0 to 1 of how similar the two strings are.
Type
number

<private, inner> commandAdd(msg)

Parses message and adds given numbers.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:add

<private, inner> commandAddMe(msg)

Replies to message with URL for inviting the bot to a guild.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:addMe
  • Command#event:invite

<private, inner> commandAvatar(msg)

Send a larger resolution version of the mentioned user's avatar.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:avatar

<private, inner> commandBan(msg)

Ban a mentioed user (or role from ID) and send a message saying they were banned.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:ban
  • Command#event:fuckyou

<private, inner> commandCreateDate(msg)

Tell the user the date when they created their Discord account.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:createDate

<private, inner> commandDerive(msg)

Take the derivative of a given equation in terms of dy/dx.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:derive

<private, inner> commandEmoji(msg)

Send information about the emojis sent in the message.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:emoji
  • Command#event:emote
  • Command#event:e
  • Command#event:emojis
  • Command#event:emotes

<private, inner> commandEvaluate(msg)

Evaluate a string as an equation with units.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:eval
  • Command#event:evaluate

<private, inner> commandFlip(msg)

Send an image of a coin, either Heads or Tails.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:flip

<private, inner> commandGame(msg)

Reply to message saying what game the mentioned user is playing and possibly other information about their profile.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:game

<private, inner> commandGetPrefix(msg)

User has requested to view the current prefix for their guild. This is intended to be fired internally, usually through chatbot.js due to no other way to reference this if the user has forgotten the prefix.
Parameters:
Name Type Description
msg Discord~Message The message that triggered this command.
Source:
Listens to Events:
  • Command#event:getPrefix

<private, inner> commandGetTime(msg)

Reply with server time and GMT.
Parameters:
Name Type Description
msg Discord~Message The message that triggered this command.
Source:
Listens to Events:
  • Command#event:gettime

<private, inner> commandGit(msg)

Get the graph of the last few git commits.
Parameters:
Name Type Description
msg Discord~Message The message that triggered this command.
Source:
Listens to Events:
  • Command#event:git

<private, inner> commandGraph(msg)

Graph a given equation by plugging in values for X and creating an image based off values.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:graph

<private, inner> commandJoinDate(msg)

Tell the user the date when they joined the server the message was sent from.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:joinDate

<private, inner> commandListBans(msg)

Fetch all guilds a user has been banned from that we know of.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:listbans
  • Command#event:bans

<private, inner> commandListCommands(msg)

Fetch all registered commands and send them to the user.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:listCommands

<private, inner> commandLookup(msg)

Lookup an ID and give information about what it represents.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:lookup

<private, inner> commandPerms(msg)

Send information about permissions for debugging.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:perms

<private, inner> commandPing(msg)

Reply to user with my ping to the Discord servers.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:ping

<private, inner> commandPmMe(msg)

Send the user a PM with a greeting introducing who the bot is.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:pmMe
  • Command#event:dmMe

<private, inner> commandPmSpikey(msg)

Send a PM to SpikeyRobot with a message.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:pmSpikey
  • Command#event:pmSpikey

<private, inner> commandPmUser(msg)

Send a PM to a specific user via a given id or name and descriminator.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:pmUser

<private, inner> commandPurge(msg)

Delete a given number of messages from a text channel.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:purge

<private, inner> commandRollDie(msg)

Roll a die with the given number of sides.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:roll
  • Command#event:dice
  • Command#event:die
  • Command#event:d

<private, inner> commandSendTo(msg)

Lookup an ID and send a message to the given channel or user without telling the recipient who sent the message. Only looks up cached users and channels on the same shard.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:sendto

<private, inner> commandServerInfo(msg)

Send information about the current server.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:server
  • Command#event:serverInfo

<private, inner> commandSimplify(msg)

Simplifies equation given in message.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:simplify

<private, inner> commandSolve(msg)

Solve an equation.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:solve

<private, inner> commandStats(msg)

Send information about the bot.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:stats

<private, inner> commandThankYou(msg)

Reply saying "you're welcome" unless another user was mentioned, then thank them instead.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:thanks
  • Command#event:thank
  • Command#event:thx
  • Command#event:thankyou

<private, inner> commandThotPm(msg)

Send a PM to a mentioned user semi-anonymously. Messages are copied to SpikeyRobot to monitor for abuse. This command only works for 3 people.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:thotPm

<private, inner> commandToggleBanMessages(msg)

Toggles sending a message when a user is banned from a guild.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:toggleBanMessages

<private, inner> commandToggleDad(msg)

Toggles sending a message when a user says "I'm something" and Dad Bot replies.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:toggleDad

<private, inner> commandToggleMute(msg)

Toggles auto-muting a user for using @everyone too much.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:toggleMute

<private, inner> commandToggleRiggedCounter(msg)

Toggles sending a message when a user says 'rigged'.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:toggleRigged

<private, inner> commandUpdate(msg)

Trigger fetching the latest version of the bot from git, then tell all shards to reload the changes.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:update

<private, inner> commandUptime(msg)

Reply to message with the amount of time since the bot has been running.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:uptime

<private, inner> commandVersion(msg)

Read the current version from package.json and show it to the user.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:version

<private, inner> editDistance(s1, s2)

Calculates the edit distance between the two strings.
Parameters:
Name Type Description
s1 string First string.
s2 string Second string to compare to the first.
Source:
Returns:
Number of characters distance between the two strings.
Type
number

<private, inner> fetchShardPerms(id [, id2])

Fetch the bitfield of permissions for our self or a given user id in the guild or channel with the given id.
This:
  • {Discord~Client}
Parameters:
Name Type Argument Description
id string The channel or guild id or user id to lookup permissions for.
id2 string <optional>
The channel or guild id or user id to lookup permissions for.
Source:
Returns:
Null if unable to find, or an object with found data. Element`cId` is channel id, `gId` is guild id, `cY` is bitfield permissions for user in channel, `cM` is bitfield permissions for self in channel, `gY` is bitfield permissions for user in guild, `gM` is bitfield permissions for self in guild, `uId` is id of matched user.
Type
Object

<private, inner> getAllStats(cb)

Fetch the bot's stats from all shards, then combine the data. Public as SpikeyBot.getStats after SubModule.initialize.
Parameters:
Name Type Description
cb function One parameter that is guarunteed to have an array of stats objeccts.
Source:

<private, inner> getStats( [full])

Fetch our statistics about the bot on this shard.
Parameters:
Name Type Argument Default Description
full boolean <optional>
false Include all available stats about the system. This adds information about CPU load. Disk storage cannot be collected here due to the synchronous nature of this function.
Source:
Returns:
The statistics we collected.
Type
object

<private, inner> lookupId(id [, trusted])

Lookup an ID for any data associated with it. This checks guilds, channels, and users.
This:
  • {Discord~Client}
Parameters:
Name Type Argument Default Description
id string The ID to lookup.
trusted boolean <optional>
false Include possibly sensitive information in result.
Source:
Returns:
A Discord formatted string to send.
Type
string

<private, inner> onDebug(info)

A general debug message was produced.
Parameters:
Name Type Description
info string The information.
Source:
Listens to Events:
  • Discord~Client#event:debug

<private, inner> onError(err)

An error occurred with our websocket connection to Discord.
Parameters:
Name Type Description
err Discord~Error The websocket error object.
Source:
Listens to Events:
  • Discord~Client#event:error

<private, inner> onGuildBanAdd(guild, user)

Handle user banned on a guild.
Parameters:
Name Type Description
guild Discord~Guild The guild on which the ban happened.
user Discord~User The user that was banned.
Source:
Listens to Events:
  • Discord~Client#event:guildBanAdd

<private, inner> onGuildCreate(guild)

Handle being added to a guild.
Parameters:
Name Type Description
guild Discord~Guild The guild that we just joined.
Source:
Listens to Events:
  • Discord~Client#event:guildCreate

<private, inner> onGuildDelete(guild)

Handle being removed from a guild.
Parameters:
Name Type Description
guild Discord~Guild The guild that we just left.
Source:
Listens to Events:
  • Discord~Client#event:guildDelete

<private, inner> onMessage(msg)

Handle receiving a message for use on auto-muting users who spam @everyone.
Parameters:
Name Type Description
msg Discord~Message The message that was sent.
Source:
Listens to Events:
  • Discord~Client#event:message

<private, inner> onRateLimit(info)

A rate limit message was produced.
Parameters:
Name Type Description
info object The information.
Source:
Listens to Events:
  • Discord~Client#event:rateLimit

<private, inner> onWarn(info)

A general warning was produced.
Parameters:
Name Type Description
info string The information.
Source:
Listens to Events:
  • Discord~Client#event:warn

<private, inner> prePad(num, digits)

Pad a number with leading zeroes so that it is `digits` long.
Parameters:
Name Type Description
num string | number The number to pad with zeroes.
digits number The minimum number of digits to make the output have.
Source:
Returns:
The padded string.
Type
string

<private, inner> replyPerms(msg, gId, gM [, gY] [, cId] [, cM] [, cY] [, uId] [, owner] [, embed])

Reply to the given message with the permission information of the given guild, channel, and user.
Parameters:
Name Type Argument Description
msg Discord~Message Message to reply to.
gId string Guild ID for displaying.
gM number Bitfield for self in the guild.
gY number <optional>
Bitfield for user in guild.
cId string <optional>
Channel ID for displaying.
cM number <optional>
Bitfield for self in channel.
cY number <optional>
Bitfield for user in channel.
uId string <optional>
User id to show.
owner boolean <optional>
Is the user the guild owner.
embed Discord~EmbedBuilder <optional>
Embed object to modify instead of creating a new one.
Source:

<private, inner> requestBanList(userId, cb)

Request the ban lists for a user from all shards.
Parameters:
Name Type Description
userId string The ID of the user to fetch.
cb function The callback once all requests have completed.
Source:

<private, inner> runBotUpdate(msg [, msg_])

Fetch the latest version of the bot from GitHub, install/update NPM packages, then reload updated SubModules.
Parameters:
Name Type Argument Description
msg Discord~Message The message that triggered this command.
msg_ Discord~Message <optional>
The message we sent as a response to the update command.
Source:

<private, inner> sendTo(id, message)

Send a message to a certain channel id.
This:
  • {Discord~ClientUser}
Parameters:
Name Type Description
id string The channel ID to send the message to.
message string The message to send. Will have decodeURIComponent run on before processing.
Source:
Returns:
True if found channel, false otherwise.
Type
boolean

<private, inner> shardMessage(args)

Received a message from the shard manager.
Parameters:
Name Type Argument Description
args * <repeatable>
Message received.
Source:

<private, inner> simplify(formula)

Simplifies given formula.
Parameters:
Name Type Description
formula string The formula to attempt to simplify.
Source:
Returns:
Simplified formula.
Type
string