Class: SMLoader

SMLoader

Manages loading, unloading, and reloading of all SubModules.

new SMLoader()

Source:

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:

<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:

<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> 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> goalSubModuleNames :null|Array.<string>

The list of all submodules that we are intended to have loaded currently. This should reflect the file at SMloader~smListFilename. Null means the data is not available, and no action should be taken.
Type:
  • null | Array.<string>
Source:

<private, inner, constant> helpmessagereply :string

The message sent to the channel where the user asked for help.
Type:
  • string
Source:

<inner> nextSlashCommandPush

Timeout of next slash command update to Discord API.
Source:

<private, inner, nullable> saveTimeout :Timeout

Timeout for delay to save SMList.
Type:
  • Timeout
Source:

<inner, constant> slashCommandPushDelay

Delay after a load/unload event until we push the change to Discord API.
Source:

<private, inner, constant> smListFilename :string

The filename storing the list of all SubModules to load.
Type:
  • string
Default Value:
  • ./subModules.json
Source:

<private, inner> subModuleNames :Array.<string>

The list of all submodule names currently loaded.
Type:
  • Array.<string>
Source:

<private, inner> subModules :object.<SubModule>

Instances of SubModules currently loaded mapped by their name.
Type:
Source:

<private, inner, constant> toAssign :Class

Properties to merge into other objects. `bot` is merged into self.bot, `client` is merged into self.client.
Type:
  • Class
Source:

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

Discord IDs that are allowed to reboot the bot.
Type:
  • Array.<string>
Source:

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

Callbacks for when a scheduled module to unload, has been unloaded. Mapped by name of subModule, then array of all callbacks.
Type:
  • object.<Array.<function()>>
Source:

<private, inner, constant> unloadTimeouts :object.<Timeout>

Timeouts for retrying to unload submodules that are currently not in an unloadable state. Mapped by name of submodule.
Type:
  • object.<Timeout>
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:

export()

Export data required to maintain the bot across reloading this module. Expected to be returned directly to this.import once reloaded.
Inherited From:
Overrides:
Source:
Returns:
The data to be exported.
Type
MainModule~ModuleData

import(data)

Imports data from a previous instance of this class in order to maintain references to other objects and classes across reloads.
Parameters:
Name Type Argument Description
data MainModule~ModuleData <nullable>
The data that was exported previously, or null if no data to import.
Inherited From:
Overrides:
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:

load(name [, opts] [, cb])

Loads submodules from file.
Parameters:
Name Type Argument Description
name string Specify submodule to load. If it is already loaded, they will be ignored and return successful.
opts object <optional>
Options object.
Properties
Name Type Argument Default Description
updateGoal boolean <optional>
true Update the goal state of the subModule to loaded.
cb function <optional>
Callback to fire once the operation is complete. Single parameter is null if success, or string if error.
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:

reload( [name] [, opts] [, cb])

Reloads submodules from file. Reloads currently loaded modules if `name` is not specified. If a submodule is specified that is not loaded, it will skip the unload step, bull will still be attempted to be loaded.
Parameters:
Name Type Argument Description
name string | Array.<string> <optional>
Specify submodules to reload, or null to reload all submodules to their goal state.
opts object <optional>
Options object.
Properties
Name Type Argument Default Description
schedule boolean <optional>
true Automatically re-schedule reload for submodules if they are not in an unloadable state.
ignoreUnloadable boolean <optional>
false Force a submodule to unload even if it is not in an unloadable state.
force boolean <optional>
false Reload a submodule even if the currently loaded version is identical to the version on file. If false it will not be reloaded if the version would not be changed due to a reload.
cb function <optional>
Callback to fire once the operation is complete. Single parameter has array of strings of status of each module attempted to be reloaded.
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:

<abstract, protected> shutdown()

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

terminate()

Signal that the bot is shutting down and will not be restarting immediately. This is triggered on all shutdowns where all MainModules and SubModules will be unloaded.
Inherited From:
Overrides:
Source:

unload(name [, opts] [, cb])

Unloads submodules that is currently loaded.
Parameters:
Name Type Argument Description
name string Specify submodule to unload. If it is already unloaded, it will be ignored and return successful.
opts object <optional>
Options object.
Properties
Name Type Argument Default Description
schedule boolean <optional>
true Automatically re-schedule unload for submodule if it is in an unloadable state.
ignoreUnloadable boolean <optional>
false Force a submodule to unload even if it is not in an unloadable state.
updateGoal boolean <optional>
true Update the goal state of the subModule to unloaded.
cb function <optional>
Callback to fire once the operation is complete. Single parameter is null if success, or string if error.
Source:

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:
Overrides:
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> commandHelp(msg)

Send help message to user who requested it.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:help

<private, inner> commandLoad(msg)

Load specific sub modules.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:load

<private, inner> commandReload(msg)

Reload all sub modules by unloading then re-requiring.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:reload

<private, inner> commandUnload(msg)

Unload specific sub modules.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:unload

<private, inner> saveSMList( [force])

Save the current goal submodules to file.
Parameters:
Name Type Argument Default Description
force boolean <optional>
false Force immediately saving instead of delaying a bit.
Source:

<private, inner> shardLoad(message, id)

Other shard has requested a load command.
Parameters:
Name Type Description
message string The command message to parse.
id number Shard id requesting this.
Source:

<private, inner> shardReload(message, id)

Other shard has requested a reload command.
Parameters:
Name Type Description
message string The command message to parse.
id number Shard id requesting this.
Source:

<private, inner> shardUnload(message, id)

Other shard has requested an unload command.
Parameters:
Name Type Description
message string The command message to parse.
id number Shard id requesting this.
Source:

<private, inner> triggerSlashCommandUpdate()

A module has been loaded or unloaded, wait a moment for updates to finish, then push changes to Discord API.
Source: