import { IMessage , IContainer } from '../../common/types' ; import { Guild } from 'discord.js' ; import { Handler } from '../../common/handler' ; export class TagRateLimitHandler extends Handler { public name : string = 'TagRateLimit' ; private _MAX_ROLES_TAGGED = 6 ; private _TAG_RATE_DURATION : number = 5 * 60 * 1000 ; private _TAGS_MAP = new Map < Guild , Map < string , number [ ] > > ( ) ; constructor ( public container ) { super ( ) ; } public execute ( message ) { if ( ! message || ! message . member || ! message . member . id ) { return ; } const guild_map = this . _TAGS_MAP . get ( this . container . guildService . get ( ) ) ?? new Map < string , number [ ] > ( ) ; guild_map . set ( message . member . id , guild_map . get ( message . member . id ) ?? [ ] ) ; const dates = guild_map . get ( message . member . id ) ?? [ ] ; message . mentions . roles . forEach ( ( ) => { dates . push ( Date . now ( ) ) ; } ) ; if ( dates . length >= this . _MAX_ROLES_TAGGED ) { const time_since = dates [ 0 ] - dates [ dates . length - 1 ] ; if ( time_since <= this . _TAG_RATE_DURATION ) { this . container . messageService . sendBotReportOnMessage ( message ) ; this . container . loggerService . info ( 'Sent bot report.' ) ; } dates . splice ( 0 , dates . length ) ; } guild_map . set ( message . member . id , dates ) ; this . _TAGS_MAP . set ( this . container . guildService . get ( ) , guild_map ) ; } }