file description module import type { HibikiClient } from "../classes/Client" ; export class MuteHandler { bot : HibikiClient ; muteCache : MuteCache [ ] = [ ] ; constructor ( bot ) { this . bot = bot ; this . muteCache = [ ] ; setTimeout ( ( ) => { this . bot . db . getMuteCache ( ) . then ( ( muteCache ) => ( this . muteCache = muteCache ) ) ; setInterval ( async ( ) => { this . muteCache . forEach ( async ( mute , i ) => { if ( ! this . muteCache . length || ! mute . expiration ) return ; if ( Date . now ( ) >= new Date ( mute . expiration ) . getTime ( ) ) { const guild = this . bot . guilds . get ( mute . guild ) ; if ( ! guild || ! guild ?. members ?. size || ! guild ?. members ?. has ( mute . member ) ) return ; const guildconfig = await this . bot . db . getGuildConfig ( mute . guild ) ; const member = guild ?. members ?. get ?. ( mute . member ) ; if ( ! member ) return ; mute . roles . forEach ( async ( role ) => { await member . addRole ( role , "Automatically unmuted" ) . catch ( ( ) => { } ) ; } ) ; await bot . db . deleteUserGuildMuteCache ( guild . id , mute . member ) ; this . muteCache . splice ( i ) ; if ( guildconfig ?. mutedRole ) { await member . removeRole ( guildconfig . mutedRole , `Automatically unmuted` ) . catch ( ( ) => { } ) ; } } } ) ; } , 5000 ) ; } , 10000 ) ; } }