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}>` + } }