add function for resolving stickers for future use

This commit is contained in:
MathMan05 committed 2026-03-03 20:36:33 -06:00
1 parent 4493d7cea8
commit f1fffc0b66
1 file changed
+24
+24
View File
@@ -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;