fileoverview description module import type { Guild , Member } from "eris" ; import type { HibikiClient } from "../../classes/Client" ; import { validItems } from "../../utils/validItems" ; import { punishMute } from "./punishments" ; const reason = "Raid detection (Automod)" ; const joinTimes = { } ; const defaultThreshold = validItems . find ( ( item ) => item . id === "raidThreshold" ) . default as number ; export async function automodAntiRaid ( guild , member , bot , cfg ) { if ( ! cfg . raidThreshold ) cfg . raidThreshold = defaultThreshold ; if ( ! joinTimes [ guild . id ] ) joinTimes [ guild . id ] = [ ] ; joinTimes [ guild . id ] . push ( { member : member . id , time : Date . now ( ) } ) ; joinTimes [ guild . id ] = joinTimes [ guild . id ] . filter ( ( join ) => Date . now ( ) - join . time < 5000 ) ; if ( joinTimes [ guild . id ] . length >= cfg . raidThreshold ) { switch ( cfg . raidPunishments ) { case "Ban" : guild . banMember ( member . id , 0 , reason ) . catch ( ( ) => { } ) ; break ; case "Kick" : guild . kickMember ( member . id , reason ) . catch ( ( ) => { } ) ; break ; case "Mute" : punishMute ( member , bot , cfg , reason , guild ) . catch ( ( ) => { } ) ; break ; } } }