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' ;
2022-11-15 09:06:18 -05:00
export default {
2023-03-05 05:04:10 -05:00
run ( client :TClient , oldMember :Discord.GuildMember , newMember :Discord.GuildMember ) {
if ( oldMember . guild . id != client . config . mainServer . id ) return ;
if ( ! client . config . botSwitches . logs ) return ;
2023-05-23 01:14:17 -04:00
const channel = ( client . channels . resolve ( client . config . mainServer . channels . logs ) as Discord . TextChannel ) ;
2023-03-05 05:04:10 -05:00
if ( oldMember . nickname != newMember . nickname ) {
2023-10-05 07:57:07 -04:00
const embed = new client . embed ( ) . setColor ( client . config . embedColor ) . setTimestamp ( ) . setThumbnail ( newMember . displayAvatarURL ( { size : 2048 } ) ) . setTitle ( ` Nickname updated: ${ newMember . user . username } ` ) . setDescription ( ` <@ ${ newMember . user . id } > \ n \` ${ newMember . user . id } \` ` )
2023-06-23 02:28:57 -04:00
oldMember . nickname === null ? '' : embed . addFields ( { name : '🔹 Old nickname' , value : ` \` \` \` ${ oldMember . nickname } \` \` \` ` } )
newMember . nickname === null ? embed . setFooter ( { text : 'Nickname has been reset.' } ) : embed . addFields ( { name : '🔹 New nickname' , value : ` \` \` \` ${ newMember . nickname } \` \` \` ` } )
2023-03-05 05:04:10 -05:00
channel . send ( { embeds : [ embed ] } )
2022-11-15 09:06:18 -05:00
}
2023-03-05 05:04:10 -05:00
2023-10-05 07:57:07 -04:00
const newRoles = newMember . roles . cache . map ( ( _ , i ) = > i ) . filter ( x = > ! oldMember . roles . cache . map ( ( _ , i ) = > i ) . some ( y = > y === x ) ) ;
const oldRoles = oldMember . roles . cache . map ( ( _ , i ) = > i ) . filter ( x = > ! newMember . roles . cache . map ( ( _ , i ) = > i ) . some ( y = > y === x ) ) ;
2023-06-23 02:28:57 -04:00
if ( newRoles . length === 0 && oldRoles . length == 0 ) return ;
2023-10-05 07:57:07 -04:00
const embed = new client . embed ( ) . setColor ( client . config . embedColor ) . setThumbnail ( newMember . displayAvatarURL ( { size : 2048 } ) ) . setTitle ( ` Role updated: ${ newMember . user . username } ` ) . setDescription ( ` <@ ${ newMember . user . id } > \ n \` ${ newMember . user . id } \` ` )
2023-05-23 01:14:17 -04:00
if ( newRoles . length != 0 ) embed . addFields ( { name : newRoles.length > 1 ? '🔹 Roles added' : '🔹 Role added' , value : newRoles.map ( x = > ` <@& ${ x } > ` ) . join ( ' ' ) } ) ;
if ( oldRoles . length != 0 ) embed . addFields ( { name : oldRoles.length > 1 ? '🔹 Roles removed' : '🔹 Role removed' , value : oldRoles.map ( x = > ` <@& ${ x } > ` ) . join ( ' ' ) } ) ;
2023-03-05 05:04:10 -05:00
channel . send ( { embeds : [ embed ] } )
}
}