Class: RoleManager

RoleManager

Manages advanced role controls and features.

new RoleManager()

Source:
Listens to Events:
  • Discord#event:message
  • Command#event:chat

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> cmdRoleAdd :Command~SingleCommand

The SingleCommand storing permissions for adding roles.
Type:
Source:

<private, inner> cmdRoleRemove :Command~SingleCommand

The SingleCommand storing permissions for removing roles.
Type:
Source:

<private, inner, constant> findDelay :number

The delay after failing to find a guild's data to look for it again.
Type:
  • number
Default Value:
  • 15 Seconds
Source:

<private, inner, constant> guildPerms :Object.<Object.<Object.<boolean>>>

The roles that each user is allowed to give. Mapped by guild id, then user id, then role id. Cached. Use RoleManager~find to access the data.
Type:
  • Object.<Object.<Object.<boolean>>>
Source:

<private, inner, constant> saveFile :string

The file path to save current state for a specific guild relative to Common~guildSaveDir.
Type:
  • string
Default Value:
  • /rolePerms.json
Source:
See:
  • Common~guildSaveDir

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:

giveRole(guild, member, role)

Give a guild member a role.
Parameters:
Name Type Description
guild string | number | Discord~Guild Guild object, or ID.
member string | number | Discord~GuildMember Guild Member object, ID or name (username, nickname or tag) to lookup.
role string | number | Discord~Role Guild Role object, ID or name to lookup.
Source:
Returns:
Null if success, string if error.
Type
string

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

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

Manage the basic fallback for the role command.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:role

<private, inner> commandRoleAdd(msg)

Handle the user attempting to add a role.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:roleAdd

<private, inner> commandRoleManage(msg)

Handle the user configuring permissions.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:roleManage

<private, inner> commandRoleRemove(msg)

Handle the user attempting to remove a role.
Parameters:
Name Type Description
msg Discord~Message Message that triggered command.
Source:
Listens to Events:
  • Command#event:roleRemove

<private, inner> find(id)

Returns a guild's data. Returns cached version if that exists, or searches the file system for saved data. Data will only be checked from disk at most once every `RoleManager~findDelay` milliseconds. Returns `null` if data could not be found, or an error occurred.
Parameters:
Name Type Description
id number | string The guild id to get the data for.
Source:
Returns:
The role data, or null if no data could be loaded.
Type
Object