Class: CmdScheduling

CmdScheduling

Provides interface for scheduling a specific time or interval for a command to be run.

new CmdScheduling()

Source:
Listens to Events:
  • Command#event:schedule
  • Command#event:sch
  • Command#event:sched
  • Command#event:scheduled

Extends

Classes

ScheduledCommand

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:

cancelCmd

Cancel a scheduled command in a guild.
Source:
See:

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:

<abstract> helpMessage :undefined|string|Discord~EmbedBuilder

The help message to show the user in the main help message.
Type:
  • undefined | string | Discord~EmbedBuilder
Inherited From:
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:

<constant> minDelay :number

Minimum allowable amount of time in milliseconds from when the scheduled command is registered to when it runs.
Type:
  • number
Default Value:
  • 10 Seconds
Source:

<constant> minRepeatDelay :number

Minimum allowable amount of time in milliseconds from when the scheduled command is run to when it run may run again.
Type:
  • number
Default Value:
  • 30 Seconds
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:

registerScheduledCommand

Register a created CmdScheduling.ScheduledCommand.
Source:
See:

<private, inner, constant> embedColor :Array.<number>

The color to use for embeds sent from this submodule.
Type:
  • Array.<number>
Default Value:
  • [50,255,255]
Source:

<private, inner, constant> idChars :string

The possible characters that can make up an ID of a scheduled command.
Type:
  • string
Default Value:
  • 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
Source:

<private, inner> listeners :object.<Array.<function()>>

Currently registered event listeners, mapped by event name.
Type:
  • object.<Array.<function()>>
Source:

<private, inner> longInterval :Interval

Interval that runs every maxTimeout milliseconds in order to re-schedule commands that were beyond the max timeout duration.
Type:
  • Interval
Source:

<private, inner, constant> maxTimeout :number

The maximum amount of time to set a Timeout for. The JS limit is 24 days (iirc), after which, Timeouts do not work properly.
Type:
  • number
Default Value:
  • 14 Days
Source:

<private, inner, constant> saveSubDir :string

The filename in the guild directory to save the scheduled commands.
Type:
  • string
Default Value:
  • /scheduledCmds.json
Source:

<private, inner, constant> schedules :object.<Array.<CmdScheduling.ScheduledCommand>>

All of the currently loaded commands to run. Mapped by Guild ID, then sorted arrays by time to run next command.
Type:
  • object.<Array.<CmdScheduling.ScheduledCommand>>
Source:

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

All of the guilds that have updated their schedules since last save.
Type:
  • object.<boolean>
Default Value:
  • {}
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:

on(name, handler)

Register an event handler for the given name with the given handler.
Parameters:
Name Type Description
name string The event name to listen for.
handler function The function to call when the event is fired.
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

removeListener(name [, handler])

Remove an event handler for the given name.
Parameters:
Name Type Argument Description
name string The event name to remove the handler for.
handler function <optional>
THe specific handler to remove, or null for all.
Source:

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> cancelAndReply(msg)

Find a scheduled command with the given ID, and remove it from commands to run.
Parameters:
Name Type Description
msg Discord~Message The message to reply to.
Source:

<private, inner> cancelCmd(gId, cmdId)

Cancel a scheduled command in a guild.
Parameters:
Name Type Description
gId string | number The guild id of which to cancel the command.
cmdId string | number The ID of the command to cancel.
Source:
Fires:
  • CmdScheduling#event:commandCancelled
Returns:
Null if failed, or object that was cancelled.
Type
CmdScheduling.ScheduledCommand

<private, inner> commandSchedule(msg)

Allow user to schedule command to be run, or view currently scheduled commands.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:schedule

<private, inner> fireEvent(name, data)

Fires a given event with the associated data.
Parameters:
Name Type Argument Description
name string The name of the event to fire.
data * <repeatable>
The arguments to pass into the function calls.
Source:

<private, inner> formatDelay(msecs)

Format a duration in milliseconds into a human readable string.
Parameters:
Name Type Description
msecs number Duration in milliseconds.
Source:
Returns:
Formatted string.
Type
string

<inner> getScheduledCommandsInGuild(gId)

Returns an array of references to scheduled commands in a guild.
Parameters:
Name Type Description
gId string | number The guild id of which to get the commands.
Source:
Returns:
Null if none, or the array of ScheduledCommands.
Type
null | Array.<CmdScheduling.ScheduledCommand>

<private, inner> makeMessage(uId, gId, cId, msg)

Forms a Discord~Message similar object from given IDs.
Parameters:
Name Type Description
uId string The id of the user who wrote this message.
gId string The id of the guild this message is in.
cId string The id of the channel this message was 'sent' in.
msg string The message content.
Source:
Returns:
The created message-like object, or null if invalid channel.
Type
MessageMaker

<private, inner> registerScheduledCommand(sCmd [, gId])

Register a created CmdScheduling.ScheduledCommand.
Parameters:
Name Type Argument Description
sCmd CmdScheduling.ScheduledCommand The ScheduledCommand object to register.
gId string <optional>
Guild ID if message has not yet been found, or to override the ID found in the given object.
Source:
Fires:
  • CmdScheduling#event:commandRegistered
Returns:
True if succeeded, False if too close to existing command.
Type
boolean

<private, inner> replyWithSchedule(msg)

Find all scheduled commands for a certain guild, and reply to the message with the list of commands.
Parameters:
Name Type Description
msg Discord~Message The message to reply to.
Source:

<inner> reScheduleCommands()

Reschedule all future commands that are beyond maxTimeout.
Source:

<private, inner> sortGuildCommands(id)

Sort all scheduled commands in a guild by the next time they will run.
Parameters:
Name Type Description
id string | number The guild id of which to sort the commands.
Source:

<private, inner> stringToMilliseconds(str)

Given a user-inputted string, convert to a number of milliseconds. Input can be on most common time units up to a week.
Parameters:
Name Type Description
str string The input string to parse.
Source:
Returns:
Number of milliseconds parsed from string.
Type
number

<private, inner> writeSaveData(i, data [, opt])

Write save data for a guild.
Parameters:
Name Type Argument Default Description
i string | number The guild ID.
data object The data to write.
opt string <optional>
'sync' See save.
Source: