Adds ICS
This commit is contained in:
parent
441715675c
commit
a79898b2e9
48 changed files with 2062 additions and 1503 deletions
|
|
@ -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]
|
||||
})
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue