Made mentions take priority over emojis and stuff

This commit is contained in:
CBenni 2018-01-07 03:17:17 +01:00
parent 755c236d95
commit 978d9c4c12

View file

@ -175,6 +175,24 @@ client.login(config.discord.token).catch(error => {
const discordAvatarRegex = /(https:\/\/cdn.discordapp.com\/avatars\/\w+\/\w+\.(\w+)\?size=)(\w+)/; const discordAvatarRegex = /(https:\/\/cdn.discordapp.com\/avatars\/\w+\/\w+\.(\w+)\?size=)(\w+)/;
function findEmoji(message) { 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; const str = message.cleanContent;
// find a discord emote // find a discord emote
const discordEmote = /<(a?):(\w+):(\d+)>/g.exec(str); const discordEmote = /<(a?):(\w+):(\d+)>/g.exec(str);
@ -202,24 +220,6 @@ function findEmoji(message) {
}); });
if (unicodeEmoji) return unicodeEmoji; 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; return null;
} }