mirror of
https://github.com/MathMan05/Fermi.git
synced 2026-10-25 14:42:24 +00:00
add function for resolving stickers for future use
This commit is contained in:
1 parent
4493d7cea8
commit
f1fffc0b66
1 file changed
+24
@@ -81,6 +81,30 @@ class Sticker extends SnowFlake {
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
static emojiMap = new WeakMap<Localuser, Map<string, Sticker | void>>();
|
||||
static async lookupEmoji(id: string, localuser: Localuser): Promise<Sticker | void> {
|
||||
const guild = localuser.guilds.find((guild) => guild.emojis.find((emoji) => emoji.id === id));
|
||||
if (guild) {
|
||||
const sticker = guild.stickers.find((_) => _.id === id);
|
||||
if (sticker) return sticker;
|
||||
}
|
||||
|
||||
const map = this.emojiMap.get(localuser) || new Map();
|
||||
this.emojiMap.set(localuser, map);
|
||||
|
||||
if (map.has(id)) return map.get(id);
|
||||
|
||||
const res = await fetch(localuser.info.api + `/stickers/${id}`, {
|
||||
headers: localuser.headers,
|
||||
});
|
||||
if (res.status === 403) {
|
||||
map.set(id, undefined);
|
||||
return undefined;
|
||||
}
|
||||
const json = (await res.json()) as stickerJson;
|
||||
map.set(id, json);
|
||||
return new Sticker(json, localuser);
|
||||
}
|
||||
static async stickerPicker(x: number, y: number, localuser: Localuser): Promise<Sticker> {
|
||||
let res: (r: Sticker) => void;
|
||||
this;
|
||||
|
||||
Reference in new issue
Block a user