buddy

node MVC discord bot
Log | Files | Refs | README

ReactionManager.js (1771B)


      1 'use strict';
      2 
      3 const BaseManager = require('./BaseManager');
      4 const MessageReaction = require('../structures/MessageReaction');
      5 
      6 /**
      7  * Manages API methods for reactions and holds their cache.
      8  * @extends {BaseManager}
      9  */
     10 class ReactionManager extends BaseManager {
     11   constructor(message, iterable) {
     12     super(message.client, iterable, MessageReaction);
     13 
     14     /**
     15      * The message that this manager belongs to
     16      * @type {Message}
     17      */
     18     this.message = message;
     19   }
     20 
     21   add(data, cache) {
     22     return super.add(data, cache, { id: data.emoji.id || data.emoji.name, extras: [this.message] });
     23   }
     24 
     25   /**
     26    * The reaction cache of this manager
     27    * @type {Collection<Snowflake, MessageReaction>}
     28    * @name ReactionManager#cache
     29    */
     30 
     31   /**
     32    * Data that can be resolved to a MessageReaction object. This can be:
     33    * * A MessageReaction
     34    * * A Snowflake
     35    * @typedef {MessageReaction|Snowflake} MessageReactionResolvable
     36    */
     37 
     38   /**
     39    * Resolves a MessageReactionResolvable to a MessageReaction object.
     40    * @method resolve
     41    * @memberof ReactionManager
     42    * @instance
     43    * @param {MessageReactionResolvable} reaction The MessageReaction to resolve
     44    * @returns {?MessageReaction}
     45    */
     46 
     47   /**
     48    * Resolves a MessageReactionResolvable to a MessageReaction ID string.
     49    * @method resolveID
     50    * @memberof ReactionManager
     51    * @instance
     52    * @param {MessageReactionResolvable} reaction The MessageReaction to resolve
     53    * @returns {?Snowflake}
     54    */
     55 
     56   /**
     57    * Removes all reactions from a message.
     58    * @returns {Promise<Message>}
     59    */
     60   removeAll() {
     61     return this.client.api
     62       .channels(this.message.channel.id)
     63       .messages(this.message.id)
     64       .reactions.delete()
     65       .then(() => this.message);
     66   }
     67 }
     68 
     69 module.exports = ReactionManager;