From 621840d1aab320aedd7bc52a733c350c011be19f Mon Sep 17 00:00:00 2001 From: MARCROCK22 <57925328+MARCROCK22@users.noreply.github.com> Date: Thu, 21 Nov 2024 11:48:43 -0400 Subject: [PATCH] fix: voiceChannel#states types (#300) --- src/common/shorters/application.ts | 16 ++++++------ src/common/shorters/bans.ts | 4 +-- src/common/shorters/channels.ts | 6 ++--- src/common/shorters/members.ts | 4 +-- src/common/shorters/roles.ts | 2 +- src/common/shorters/threads.ts | 4 +-- src/structures/Message.ts | 4 +-- src/structures/VoiceState.ts | 2 +- src/structures/channels.ts | 39 ++++++++++++++++++------------ 9 files changed, 44 insertions(+), 37 deletions(-) diff --git a/src/common/shorters/application.ts b/src/common/shorters/application.ts index d4c0730..dd9224f 100644 --- a/src/common/shorters/application.ts +++ b/src/common/shorters/application.ts @@ -13,7 +13,7 @@ export class ApplicationShorter extends BaseShorter { * @param applicationId The ID of the application. * @returns The emojis. */ - async listEmojis(applicationId: string) { + listEmojis(applicationId: string) { return this.client.proxy.applications(applicationId).emojis.get(); } /** @@ -22,7 +22,7 @@ export class ApplicationShorter extends BaseShorter { * @param emojiId The ID of the emoji. * @returns The emoji. */ - async getEmoji(applicationId: string, emojiId: string) { + getEmoji(applicationId: string, emojiId: string) { return this.client.proxy.applications(applicationId).emojis(emojiId).get(); } @@ -33,7 +33,7 @@ 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(applicationId: string, body: RESTPostAPIApplicationEmojiJSONBody) { + createEmoji(applicationId: string, body: RESTPostAPIApplicationEmojiJSONBody) { return this.client.proxy.applications(applicationId).emojis.post({ body }); } @@ -42,7 +42,7 @@ export class ApplicationShorter extends BaseShorter { * @param applicationId The ID of the application. * @param [query] The query parameters. */ - async listEntitlements(applicationId: string, query?: RESTGetAPIEntitlementsQuery) { + listEntitlements(applicationId: string, query?: RESTGetAPIEntitlementsQuery) { return this.client.proxy .applications(applicationId) .entitlements.get({ query }) @@ -54,7 +54,7 @@ export class ApplicationShorter extends BaseShorter { * @param applicationId The ID of the application. * @param entitlementId The ID of the entitlement. */ - async consumeEntitlement(applicationId: string, entitlementId: string) { + consumeEntitlement(applicationId: string, entitlementId: string) { return this.client.proxy.applications(applicationId).entitlements(entitlementId).consume.post(); } @@ -63,7 +63,7 @@ export class ApplicationShorter extends BaseShorter { * @param applicationId The ID of the application. * @param body The body of the request. */ - async createTestEntitlement(applicationId: string, body: RESTPostAPIEntitlementBody) { + createTestEntitlement(applicationId: string, body: RESTPostAPIEntitlementBody) { return this.client.proxy .applications(applicationId) .entitlements.post({ body }) @@ -75,7 +75,7 @@ export class ApplicationShorter extends BaseShorter { * @param applicationId The ID of the application. * @param entitlementId The ID of the entitlement. */ - async deleteTestEntitlement(applicationId: string, entitlementId: string) { + deleteTestEntitlement(applicationId: string, entitlementId: string) { return this.client.proxy.applications(applicationId).entitlements(entitlementId).delete(); } @@ -84,7 +84,7 @@ export class ApplicationShorter extends BaseShorter { * @param applicationId The ID of the application. * @returns The SKUs. */ - async listSKUs(applicationId: string) { + listSKUs(applicationId: string) { return this.client.proxy.applications(applicationId).skus.get(); } } diff --git a/src/common/shorters/bans.ts b/src/common/shorters/bans.ts index 5f50eac..18b1685 100644 --- a/src/common/shorters/bans.ts +++ b/src/common/shorters/bans.ts @@ -26,8 +26,8 @@ export class BanShorter extends BaseShorter { * @param memberId The ID of the member to unban. * @param reason The reason for unbanning the member. */ - async remove(guildId: string, memberId: string, reason?: string) { - await this.client.proxy.guilds(guildId).bans(memberId).delete({ reason }); + remove(guildId: string, memberId: string, reason?: string) { + return this.client.proxy.guilds(guildId).bans(memberId).delete({ reason }); } /** diff --git a/src/common/shorters/channels.ts b/src/common/shorters/channels.ts index 80f0c95..e52a6ad 100644 --- a/src/common/shorters/channels.ts +++ b/src/common/shorters/channels.ts @@ -86,8 +86,8 @@ export class ChannelShorter extends BaseShorter { * @param id The ID of the channel. * @returns A Promise that resolves when the typing indicator is successfully sent. */ - async typing(id: string): Promise { - await this.client.proxy.channels(id).typing.post(); + typing(id: string): Promise { + return this.client.proxy.channels(id).typing.post(); } async pins(channelId: string): Promise { @@ -129,7 +129,7 @@ export class ChannelShorter extends BaseShorter { * @param reason The reason for unpinning the message. * @returns A promise that resolves when the thread is succesfully created. */ - async thread( + thread( channelId: string, body: RESTPostAPIChannelThreadsJSONBody | RESTPostAPIGuildForumThreadsJSONBody, reason?: string, diff --git a/src/common/shorters/members.ts b/src/common/shorters/members.ts index 4da2dd5..727f59d 100644 --- a/src/common/shorters/members.ts +++ b/src/common/shorters/members.ts @@ -65,8 +65,8 @@ export class MemberShorter extends BaseShorter { * @param memberId The ID of the member to unban. * @param reason The reason for unbanning the member. */ - async unban(guildId: string, memberId: string, reason?: string) { - await this.client.proxy.guilds(guildId).bans(memberId).delete({ reason }); + unban(guildId: string, memberId: string, reason?: string) { + return this.client.proxy.guilds(guildId).bans(memberId).delete({ reason }); } /** diff --git a/src/common/shorters/roles.ts b/src/common/shorters/roles.ts index 700d5c6..81b8a47 100644 --- a/src/common/shorters/roles.ts +++ b/src/common/shorters/roles.ts @@ -103,7 +103,7 @@ export class RoleShorter extends BaseShorter { }); if (!this.client.cache.hasRolesIntent) { await this.client.cache.roles?.set( - roles.map(x => [x.id, x]), + roles.map(x => [x.id, x] as [string, any]), guildId, ); } diff --git a/src/common/shorters/threads.ts b/src/common/shorters/threads.ts index 80fd9d0..f868dd4 100644 --- a/src/common/shorters/threads.ts +++ b/src/common/shorters/threads.ts @@ -20,7 +20,7 @@ export class ThreadShorter extends BaseShorter { * @param reason The reason for unpinning the message. * @returns A promise that resolves when the thread is succesfully created. */ - async create( + create( channelId: string, body: RESTPostAPIChannelThreadsJSONBody | RESTPostAPIGuildForumThreadsJSONBody, reason?: string, @@ -42,7 +42,7 @@ export class ThreadShorter extends BaseShorter { ); } - async fromMessage( + fromMessage( channelId: string, messageId: string, options: RESTPostAPIChannelMessagesThreadsJSONBody & { reason?: string }, diff --git a/src/structures/Message.ts b/src/structures/Message.ts index 3ae886a..77edfea 100644 --- a/src/structures/Message.ts +++ b/src/structures/Message.ts @@ -68,12 +68,12 @@ export class BaseMessage extends DiscordBase { return Formatter.messageLink(this.guildId!, this.channelId, this.id); } - guild(force = false) { + async guild(force = false) { if (!this.guildId) return; return this.client.guilds.fetch(this.guildId, force); } - async channel(force = false) { + channel(force = false) { return this.client.channels.fetch(this.channelId, force); } diff --git a/src/structures/VoiceState.ts b/src/structures/VoiceState.ts index b5b975c..62b7dd1 100644 --- a/src/structures/VoiceState.ts +++ b/src/structures/VoiceState.ts @@ -30,7 +30,7 @@ export class VoiceState extends Base { return this.client.users.fetch(this.userId, force); } - channel(force?: boolean) { + async channel(force?: boolean) { if (!this.channelId) return; return this.client.channels.fetch(this.channelId, force) as Promise; } diff --git a/src/structures/channels.ts b/src/structures/channels.ts index 334d469..f298c53 100644 --- a/src/structures/channels.ts +++ b/src/structures/channels.ts @@ -1,4 +1,4 @@ -import { Collection, Formatter, type RawFile } from '..'; +import { Collection, Formatter, type RawFile, type ReturnCache } from '..'; import { ActionRow, Embed, PollBuilder, resolveAttachment } from '../builders'; import { type BaseChannelStructure, @@ -15,16 +15,18 @@ import { type ThreadChannelStructure, Transformers, type VoiceChannelStructure, + type VoiceStateStructure, } from '../client'; import type { UsingClient } from '../commands'; -import type { - EmojiResolvable, - MessageCreateBodyRequest, - MessageUpdateBodyRequest, - MethodContext, - ObjectToLower, - StringToNumber, - ToClass, +import { + type EmojiResolvable, + type MessageCreateBodyRequest, + type MessageUpdateBodyRequest, + type MethodContext, + type ObjectToLower, + type StringToNumber, + type ToClass, + fakePromise, } from '../common'; import { mix } from '../deps/mixer'; import { @@ -376,7 +378,7 @@ export class ThreadOnlyMethods extends DiscordBase { return this.edit({ default_thread_rate_limit_per_user: rate }, reason); } - async thread(body: RESTPostAPIGuildForumThreadsJSONBody, reason?: string) { + thread(body: RESTPostAPIGuildForumThreadsJSONBody, reason?: string) { return this.client.channels.thread(this.id, body, reason); } } @@ -404,11 +406,16 @@ export class VoiceChannelMethods extends DiscordBase { return this.client.channels.setVoiceStatus(this.id, status); } - async states() { - if (!this.guildId) return []; - const states = await this.cache.voiceStates?.values(this.guildId); - if (!states?.length) return []; - return states.filter(state => state.channelId === this.id); + states(): ReturnCache { + if (!this.guildId) return this.cache.adapter.isAsync ? (Promise.resolve([]) as never) : []; + return fakePromise( + this.cache.voiceStates?.values(this.guildId) ?? + (this.cache.adapter.isAsync + ? (Promise.resolve([]) as Promise) + : ([] as VoiceStateStructure[])), + ).then(states => { + return states.filter(state => state.channelId === this.id); + }); } public async members(force?: boolean) { @@ -447,7 +454,7 @@ export class WebhookChannelMethods extends DiscordBase { static channel(ctx: MethodContext<{ channelId: string }>) { return { list: () => ctx.client.webhooks.listFromChannel(ctx.channelId), - create: async (body: RESTPostAPIChannelWebhookJSONBody) => ctx.client.webhooks.create(ctx.channelId, body), + create: (body: RESTPostAPIChannelWebhookJSONBody) => ctx.client.webhooks.create(ctx.channelId, body), }; } }