Class: WebProxy

WebProxy

Proxy for account authentication.

new WebProxy()

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

The url to send a request to the discord api.
Type:
  • Object
Default Value:
  • {"protocol":"https:","host":"discordapp.com","path":"/api","method":"GET","headers":""}
Source:

<private, inner> loginInfo :object.<LoginState>

Stores the tokens and associated data for all clients connected while data is valid. Mapped by session id.
Type:
Source:

<private, inner, constant> rateLimitFile :string

File storing website rate limit specifications.
Type:
  • string
Source:

<private, inner> rateLimits :object

Object storing parsed rate limit info from rateLimitFile.
Type:
  • object
Default Value:
  • {"commands":"","groups":""}
Source:

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

Cache of requests to the Discord API to reduce duplicate calls and reduce rate limiting. Mapped by user ID and request path. If user ID is unknown, requests are not cached.
Type:
  • object.<Array.<function()>>
Source:

<private, inner, constant> sockets :object.<Socket>

Map of all currently connected sockets.
Type:
  • object.<Socket>
Source:

<private, inner, constant> tokenHost :Object

The url to send a received `code` to via `POST` to receive a user's tokens.
Type:
  • Object
Default Value:
  • {"protocol":"https:","host":"discordapp.com","path":"/api/oauth2/token","method":"POST","headers":""}
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:

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

shutdown()

Causes a full shutdown of all servers.
Overrides:
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> apiRequest(loginInfo, path, cb)

Formats a request to the discord api at the given path.
Parameters:
Name Type Description
loginInfo LoginInfo The credentials of the user we are sending the request for.
path string The path for the api request to send.
cb basicCallback The response from the https request with error and data arguments.
Source:

<private, inner> authorizeRequest(code, cb)

Authenticate with the discord server using a login code.
Parameters:
Name Type Description
code string The login code received from our client.
cb basicCallback The response from the https request with error and data arguments.
Source:

<private, inner> discordRequest(data, cb, host)

Send a https request to discord.
Parameters:
Name Type Argument Description
data object | string The data to send in the request.
cb basicCallback Callback with error, and data arguments.
host object <nullable>
Request object to override the default with.
Source:

<private, inner> fetchGuilds(loginInfo, cb)

Fetches the guild information of the user we have the token of.
Parameters:
Name Type Description
loginInfo LoginInfo The credentials of the session user.
cb singleCB The callback storing the user's data, or null if something went wrong.
Source:

<private, inner> fetchIdentity(loginInfo, cb)

Fetches the identity of the user we have the token of.
Parameters:
Name Type Description
loginInfo LoginInfo The credentials of the session user.
cb singleCB The callback storing the user's data, or null if something went wrong.
Source:

<private, inner> handler(req, res)

Handler for all http requests. Should never be called.
Parameters:
Name Type Description
req http.IncomingMessage The client's request.
res http.ServerResponse Our response to the client.
Source:

<private, inner> makeRefreshTimeout(loginInfo, cb)

Refreshes the given token once it expires.
Parameters:
Name Type Description
loginInfo LoginInfo The credentials to refresh.
cb singleCB The callback that is fired storing the new credentials once they are refreshed.
Source:

<private, inner> purgeSessions()

Purge stale data from loginInfo.
Source:

<private, inner> refreshToken(refreshToken_, scope, cb)

Request new credentials with refresh token from discord.
Parameters:
Name Type Description
refreshToken_ string The refresh token used for refreshing credentials.
scope string Scope to refresh.
cb basicCallback The callback from the https request, with an error argument, and a data argument.
Source:

<private, inner> revokeToken(token, cb)

Revoke a current refresh token from discord.
Parameters:
Name Type Description
token string The refresh token to revoke.
cb basicCallback The callback from the https request, with an error argument, and a data argument.
Source:

<private, inner> socketConnection(socket)

Handler for a new socket connecting.
Parameters:
Name Type Description
socket socketIo~Socket The socket.io socket that connected.
Source:

<private, inner> updateRateLimits()

Parse rate limits from file.
Source: