From 978d9c4c1239616cde979fa1ce07e9f5e45325b1 Mon Sep 17 00:00:00 2001 From: CBenni Date: Sun, 7 Jan 2018 03:17:17 +0100 Subject: [PATCH] Made mentions take priority over emojis and stuff --- index.js | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/index.js b/index.js index 7b66670..99dc0bf 100644 --- a/index.js +++ b/index.js @@ -175,6 +175,24 @@ client.login(config.discord.token).catch(error => { const discordAvatarRegex = /(https:\/\/cdn.discordapp.com\/avatars\/\w+\/\w+\.(\w+)\?size=)(\w+)/; function findEmoji(message) { + // find a user mention + if (message.mentions.members.size > 0) { + const mentionedMember = message.mentions.members.first(); + const mentionedUser = mentionedMember.user; + let avatarUrl = mentionedUser.displayAvatarURL; + const avatarMatch = discordAvatarRegex.exec(avatarUrl); + if (avatarMatch) { + const ext = avatarMatch[2]; + avatarUrl = `${avatarMatch[1]}128`; + } + return { + name: mentionedMember.displayName, + id: mentionedMember.id, + url: avatarUrl, + ext: avatarUrl.indexOf('.gif') >= 0 ? 'gif' : 'png' + }; + } + const str = message.cleanContent; // find a discord emote const discordEmote = /<(a?):(\w+):(\d+)>/g.exec(str); @@ -202,24 +220,6 @@ function findEmoji(message) { }); if (unicodeEmoji) return unicodeEmoji; - // find a user mention - if (message.mentions.members.size > 0) { - const mentionedMember = message.mentions.members.first(); - const mentionedUser = mentionedMember.user; - let avatarUrl = mentionedUser.displayAvatarURL; - const avatarMatch = discordAvatarRegex.exec(avatarUrl); - if (avatarMatch) { - const ext = avatarMatch[2]; - avatarUrl = `${avatarMatch[1]}128`; - } - return { - name: mentionedMember.displayName, - id: mentionedMember.id, - url: avatarUrl, - ext: avatarUrl.indexOf('.gif') >= 0 ? 'gif' : 'png' - }; - } - return null; }