Class: Twitch

Twitch


new Twitch()

SubModule managing Twitch related commands.
Source:
Listens to Events:
  • Command#event:twitch

Extends

Members


<static> loginHost

Get default host information for API request to fetch user information.
Source:

<static> subHost

Get default host information for requesting to subscribe or unsubscribe from a webhook.
Source:

<private, constant> _strings :Strings

Instance of locale string manager.
Type:
Source:

<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 :external:Discord~Client

The current bot client. Defaults to require cache value for editor autocompletion, updates to current reference at init.
Type:
  • external: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 :external:Discord

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

<abstract> helpMessage :undefined|string|external:Discord~MessageEmbed

The help message to show the user in the main help message.
Type:
  • undefined | string | external:Discord~MessageEmbed
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> _commandSubscribe(msg)

Subscribe to notifications for a streamer in a text channel.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
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.
Source:
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.
Source:
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.
Source:

<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.
Source:
Returns:
Formatted embed message.
Type
external:Discord~MessageEmbed

<private> _handleChannelDelete(channel)

Handle a Discord channel being deleted.
Parameters:
Name Type Description
channel external:Discord~Channel The deleted Discord channel.
Source:
Listens to Events:
  • external:Discord~Client#event:ChannelDelete

<private> _handleGuildDelete(guild)

Handle a Discord guild being deleted (usually bot being kicked).
Parameters:
Name Type Description
guild external:Discord~Guild The deleted Discord guild.
Source:
Listens to Events:
  • external: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.
Source:

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

<private> _resubCheck()

Check our database for webhook subscriptions that are about to expire, and re-subscribe to them.
Source:

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