import { Guild , GuildEmoji , TextChannel } from 'discord.js' ; import { ConfigurationManager } from './configuration.manager' ; export class EmojiManager { param guild static generateList ( guild ) { const entries = [ ] ; const emojis = guild . emojis . cache . filter ( this . filterEmojis ) . sort ( this . sortEmojis ) ; for ( const [ , emoji ] of emojis ) { entries . push ( `${ emoji } \`:${ emoji . name }:\`` ) ; } if ( entries . length === 0 ) { entries . push ( 'This guild has no emojis.' ) ; } return entries ; } param guild static getEmojiList ( guild ) { return this . getChannel ( guild , 'emoji-list' ) ; } param guild static getEmojiChangelog ( guild ) { return this . getChannel ( guild , 'emoji-changelog' ) ; } param guild param key protected static getChannel ( guild , key ) { const channelId = ConfigurationManager . get ( ) . getConfiguration ( key , guild . id ) ; const channel = guild . channels . resolve ( channelId ) ; if ( ! channel || channel . type !== 'text' ) { return null ; } return < TextChannel > channel ; } param emoji protected static filterEmojis ( emoji ) { return ! emoji . managed ; } param first param second protected static sortEmojis ( first , second ) { const firstName = first . name . toLowerCase ( ) ; const secondName = second . name . toLowerCase ( ) ; if ( firstName < secondName ) { return - 1 ; } if ( firstName > secondName ) { return 1 ; } return 0 ; } }