feat(Emoji): Add Methods (#99)

* feat(Emoji): add methods

* fix: redundancy

Co-authored-by: Yuzu <yuzuru@programmer.net>
This commit is contained in:
Marcos Susaña 2022-08-09 11:46:24 -04:00 committed by GitHub
parent 4d779e6bb2
commit 835b8d3f39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 5 deletions

View File

@ -128,7 +128,8 @@ export function USER_DM() {
return `/users/@me/channels`;
}
export function GUILD_EMOJIS(guildId: Snowflake): string {
export function GUILD_EMOJIS(guildId: Snowflake, emojiId?: Snowflake): string {
if (emojiId) return `/guilds/${guildId}/emojis/${emojiId}`;
return `/guilds/${guildId}/emojis`;
}

View File

@ -1,11 +1,9 @@
import type { Session } from '../biscuit';
import type { Model } from './base';
import type { Snowflake } from '../snowflakes';
import type { DiscordEmoji } from '@biscuitland/api-types';
import type { ModifyGuildEmoji } from './guilds';
import { Guild } from './guilds';
import { Guild, ModifyGuildEmoji} from './guilds';
import { User } from './user';
import { EMOJI_URL } from '@biscuitland/api-types';
import { EMOJI_URL, DiscordEmoji, GUILD_EMOJIS } from '@biscuitland/api-types';
export class Emoji implements Partial<Model> {
constructor(session: Session, data: DiscordEmoji) {
@ -64,7 +62,22 @@ export class GuildEmoji extends Emoji implements Model {
return this;
}
async fetchAuthor(): Promise<User | null> {
const emoji = await this.session.rest.get<DiscordEmoji>(GUILD_EMOJIS(this.guildId, this.id));
if (emoji.user) return new User(this.session, emoji.user);
return null;
}
setName(name: string): Promise<GuildEmoji> {
return this.edit({ name });
}
get url(): string {
return EMOJI_URL(this.id, this.animated);
}
toString(): string {
return `<${this.animated ? 'a' : ''}:${this.name}:${this.id}>`
}
}