file descriptionL module import type { Embed , Emoji , Guild } from "eris" ; import { Logger } from "../classes/Logger" ; const TYPE = "eventLogging" ; export class EmojiUpdate extends Logger { events = [ "guildEmojisUpdate" ] ; async run ( event , guild , emojis , oldEmojis ) { if ( ! guild || emojis === oldEmojis ) return ; const guildconfig = await this . bot . db . getGuildConfig ( guild . id ) ; const channel = await this . getChannel ( guild , TYPE , event , guildconfig ) ; if ( ! channel ) return ; const string = this . bot . localeSystem . getLocaleFunction ( guildconfig . guildLocale ? guildconfig . guildLocale : this . bot . config . defaultLocale ) ; let changes = [ ] ; changes = oldEmojis . filter ( ( oldEmoji ) => ! emojis . some ( ( newEmoji ) => JSON . stringify ( newEmoji ) === JSON . stringify ( oldEmoji ) ) ) . concat ( emojis . filter ( ( newEmoji ) => ! oldEmojis . some ( ( oldEmoji ) => JSON . stringify ( newEmoji ) === JSON . stringify ( oldEmoji ) ) ) ) ; if ( ! changes . length ) return ; const duplicates = [ ] ; const changesIds = changes . map ( ( c ) => c . id ) ; const emojisIds = emojis . map ( ( c ) => c . id ) ; const changesString = [ ] ; changes . forEach ( ( change , i ) => { const lastIndex = changesIds . lastIndexOf ( change . id ) ; if ( lastIndex !== i ) { changesString . push ( string ( "logger.EMOJI_RENAMED" , { name : changes [ lastIndex ] . name , oldname : change . name } ) ) ; duplicates . push ( changes [ lastIndex ] . id ) ; } else if ( ! emojisIds . includes ( change . id ) ) changesString . push ( string ( "logger.EMOJI_DELETED" , { emoji : change . name } ) ) ; else if ( ! duplicates . includes ( change . id ) ) changesString . push ( string ( "logger.EMOJI_CREATED" , { emoji : change . name } ) ) ; } ) ; if ( ! changesString . length ) return ; const embed = { title : `🔧 ${ string ( "logger.EMOJI_UPDATED" ) }` , description : changesString . join ( "\n" ) , color : this . convertHex ( "general" ) , fields : [ ] , } as Embed ; this . bot . createMessage ( channel , { embed : embed } ) ; } }