new Pets()
Manages pet related commands.
Listens to Events:
- Command#event:pet
Extends
Classes
Members
-
<private, constant> _baseMoves :Pets~BaseMoves
-
Instance of Pets~BaseMoves.
Type:
-
<private, constant> _basePets :Pets~BasePets
-
Instance of Pets~BasePets.
Type:
-
<private> _pets :object.<object.<Pet>>
-
All pets currently cached. Mapped by user ID, then pet ID. Only one pet is allowed per user at this time, but this future proofing in case users will be able to have multiples in the future.
Type:
- object.<object.<Pet>>
-
<private> _releasing :object.<boolean>
-
Cache of IDs that are currently being released to disk, but are not loaded anymore. Used for Pets._releasePet to prevent saving multiple times. If the ID exists, it will be true.
Type:
- object.<boolean>
-
<private, constant> _strings :Strings
-
Instance of locale strings helper.
Type:
-
<nullable> bot :SpikeyBot
-
The parent SpikeyBot instance. Defaults to required cache value for autocompletion, updates to current reference at init.
Type:
- Inherited From:
- Overrides:
- 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:
- Overrides:
- 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:
- Overrides:
- 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:
- Overrides:
- Source:
-
common :Common
-
The common object. Defaults to require cache value for editor autocompletion, updates to current reference at init.
Type:
- Inherited From:
- Overrides:
- 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:
- Overrides:
- 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:
- Overrides:
- Source:
-
<protected, readonly> initialized :boolean
-
Has this subModule been initialized yet (Has begin() been called).
Type:
- boolean
- Inherited From:
- Overrides:
- 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:
- Overrides:
- 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:
-
postPrefix :string
-
The postfix for the global prefix for this subModule. Must be defined before begin(), otherwise it is ignored.
Type:
- string
- Inherited From:
- Overrides:
- Source:
Methods
-
<private> _checkPurge(obj)
-
Check if pet is purgable from memory, and purges if possible.
Parameters:
Name Type Description objPet Pet object to potentially purge. -
<private> _commandAbandon(msg)
-
User requested to abandon a pet.
Parameters:
Name Type Description msgDiscord~Message Message that triggered command. Listens to Events:
- Command#event:pet_abandon
-
<private> _commandAdopt(msg)
-
User requested to adopt a new pet.
Parameters:
Name Type Description msgDiscord~Message Message that triggered command. Listens to Events:
- Command#event:pet_adopt
-
<private> _commandPet(msg)
-
User typed the pet command.
Parameters:
Name Type Description msgDiscord~Message Message that triggered command. Listens to Events:
- Command#event:pet
-
<private> _getAllPets(user, cb)
-
Get an array of all of a user's pets.
Parameters:
Name Type Description userDiscord~User Discord user to fetch all pets for. cbfunction Callback with first argument as optional error, and second as array of Pet objects. -
<private> _getPet(user, pId, cb)
-
Fetch a user's pet.
Parameters:
Name Type Description userDiscord~User A user of which to fetch the pet for. pIdstring The pet ID to fetch. cbfunction Callback once complete. First argument is optional error, second is parsed Pet object. -
<private> _releasePet(uId, pId)
-
Force a pet to be saved to file and removed from memory immediately. File IO is still asynchronous. This is used to release pets from other shards, and returns true if pet has been completely released to disk.
Parameters:
Name Type Description uIdstring The ID of the user. pIdstring THe ID of the pet. Returns:
True if fully released, false if not done yet.- Type
- boolean
-
<private> _reply(msg, titleKey, bodyKey [, rep])
-
Reply to msg with locale strings.
Parameters:
Name Type Argument Description msgDiscord~Message Message to reply to. titleKeystring <nullable>
String key for the title, or null for default. bodyKeystring String key for the body message. repstring <optional>
<repeatable>
Placeholder replacements for the body only. Returns:
Message send promise from Discord.- Type
- Promise.<Discord~Message>
-
<private> _saveSingle(obj [, opt] [, cb])
-
Save a single pet object to disk, and purge if stale.
Parameters:
Name Type Argument Default Description objPet The pet object to save. optstring <optional>
'sync' Either 'sync' or 'async'. cbfunction <optional>
Optional callback that fires with no arguments on completion. -
begin(Discord, client, command, common, bot)
-
Initialize this submodule.
Parameters:
Name Type Description DiscordDiscord The Discord object for the API library. clientDiscord~Client The client that represents this bot. commandCommand The command instance in which to register command listeners. commonCommon Class storing common functions. botSpikeyBot The parent SpikeyBot instance. - Inherited From:
- Overrides:
- Source:
-
<protected> debug(msg)
-
Log using common.logDebug, but automatically set name.
Parameters:
Name Type Description msgstring The message to log. - Inherited From:
- Overrides:
- Source:
-
end()
-
Trigger subModule to shutdown and get ready for process terminating.
- Inherited From:
- Overrides:
- Source:
-
<protected> error(msg)
-
Log using common.error, but automatically set name.
Parameters:
Name Type Description msgstring The message to log. - 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:
-
<protected> log(msg)
-
Log using common.log, but automatically set name.
Parameters:
Name Type Description msgstring The message to log. - Inherited From:
- Overrides:
- 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:
- Overrides:
- 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 optstring <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:
- 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 msgstring The message to log. - Inherited From:
- Overrides:
- Source: