1 |
|
2 |
|
3 |
|
4 | const log = logger.withScope('handleEmojis')
|
5 | export 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 |
|
11 |
|
12 | matches = [...new Set(matches)]
|
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 | }
|