pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 1 | import emojis from "../config/emojis.json" assert {type: "json"}; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 2 | |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 3 | function getEmojiByName(name: string, format?: string): string { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 4 | const split = name.split("."); |
| 5 | let id = emojis; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 6 | split.forEach(part => { |
| 7 | id = id[part]; |
| 8 | }); |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 9 | if ( format === "id" ) { |
| 10 | if (id === undefined) return "0"; |
| 11 | return id.toString(); |
| 12 | } |
| 13 | if (id === undefined) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 14 | return "<a:_:946346549271732234>"; |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 15 | } else if (id.toString().startsWith("a")) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 16 | return `<a:_:${id.toString().slice(1, id.toString().length)}>`; |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 17 | } |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 18 | return `<:_:${id}>`; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | export default getEmojiByName; |