-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add message reaction collectors & abstract collectors (#1335)
* message reaction collectors * docs cleanup * abstraction * remove pointless method * rename reaction collector creator method * docs and stuff * fix docs & build * backwards compatibility, fix docs * fix docs * remove deprecated comments * betterer docs again * Fix documentation * Fix Alias to not break depreciated code
- Loading branch information
1 parent
8475a4a
commit ca34c43
Showing
10 changed files
with
343 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const Collector = require('./interfaces/Collector'); | ||
const Collection = require('../util/Collection'); | ||
|
||
/** | ||
* @typedef {CollectorOptions} ReactionCollectorOptions | ||
* @property {number} max The maximum total amount of reactions to collect. | ||
* @property {number} maxEmojis The maximum number of emojis to collect. | ||
* @property {number} maxUsers The maximum number of users to react. | ||
*/ | ||
|
||
/** | ||
* Collects reactions on messages. | ||
* @implements {Collector} | ||
*/ | ||
class ReactionCollector extends Collector { | ||
|
||
/** | ||
* @param {Message} message The message upon which to collect reactions. | ||
* @param {CollectorFilter} filter The filter to apply to this collector. | ||
* @param {ReactionCollectorOptions} [options={}] The options to apply to this collector. | ||
*/ | ||
constructor(message, filter, options = {}) { | ||
super(message.client, filter, options); | ||
|
||
/** | ||
* @type {Message} message The message. | ||
*/ | ||
this.message = message; | ||
|
||
/** | ||
* @type {Collection} users Users which have reacted. | ||
*/ | ||
this.users = new Collection(); | ||
|
||
/** | ||
* @type {number} total Total number of reactions collected. | ||
*/ | ||
this.total = 0; | ||
|
||
this.client.on('messageReactionAdd', this.listener); | ||
} | ||
|
||
handle(reaction) { | ||
if (reaction.message.id !== this.message.id) return null; | ||
return { | ||
key: reaction.emoji.id || reaction.emoji.name, | ||
value: reaction, | ||
}; | ||
} | ||
|
||
postCheck(reaction, user) { | ||
this.users.set(user.id, user); | ||
if (this.options.max && ++this.total >= this.options.max) return 'limit'; | ||
if (this.options.maxEmojis && this.collected.size >= this.options.maxEmojis) return 'emojiLimit'; | ||
if (this.options.maxUsers && this.users.size >= this.options.maxUsers) return 'userLimit'; | ||
return null; | ||
} | ||
|
||
cleanup() { | ||
this.client.removeListener('messageReactionAdd', this.listener); | ||
} | ||
} | ||
|
||
module.exports = ReactionCollector; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.