new Twitch()
Manages Twitch related commands.
Listens to Events:
- Command#event:twitch
Extends
Members
-
<static> loginHost
-
Get default host information for API request to fetch user information.
-
<static> subHost
-
Get default host information for requesting to subscribe or unsubscribe from a webhook.
-
<private, constant> _strings :Strings
-
Instance of locale string manager.
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> _commandResub(msg)
-
Trigger the bot to check for need to resubscribe to channel subscriptions. Specifying the `--force` flag will force all resubscriptions to be attempted even if they aren't expired yet.
Parameters:
Name Type Description msg
Discord~Message Message that triggered command. Listens to Events:
- Command#event:twitch_resub
-
<private> _commandSubscribe(msg)
-
Subscribe to notifications for a streamer in a text channel.
Parameters:
Name Type Description msg
Discord~Message Message that triggered command. Listens to Events:
- Command#event:twitch_add
-
<private> _commandTwitch(msg)
-
Fallback twitch command if no options specified.
Parameters:
Name Type Description msg
Discord~Message Message that triggered command. Listens to Events:
- Command#event:twitch
-
<private> _commandUnSubscribe(msg)
-
Unsubscribe from notifications for a streamer in a text channel.
Parameters:
Name Type Description msg
Discord~Message Message that triggered command. Listens to Events:
- Command#event:twitch_remove
-
<private> _fetchUser(login, cb)
-
Fetch the user data from a twitch username.
Parameters:
Name Type Description login
string The user's login name. cb
function Callback with optional error, otherwise user data object from Twitch. -
<private> _formatMessage(data [, locale])
-
Format the Twitch webhook into a Discord message to send.
Parameters:
Name Type Argument Description data
object Webhook data from Twitch. locale
string <optional>
Locale for formatting strings. Returns:
Formatted embed message.- Type
- Discord~EmbedBuilder
-
<private> _handleChannelDelete(channel)
-
Handle a Discord channel being deleted.
Parameters:
Name Type Description channel
Discord~Channel The deleted Discord channel. Listens to Events:
- Discord~Client#event:ChannelDelete
-
<private> _handleGuildDelete(guild)
-
Handle a Discord guild being deleted (usually bot being kicked).
Parameters:
Name Type Description guild
Discord~Guild The deleted Discord guild. Listens to Events:
- Discord~Client#event:GuildDelete
-
<private> _injectWebhookMetadata(data, cb)
-
Fetch other metadata related to this webhook request that might be available, such as game information.
Parameters:
Name Type Description data
object Data object from webhookHandler. cb
function Callback with the same object that was passed in as the only parameter. -
<private> _parseTwitchUserResponse(content, cb)
-
Parse the data received from the request for user data.
Parameters:
Name Type Description content
string The received information from Twitch. cb
function Callback. -
<private> _resubCheck( [force])
-
Check our database for webhook subscriptions that are about to expire, and re-subscribe to them.
Parameters:
Name Type Argument Default Description force
boolean <optional>
false Force all subscriptions to be resubscribed, even if they have not expired yet. THIS CAN LEAD TO EXCEEDING RATE LIMITS. This will not check or limit the number of resubs that occur. Only use inteligently. -
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:
- Overrides:
- Source:
-
<protected> debug(msg)
-
Log using common.logDebug, but automatically set name.
Parameters:
Name Type Description msg
string 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 msg
string 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 msg
string 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
-
<abstract> 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:
-
subscribeToUser(user)
-
Subscribe to webhook requests for a given user.
Parameters:
Name Type Description user
object The user data of which to subscribe to. -
<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 msg
string The message to log. - Inherited From:
- Overrides:
- Source:
-
webhookHandler(channels, data)
-
Format and send messages to all available channels that were specified and on the current shard, using the provided data from the webhook.
Parameters:
Name Type Description channels
Array.<string> Array of all channel IDs this message is to be sent in. IDs not on this shard will be ignored. data
Object Data received from Twitch webhook.