import { TextChannel , MessageReaction , User , GuildChannel , CategoryChannel } from 'discord.js' ; import { Handler } from '../../common/handler' ; import { IContainer , IMessage , ClassType } from '../../common/types' ; export class ReactHandler extends Handler { public name : string = 'React' ; private _PIN_THRESH = 5 ; constructor ( public container ) { super ( ) ; } public async execute ( reaction , user ) { const message = reaction . message ; if ( ! message ) { return ; } const channel = message . channel as TextChannel ; this . _handleClassChannelPinRequest ( message as IMessage , channel ) ; await this . _handleWarningAcknowledge ( reaction , user ) ; } private async _handleWarningAcknowledge ( reaction , user ) { const warnCat = this . container . guildService . getChannel ( 'warnings' ) as CategoryChannel ; const chan = reaction . message . channel as GuildChannel ; if ( chan . parent !== warnCat ) { return ; } if ( reaction . users . cache . last ( ) ?. id !== chan . name ) { return ; } if ( reaction . emoji . name !== this . container . warningService . ACKNOWLEDGE_EMOJI ) { return ; } await this . container . warningService . deleteChan ( user . id ) ; } private _handleClassChannelPinRequest ( message , channel ) { if ( ! this . container . classService . getClasses ( ClassType . ALL ) . has ( channel . name ) ) { return ; } if ( message . pinned || ! message . pinnable ) { return ; } const onlyPin = ( react ) => react . emoji . name === '📌' ; message . awaitReactions ( { filter : onlyPin , max : this . _PIN_THRESH } ) . then ( ( collection ) => { const count = collection . first ( ) ?. count ; if ( ! count ) { return ; } count >= this . _PIN_THRESH && message . pin ( ) ; } ) . catch ( ) ; } }