Made mentions take priority over emojis and stuff
This commit is contained in:
parent
755c236d95
commit
978d9c4c12
1 changed files with 18 additions and 18 deletions
36
index.js
36
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;
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue