UNPKG

931 BPlain TextView Raw
1/*
2 This will grab any emojis being sent and parse them we do this as Bots have built in nitro.
3*/
4const log = logger.withScope('handleEmojis')
5export default (message: string) => {
6 let matches = message.match(/:[^: ]*:/g)
7 if (!matches || !matches[0]) return message
8 log.trace('Emojis found', matches)
9 log.debug(`found an emoji ${matches}`)
10 // Match first result and attach it as emote will not parse otherwise.
11 // We must use a handler to track which emojis have already been used.
12 matches = [...new Set(matches)] // removes duplicates
13 for (let match of matches) {
14 const emoji = discord.client.emojis.find(emoji => emoji.name.toLowerCase() === match.replace(/:/g, '').toLowerCase())
15 if (emoji) {
16 log.debug(`found an emoji ${match}`)
17 message = message.replace(new RegExp(match, 'g'), emoji.toString())
18 } else {
19 log.debug(`No emoji found for ${match}...`)
20 }
21 }
22 return message
23}