feat/fix(Util): fix animated part of parseEmoji regex and make id optional (#3407)

* Small changes to parseEmoji regex

I just made a small change to the parseEmoji regex, this change will make an invalid emoji, like `<aname:id>` return as null, before this change it would return as an animated emoji because the name started with an `a` which would result in false positives, then the `?` I added to the end of `(\d{17,19})?` is used if someone provided an emoji as `:name:` or `a:name:` it will return the correct values but have an invalid id.

* Update Util.js

2nd Update: I changed the regex to output the results if you provide `<aemoji:123456789012345678>` and <:aemoji:123456789012345678>` which will output `{ animated: false, name: "aemoji", id: "123456789012345678" }` or `<:emojiname:>` which outputs `{ animated: false, name: "emojiname", id: null }` or `<a:emoji:>` which would output `{ animated: true, name: "emoji", id: null }`. Before this PR the method would return that the emoji was animated if you provided something like `<anemojiname:emoji_id>` because the name started with an `a`.
This commit is contained in:
BannerBomb
2019-08-17 12:07:58 -04:00
committed by SpaceEEC
parent 2df4f227a4
commit b662678f21

View File

@@ -244,9 +244,9 @@ class Util {
static parseEmoji(text) {
if (text.includes('%')) text = decodeURIComponent(text);
if (!text.includes(':')) return { animated: false, name: text, id: null };
const m = text.match(/<?(a)?:?(\w{2,32}):(\d{17,19})>?/);
const m = text.match(/<?(?:(a):)?(\w{2,32}):(\d{17,19})?>?/);
if (!m) return null;
return { animated: Boolean(m[1]), name: m[2], id: m[3] };
return { animated: Boolean(m[1]), name: m[2], id: m[3] || null };
}
/**