import { Message , MessageReaction , User } from 'discord.js' ; import { RateLimiter } from 'discord.js-rate-limiter' ; import { EventHandler } from '.' ; import { EventData } from '../models/internal-models' ; import { Reaction } from '../reactions' ; let Config = require ( '../../config/config.json' ) ; export class ReactionHandler implements EventHandler { private rateLimiter = new RateLimiter ( Config . rateLimiting . reactions . amount , Config . rateLimiting . reactions . interval * 1000 ) ; constructor ( private reactions ) { } public async process ( msgReaction , msg , reactor ) { if ( reactor . id === msgReaction . client . user ?. id || reactor . bot ) { return ; } let limited = this . rateLimiter . take ( msg . author . id ) ; if ( limited ) { return ; } let reaction = this . findReaction ( msgReaction . emoji . name ) ; if ( ! reaction ) { return ; } if ( reaction . requireGuild && ! msg . guild ) { return ; } if ( reaction . requireSentByClient && msg . author . id !== msg . client . user ?. id ) { return ; } if ( reaction . requireEmbedAuthorTag && msg . embeds [ 0 ] ?. author ?. name !== reactor . tag ) { return ; } let data = new EventData ( ) ; await reaction . execute ( msgReaction , msg , reactor , data ) ; } private findReaction ( emoji ) { return this . reactions . find ( reaction => reaction . emoji === emoji ) ; } }