2022-11-15 09:06:18 -05:00
import Discord from 'discord.js' ;
2023-04-14 06:47:58 -04:00
import TClient from '../client.js' ;
2023-12-24 10:21:40 -05:00
export default class GuildMemberRemove {
static async run ( client :TClient , member :Discord.GuildMember ) {
2023-03-05 05:04:10 -05:00
if ( ! client . config . botSwitches . logs ) return ;
2023-12-24 10:21:40 -05:00
if ( ! member . joinedTimestamp || member . guild ? . id != client . config . dcServer . id ) return ;
if ( client . guilds . cache . get ( client . config . dcServer . id ) . bans . cache . has ( member . id ) ) return await client . userLevels . deleteUser ( member . id ) ;
2023-06-09 21:11:19 -04:00
let isBot = 'Bot' ;
if ( ! member . user . bot ) isBot = 'Member' ;
2023-12-24 10:21:40 -05:00
const levelData = await client . userLevels . fetchUser ( member . id ) ;
2024-01-31 07:45:35 -05:00
const embed = new client . embed ( ) . setColor ( client . config . embedColorRed ) . setTimestamp ( ) . setThumbnail ( member . user . displayAvatarURL ( { size : 2048 } ) as string )
. setTitle ( ` ${ isBot } Left: ${ member . user . username } ` ) . addFields (
{ name : '🔹 User' , value : ` <@ ${ member . user . id } > \ n \` ${ member . user . id } \` ` } ,
2023-03-05 05:04:10 -05:00
{ name : '🔹 Account Creation Date' , value : ` <t: ${ Math . round ( member . user . createdTimestamp / 1000 ) } > \ n<t: ${ Math . round ( member . user . createdTimestamp / 1000 ) } :R> ` } ,
{ name : '🔹 Server Join Date' , value : ` <t: ${ Math . round ( member . joinedTimestamp / 1000 ) } > \ n<t: ${ Math . round ( member . joinedTimestamp / 1000 ) } :R> ` } ,
{ name : ` 🔹 Roles: ${ member . roles . cache . size - 1 } ` , value : ` ${ member . roles . cache . size > 1 ? member . roles . cache . filter ( ( x ) = > x . id !== member . guild . roles . everyone . id ) . sort ( ( a , b ) = > b . position - a . position ) . map ( x = > x ) . join ( member . roles . cache . size > 4 ? ' ' : '\n' ) . slice ( 0 , 1024 ) : 'No roles' } ` , inline : true }
) ;
2023-12-24 10:21:40 -05:00
if ( levelData && levelData . dataValues . messages > 1 ) embed . addFields ( { name : '🔹 Total messages' , value : levelData.dataValues.messages.toLocaleString ( 'en-US' ) , inline : true } ) ;
( client . channels . resolve ( client . config . dcServer . channels . logs ) as Discord . TextChannel ) . send ( { embeds : [ embed ] } ) ;
await client . userLevels . deleteUser ( member . id ) ;
2023-03-05 05:04:10 -05:00
}
2022-11-25 04:47:26 -05:00
}