harmony/src/managers/emojis.ts

35 lines
1.1 KiB
TypeScript
Raw Normal View History

import { Client } from '../models/client.ts'
import { Emoji } from '../structures/emoji.ts'
import { EmojiPayload } from '../types/emoji.ts'
2020-11-08 07:58:24 +00:00
import { GUILD_EMOJI } from '../types/endpoint.ts'
2020-11-04 12:38:00 +00:00
import { BaseManager } from './base.ts'
export class EmojisManager extends BaseManager<EmojiPayload, Emoji> {
2020-12-02 12:29:52 +00:00
constructor(client: Client) {
2020-11-08 08:47:01 +00:00
super(client, `emojis`, Emoji)
}
2020-12-02 12:29:52 +00:00
async get(key: string): Promise<Emoji | undefined> {
const raw = await this._get(key)
if (raw === undefined) return
const emoji = new this.DataType(this.client, raw)
2020-11-08 11:36:30 +00:00
if ((raw as any).guild_id !== undefined) {
const guild = await this.client.guilds.get((raw as any).guild_id)
2020-11-08 11:36:30 +00:00
if (guild !== undefined) emoji.guild = guild
}
return emoji
}
2020-12-02 12:29:52 +00:00
async fetch(guildID: string, id: string): Promise<Emoji> {
return await new Promise((resolve, reject) => {
this.client.rest
2020-11-08 08:47:01 +00:00
.get(GUILD_EMOJI(guildID, id))
2020-12-02 12:29:52 +00:00
.then(async (data) => {
2020-11-08 08:47:01 +00:00
await this.set(id, data as EmojiPayload)
resolve(new Emoji(this.client, data as EmojiPayload))
})
2020-12-02 12:29:52 +00:00
.catch((e) => reject(e))
})
}
}