Adds deployment for icons
This commit is contained in:
parent
154002f6f3
commit
0e10ea3cab
14 changed files with 1449 additions and 53 deletions
52
source/Icons/IconCache.ts
Normal file
52
source/Icons/IconCache.ts
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import {Routes} from "discord.js";
|
||||
import {DiscordClient} from "../Discord/DiscordClient";
|
||||
|
||||
export class IconCache {
|
||||
private existingIcons: Map<string, string>|null;
|
||||
|
||||
constructor(
|
||||
private readonly client: DiscordClient
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
public get(iconName: string): string | null {
|
||||
if (!this.existingIcons?.has(iconName) ?? false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.existingIcons?.get(iconName) ?? null;
|
||||
}
|
||||
|
||||
public async set(iconName: string, pngBuffer: Buffer) {
|
||||
const pngBase64 = pngBuffer.toString("base64");
|
||||
const iconDataUrl = `data:image/png;base64,${pngBase64}`;
|
||||
|
||||
await this.client.RESTClient.post(
|
||||
Routes.applicationEmojis(this.client.ApplicationId),
|
||||
{
|
||||
body: {
|
||||
name: iconName,
|
||||
image: iconDataUrl
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
public async populate() {
|
||||
if (this.existingIcons != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const existingEmojis: DiscordIconRequest = await this.client.RESTClient.get(
|
||||
Routes.applicationEmojis(this.client.ApplicationId)
|
||||
)
|
||||
|
||||
this.existingIcons = new Map<string, string>(
|
||||
existingEmojis.items.map((item) => {
|
||||
return [ item.name, item.id ]
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue