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