diff --git a/src/common/shorters/application.ts b/src/common/shorters/application.ts index a9c51eb..0d3de0a 100644 --- a/src/common/shorters/application.ts +++ b/src/common/shorters/application.ts @@ -1,5 +1,10 @@ import { CacheFrom, resolveImage } from '../..'; -import { type ApplicationEmojiStructure, type EntitlementStructure, Transformers } from '../../client'; +import { + type ApplicationEmojiStructure, + type ApplicationStructure, + type EntitlementStructure, + Transformers, +} from '../../client'; import type { APIEntitlement, RESTGetAPIEntitlementsQuery, @@ -23,7 +28,7 @@ export class ApplicationShorter extends BaseShorter { if (cached?.length) return cached; } const data = await this.client.proxy.applications(this.client.applicationId).emojis.get(); - this.client.cache.emojis?.set( + await this.client.cache.emojis?.set( CacheFrom.Rest, data.items.map(e => [e.id, e]), this.client.applicationId, @@ -41,7 +46,7 @@ export class ApplicationShorter extends BaseShorter { if (cached) return cached; } const data = await this.client.proxy.applications(this.client.applicationId).emojis(emojiId).get(); - this.client.cache.emojis?.set(CacheFrom.Rest, data.id, this.client.applicationId, data); + await this.client.cache.emojis?.set(CacheFrom.Rest, data.id, this.client.applicationId, data); return Transformers.ApplicationEmoji(this.client, data); } @@ -51,11 +56,11 @@ export class ApplicationShorter extends BaseShorter { * @param body.image The [image data string](https://discord.com/developers/docs/reference#image-data) of the emoji. * @returns The created emoji. */ - async createEmoji(raw: ApplicationEmojiResolvable) { + async createEmoji(raw: ApplicationEmojiResolvable): Promise { const data = await this.client.proxy .applications(this.client.applicationId) .emojis.post({ body: { ...raw, image: await resolveImage(raw.image) } }); - this.client.cache.emojis?.set(CacheFrom.Rest, data.id, this.client.applicationId, data); + await this.client.cache.emojis?.set(CacheFrom.Rest, data.id, this.client.applicationId, data); return Transformers.ApplicationEmoji(this.client, data); } @@ -65,9 +70,9 @@ export class ApplicationShorter extends BaseShorter { * @param body.name The new name of the emoji. * @returns The edited emoji. */ - async editEmoji(emojiId: string, body: RESTPatchAPIApplicationEmojiJSONBody) { + async editEmoji(emojiId: string, body: RESTPatchAPIApplicationEmojiJSONBody): Promise { const data = await this.client.proxy.applications(this.client.applicationId).emojis(emojiId).patch({ body }); - this.client.cache.emojis?.patch(CacheFrom.Rest, emojiId, this.client.applicationId, data); + await this.client.cache.emojis?.patch(CacheFrom.Rest, emojiId, this.client.applicationId, data); return Transformers.ApplicationEmoji(this.client, data); } @@ -125,12 +130,12 @@ export class ApplicationShorter extends BaseShorter { return this.client.proxy.applications(this.client.applicationId).skus.get(); } - async fetch() { + async fetch(): Promise { const data = await this.client.proxy.applications('@me').get(); return Transformers.Application(this.client, data); } - async edit(body: RESTPatchCurrentApplicationJSONBody) { + async edit(body: RESTPatchCurrentApplicationJSONBody): Promise { const data = await this.client.proxy.applications('@me').patch({ body }); return Transformers.Application(this.client, data); } diff --git a/src/common/shorters/channels.ts b/src/common/shorters/channels.ts index 716dd6f..24f6c26 100644 --- a/src/common/shorters/channels.ts +++ b/src/common/shorters/channels.ts @@ -30,8 +30,8 @@ export class ChannelShorter extends BaseShorter { async raw(id: string, force?: boolean): Promise { if (!force) { const channel = await this.client.cache.channels?.raw(id); - const overwrites = await this.client.cache.overwrites?.raw(id); if (channel) { + const overwrites = await this.client.cache.overwrites?.raw(id); if (overwrites) (channel as APIGuildChannel).permission_overwrites = overwrites; return channel as APIChannel; } diff --git a/src/structures/Application.ts b/src/structures/Application.ts index ca82cb3..efabdde 100644 --- a/src/structures/Application.ts +++ b/src/structures/Application.ts @@ -1,4 +1,5 @@ import type { UsingClient } from '..'; +import type { ApplicationEmojiStructure, ApplicationStructure } from '../client'; import type { ApplicationEmojiResolvable, ObjectToLower } from '../common'; import type { APIApplication, @@ -21,14 +22,14 @@ export class Application extends DiscordBase { /** * Fetch the current application. */ - fetch() { + fetch(): Promise { return this.client.applications.fetch(); } /** * Edit the current application. */ - edit(data: RESTPatchCurrentApplicationJSONBody) { + edit(data: RESTPatchCurrentApplicationJSONBody): Promise { return this.client.applications.edit(data); } @@ -43,19 +44,20 @@ export class Application extends DiscordBase { /** * Get an application emoji. */ - fetch: (id: string) => this.client.applications.getEmoji(id), + fetch: (id: string): Promise => this.client.applications.getEmoji(id), /** * Get the application emojis. */ - list: () => this.client.applications.listEmojis(), + list: (): Promise => this.client.applications.listEmojis(), /** * Create an application emoji. */ - create: (data: ApplicationEmojiResolvable) => this.client.applications.createEmoji(data), + create: (data: ApplicationEmojiResolvable): Promise => + this.client.applications.createEmoji(data), /** * Edit an application emoji. */ - edit: (emojiId: string, body: RESTPatchAPIApplicationEmojiJSONBody) => + edit: (emojiId: string, body: RESTPatchAPIApplicationEmojiJSONBody): Promise => this.client.applications.editEmoji(emojiId, body), }; } diff --git a/src/structures/Emoji.ts b/src/structures/Emoji.ts index 0195c21..a64c7d8 100644 --- a/src/structures/Emoji.ts +++ b/src/structures/Emoji.ts @@ -1,6 +1,12 @@ import type { BaseCDNUrlOptions } from '../api'; import type { ReturnCache } from '../cache'; -import type { GuildEmojiStructure, GuildStructure } from '../client'; +import { + type ApplicationEmojiStructure, + type GuildEmojiStructure, + type GuildStructure, + Transformers, + type UserStructure, +} from '../client'; import type { UsingClient } from '../commands'; import { type EmojiShorter, Formatter, type MethodContext, type ObjectToLower, type When } from '../common'; import type { @@ -9,16 +15,15 @@ import type { RESTPatchAPIApplicationEmojiJSONBody, RESTPatchAPIGuildEmojiJSONBody, } from '../types'; -import { User } from './User'; import { DiscordBase } from './extra/DiscordBase'; export interface Emoji extends DiscordBase, ObjectToLower> {} export class Emoji extends DiscordBase { - user: When; + user: When; constructor(client: UsingClient, data: APIEmoji) { super(client, { ...data, id: data.id! }); - this.user = (data.user && new User(client, data.user)) as never; + this.user = (data.user && Transformers.User(client, data.user)) as never; } url(options?: BaseCDNUrlOptions) { @@ -93,11 +98,11 @@ export class ApplicationEmoji extends Emoji { super(client, data); } - fetch() { + fetch(): Promise { return this.client.applications.getEmoji(this.id); } - edit(body: RESTPatchAPIApplicationEmojiJSONBody) { + edit(body: RESTPatchAPIApplicationEmojiJSONBody): Promise { return this.client.applications.editEmoji(this.id, body); }