From 835b8d3f391f0addaa0a46350a3f7060781056fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Susa=C3=B1a?= Date: Tue, 9 Aug 2022 11:46:24 -0400 Subject: [PATCH] feat(Emoji): Add Methods (#99) * feat(Emoji): add methods * fix: redundancy Co-authored-by: Yuzu --- packages/api-types/src/utils/routes.ts | 3 ++- packages/core/src/structures/emojis.ts | 21 +++++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/packages/api-types/src/utils/routes.ts b/packages/api-types/src/utils/routes.ts index bddd09b..1447621 100644 --- a/packages/api-types/src/utils/routes.ts +++ b/packages/api-types/src/utils/routes.ts @@ -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`; } diff --git a/packages/core/src/structures/emojis.ts b/packages/core/src/structures/emojis.ts index 41d4b77..2bf6f05 100644 --- a/packages/core/src/structures/emojis.ts +++ b/packages/core/src/structures/emojis.ts @@ -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 { constructor(session: Session, data: DiscordEmoji) { @@ -64,7 +62,22 @@ export class GuildEmoji extends Emoji implements Model { return this; } + async fetchAuthor(): Promise { + const emoji = await this.session.rest.get(GUILD_EMOJIS(this.guildId, this.id)); + + if (emoji.user) return new User(this.session, emoji.user); + return null; + } + + setName(name: string): Promise { + return this.edit({ name }); + } + get url(): string { return EMOJI_URL(this.id, this.animated); } + + toString(): string { + return `<${this.animated ? 'a' : ''}:${this.name}:${this.id}>` + } }