- 1 :
/**
- 2 :
* A class used to register commands for the command handler
- 3 :
*/
- 4 :
class ReactCommand {
- 5 :
/**
- 6 :
* Construct a react command
- 7 :
* @class
- 8 :
* @param {Object} data The react command data
- 9 :
* @prop {String} data.emoji The emoji that triggers the command
- 10 :
* @prop {String} data.desc The description of the react command
- 11 :
* @prop {Object} data.options Additional options for the react command
- 12 :
* @prop {Boolean} [data.options.restricted=false] Whether or not this command is restricted to admin only
- 13 :
* @prop {Boolean} [data.options.removeReaction=false] Whether the triggering reaction is removed after executed or not
- 14 :
* @prop {Boolean} [data.options.guildOnly=false] Whether or not this command can only be triggered in guilds as opposed to DMs
- 15 :
* @prop {Number} [data.options.authLevel=0] The minimum auth level required to execute this command
- 16 :
* @prop {ReactCommandAction} data.action The react command action
- 17 :
*/
- 18 :
constructor ({ emoji, desc, options = {}, action }) {
- 19 :
const {
- 20 :
restricted = false,
- 21 :
removeReaction = false,
- 22 :
guildOnly = false,
- 23 :
authLevel
- 24 :
} = options
- 25 :
- 26 :
/**
- 27 :
* The emoji that triggers the command
- 28 :
* @type {String}
- 29 :
*/
- 30 :
this.emoji = emoji
- 31 :
- 32 :
/**
- 33 :
* The description of the react command
- 34 :
* @type {String}
- 35 :
*/
- 36 :
this.desc = desc
- 37 :
- 38 :
/**
- 39 :
* The options for the react command
- 40 :
* @type {Object}
- 41 :
* @prop {Boolean} restricted Whether or not this command is restricted to admin only
- 42 :
* @prop {Boolean} removeReaction Whether the triggering reaction is removed after executed or not
- 43 :
* @prop {Boolean} guildOnly Whether or not this command can only be triggered in guilds as opposed to DMs
- 44 :
* @prop {Number} authLevel The minimum auth level required to execute this command
- 45 :
*/
- 46 :
this.options = {
- 47 :
restricted,
- 48 :
removeReaction,
- 49 :
guildOnly,
- 50 :
authLevel: parseInt(authLevel) || 0
- 51 :
}
- 52 :
- 53 :
/**
- 54 :
* The react command action
- 55 :
* @type {ReactCommandAction}
- 56 :
*/
- 57 :
this.action = action
- 58 :
}
- 59 :
- 60 :
/**
- 61 :
* Get the info of this react command
- 62 :
* @type {String}
- 63 :
* @example '**emoji** - *description*'
- 64 :
*/
- 65 :
get info () {
- 66 :
return `${this.options.restricted ? '~~' : ''}**${this.emoji}** - *${this.desc}*${this.options.restricted ? '~~' : ''}`
- 67 :
}
- 68 :
}
- 69 :
- 70 :
module.exports = ReactCommand
- 71 :
- 72 :
/**
- 73 :
* The react command action
- 74 :
* @callback reactCommandAction
- 75 :
* @param {ReactCommandData} data Data passed from the handler
- 76 :
* @returns {CommandResults[]|CommandResults|String[]|String} Data to respond with
- 77 :
*/
- 78 :
- 79 :
/**
- 80 :
* The object passed to a react command action
- 81 :
* @typedef {Object} ReactCommandData
- 82 :
* @prop {Agent} ReactCommandData.agent The agent managing the bot
- 83 :
* @prop {Eris.Client} ReactCommandData.client The Eris client
- 84 :
* @prop {Map<String, ReactCommand>} ReactCommandData.reactCommands The list of bot react commands
- 85 :
* @prop {Eris.Message} ReactCommandData.msg The message reacted on
- 86 :
* @prop {String} ReactCommandData.emoji The emoji reacted with
- 87 :
* @prop {Eris.User} ReactCommandData.user The user who reacted
- 88 :
* @prop {Object} ReactCommandData.attachments User-supplied data that is passed to commands
- 89 :
* @prop {ReactInterface} ReactCommandData.parentInterface If the react command was a button, the interface it was a part of
- 90 :
*/