blob: 63b2042195882863bff12426e465bf64368fbb70 [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +01001import emojis from "../config/emojis.json" assert {type: "json"};
pineafan4f164f32022-02-26 22:07:12 +00002
pineafan8b4b17f2022-02-27 20:42:52 +00003function getEmojiByName(name: string, format?: string): string {
pineafan63fc5e22022-08-04 22:04:10 +01004 const split = name.split(".");
5 let id = emojis;
pineafan4f164f32022-02-26 22:07:12 +00006 split.forEach(part => {
7 id = id[part];
8 });
pineafan8b4b17f2022-02-27 20:42:52 +00009 if ( format === "id" ) {
10 if (id === undefined) return "0";
11 return id.toString();
12 }
13 if (id === undefined) {
pineafan63fc5e22022-08-04 22:04:10 +010014 return "<a:_:946346549271732234>";
pineafan8b4b17f2022-02-27 20:42:52 +000015 } else if (id.toString().startsWith("a")) {
pineafan63fc5e22022-08-04 22:04:10 +010016 return `<a:_:${id.toString().slice(1, id.toString().length)}>`;
pineafan8b4b17f2022-02-27 20:42:52 +000017 }
pineafan377794f2022-04-18 19:01:01 +010018 return `<:_:${id}>`;
pineafan4f164f32022-02-26 22:07:12 +000019}
20
21export default getEmojiByName;