This commit is contained in:
Michel Fedde 2025-06-18 22:53:54 +02:00
parent 441715675c
commit a79898b2e9
48 changed files with 2062 additions and 1503 deletions

View file

@ -4,30 +4,30 @@ import {Nullable} from "../types/Nullable";
export class IconCache {
private existingIcons: Map<string, string> | undefined;
constructor(
private readonly client: DiscordClient
) {
}
public get(iconName: string): Snowflake | null {
if (!this.existingIcons?.has(iconName)) {
return null;
}
return this.existingIcons?.get(iconName) ?? null;
}
public getEmoji(iconName: string): string {
const id = this.get(iconName);
return formatEmoji({
id,
name: iconName
});
}
public async set(iconName: string, pngBuffer: Buffer) {
const pngBase64 = pngBuffer.toString("base64");
const iconDataUrl = `data:image/png;base64,${pngBase64}`;
@ -42,23 +42,23 @@ export class IconCache {
}
)
}
public async populate() {
if (this.existingIcons != null) {
return;
}
const existingEmojis: Nullable<DiscordIconRequest> = await this.client.RESTClient.get(
Routes.applicationEmojis(this.client.ApplicationId)
)
if (!existingEmojis) {
return;
}
this.existingIcons = new Map<string, string>(
existingEmojis.items.map((item) => {
return [ item.name, item.id ]
return [item.name, item.id]
})
)
}