diff --git a/src/client/base.ts b/src/client/base.ts index 6b749a0..983b99a 100644 --- a/src/client/base.ts +++ b/src/client/base.ts @@ -42,6 +42,7 @@ import { import { promises } from 'node:fs'; import { HandleCommand } from '../commands/handle'; import { BanShorter } from '../common/shorters/bans'; +import { VoiceStateShorter } from '../common/shorters/voiceStates'; import type { Awaitable, DeepPartial, IntentStrings, OmitInsert, PermissionStrings, When } from '../common/types/util'; import type { ComponentCommand, ComponentContext, ModalCommand, ModalContext } from '../components'; import { ComponentHandler } from '../components/handler'; @@ -75,6 +76,7 @@ export class BaseClient { threads = new ThreadShorter(this); bans = new BanShorter(this); interactions = new InteractionShorter(this); + voiceStates = new VoiceStateShorter(this); debugger?: Logger; diff --git a/src/commands/applications/chatcontext.ts b/src/commands/applications/chatcontext.ts index 7daa06f..f770422 100644 --- a/src/commands/applications/chatcontext.ts +++ b/src/commands/applications/chatcontext.ts @@ -136,11 +136,10 @@ export class CommandContext< } async fetchResponse(): Promise< - If + If > { if (this.interaction) return this.interaction.fetchResponse(); - this.messageResponse = await this.messageResponse?.fetch(); - return this.messageResponse as undefined; + return (this.messageResponse = (await this.messageResponse!.fetch()) as never); } channel(mode?: 'rest' | 'flow'): Promise>; diff --git a/src/commands/applications/entrycontext.ts b/src/commands/applications/entrycontext.ts index b4c932b..47d4d51 100644 --- a/src/commands/applications/entrycontext.ts +++ b/src/commands/applications/entrycontext.ts @@ -1,17 +1,11 @@ import type { ReturnCache } from '../..'; -import type { - GuildMemberStructure, - GuildStructure, - MessageStructure, - WebhookMessageStructure, -} from '../../client/transformers'; +import type { GuildMemberStructure, GuildStructure } from '../../client/transformers'; import type { InteractionCreateBodyRequest, InteractionMessageUpdateBodyRequest, MakeRequired, ModalCreateBodyRequest, UnionToTuple, - When, } from '../../common'; import type { AllChannels, EntryPointInteraction } from '../../structures'; import { MessageFlags } from '../../types'; @@ -43,22 +37,16 @@ export class EntryPointContext ex return this.command.name; } - write( - body: InteractionCreateBodyRequest, - withResponse?: WR, - ): Promise> { - return this.interaction.write(body, withResponse); + write(body: InteractionCreateBodyRequest, withResponse?: WR) { + return this.interaction.write(body, withResponse); } modal(body: ModalCreateBodyRequest) { return this.interaction.modal(body); } - deferReply( - ephemeral = false, - withResponse?: WR, - ): Promise> { - return this.interaction.deferReply(ephemeral ? MessageFlags.Ephemeral : undefined, withResponse); + deferReply(ephemeral = false, withResponse?: WR) { + return this.interaction.deferReply(ephemeral ? MessageFlags.Ephemeral : undefined, withResponse); } editResponse(body: InteractionMessageUpdateBodyRequest) { @@ -72,8 +60,8 @@ export class EntryPointContext ex editOrReply( body: InteractionCreateBodyRequest | InteractionMessageUpdateBodyRequest, withResponse?: WR, - ): Promise> { - return this.interaction.editOrReply(body as InteractionCreateBodyRequest, withResponse); + ) { + return this.interaction.editOrReply(body as InteractionCreateBodyRequest, withResponse); } fetchResponse() { diff --git a/src/commands/applications/menucontext.ts b/src/commands/applications/menucontext.ts index fa0c7b3..3b031c3 100644 --- a/src/commands/applications/menucontext.ts +++ b/src/commands/applications/menucontext.ts @@ -5,7 +5,6 @@ import { type MessageStructure, Transformers, type UserStructure, - type WebhookMessageStructure, } from '../../client/transformers'; import { type InteractionCreateBodyRequest, @@ -13,7 +12,6 @@ import { type MakeRequired, type ModalCreateBodyRequest, type UnionToTuple, - type When, toSnakeCase, } from '../../common'; import type { AllChannels, MessageCommandInteraction, UserCommandInteraction } from '../../structures'; @@ -68,22 +66,16 @@ export class MenuCommandContext< return this.command.name; } - write( - body: InteractionCreateBodyRequest, - withResponse?: WR, - ): Promise> { - return this.interaction.write(body, withResponse); + write(body: InteractionCreateBodyRequest, withResponse?: WR) { + return this.interaction.write(body, withResponse); } modal(body: ModalCreateBodyRequest) { return this.interaction.modal(body); } - deferReply( - ephemeral = false, - withResponse?: WR, - ): Promise> { - return this.interaction.deferReply(ephemeral ? MessageFlags.Ephemeral : undefined, withResponse); + deferReply(ephemeral = false, withResponse?: WR) { + return this.interaction.deferReply(ephemeral ? MessageFlags.Ephemeral : undefined, withResponse); } editResponse(body: InteractionMessageUpdateBodyRequest) { @@ -97,8 +89,8 @@ export class MenuCommandContext< editOrReply( body: InteractionCreateBodyRequest | InteractionMessageUpdateBodyRequest, withResponse?: WR, - ): Promise> { - return this.interaction.editOrReply(body as InteractionCreateBodyRequest, withResponse); + ) { + return this.interaction.editOrReply(body as InteractionCreateBodyRequest, withResponse); } fetchResponse() { diff --git a/src/common/shorters/voiceStates.ts b/src/common/shorters/voiceStates.ts new file mode 100644 index 0000000..90b318d --- /dev/null +++ b/src/common/shorters/voiceStates.ts @@ -0,0 +1,15 @@ +import { BaseShorter } from './base'; + +export class VoiceStateShorter extends BaseShorter { + requestSpeak(guildId: string, date: string) { + return this.client.proxy.guilds(guildId)['voice-states']['@me'].patch({ + body: { request_to_speak_timestamp: date }, + }); + } + + setSuppress(guildId: string, suppress: boolean) { + return this.client.proxy.guilds(guildId)['voice-states']['@me'].patch({ + body: { suppress }, + }); + } +} diff --git a/src/common/shorters/webhook.ts b/src/common/shorters/webhook.ts index fee71b8..dbeb0bc 100644 --- a/src/common/shorters/webhook.ts +++ b/src/common/shorters/webhook.ts @@ -140,14 +140,14 @@ export class WebhookShorter extends BaseShorter { * @param token The token of the webhook. * @param messageId The ID of the message to fetch. * @param threadId The ID of the thread the message belongs to. - * @returns A Promise that resolves to the fetched message, or undefined if not found. + * @returns A Promise that resolves to the fetched message */ async fetchMessage(webhookId: string, token: string, messageId: string, threadId?: string) { const message = await this.client.proxy .webhooks(webhookId)(token) .messages(messageId) .get({ auth: false, query: threadId ? { thread_id: threadId } : undefined }); - return message ? Transformers.WebhookMessage(this.client, message, webhookId, token) : undefined; + return Transformers.WebhookMessage(this.client, message, webhookId, token); } async listFromGuild(guildId: string) { diff --git a/src/components/componentcontext.ts b/src/components/componentcontext.ts index 10ed017..486e09c 100644 --- a/src/components/componentcontext.ts +++ b/src/components/componentcontext.ts @@ -9,12 +9,7 @@ import type { StringSelectMenuInteraction, UserSelectMenuInteraction, } from '..'; -import type { - GuildMemberStructure, - GuildStructure, - MessageStructure, - WebhookMessageStructure, -} from '../client/transformers'; +import type { GuildMemberStructure, GuildStructure } from '../client/transformers'; import type { CommandMetadata, ExtendContext, GlobalMetadata, RegisteredMiddlewares, UsingClient } from '../commands'; import { BaseContext } from '../commands/basecontext'; import type { @@ -24,7 +19,6 @@ import type { MakeRequired, ModalCreateBodyRequest, UnionToTuple, - When, } from '../common'; import { ComponentType, MessageFlags } from '../types'; @@ -77,15 +71,15 @@ export class ComponentContext< * @param fetchReply - Whether to fetch the reply or not. */ write(body: InteractionCreateBodyRequest, fetchReply?: FR) { - return this.interaction.write(body, fetchReply); + return this.interaction.write(body, fetchReply); } /** * Defers the reply to the interaction. * @param ephemeral - Whether the reply should be ephemeral or not. */ - deferReply(ephemeral = false) { - return this.interaction.deferReply(ephemeral ? MessageFlags.Ephemeral : undefined); + deferReply(ephemeral = false, fetchReply?: FR) { + return this.interaction.deferReply(ephemeral ? MessageFlags.Ephemeral : undefined, fetchReply); } /** @@ -119,8 +113,15 @@ export class ComponentContext< editOrReply( body: InteractionCreateBodyRequest | InteractionMessageUpdateBodyRequest, fetchReply?: FR, - ): Promise> { - return this.interaction.editOrReply(body as InteractionCreateBodyRequest, fetchReply); + ) { + return this.interaction.editOrReply(body as InteractionCreateBodyRequest, fetchReply); + } + + /** + * @returns A Promise that resolves to the fetched message + */ + fetchResponse() { + return this.interaction.fetchResponse(); } /** diff --git a/src/components/modalcontext.ts b/src/components/modalcontext.ts index 3f61830..7a1f3fd 100644 --- a/src/components/modalcontext.ts +++ b/src/components/modalcontext.ts @@ -1,10 +1,5 @@ import type { AllChannels, ModalCommand, ModalSubmitInteraction, ReturnCache } from '..'; -import type { - GuildMemberStructure, - GuildStructure, - MessageStructure, - WebhookMessageStructure, -} from '../client/transformers'; +import type { GuildMemberStructure, GuildStructure } from '../client/transformers'; import type { CommandMetadata, ExtendContext, GlobalMetadata, RegisteredMiddlewares, UsingClient } from '../commands'; import { BaseContext } from '../commands/basecontext'; import type { @@ -13,7 +8,6 @@ import type { MakeRequired, ModalCreateBodyRequest, UnionToTuple, - When, } from '../common'; import { MessageFlags } from '../types'; @@ -61,15 +55,15 @@ export class ModalContext extends * @param fetchReply - Whether to fetch the reply or not. */ write(body: InteractionCreateBodyRequest, fetchReply?: FR) { - return this.interaction.write(body, fetchReply); + return this.interaction.write(body, fetchReply); } /** * Defers the reply to the interaction. * @param ephemeral - Whether the reply should be ephemeral or not. */ - deferReply(ephemeral = false) { - return this.interaction.deferReply(ephemeral ? MessageFlags.Ephemeral : undefined); + deferReply(ephemeral = false, fetchReply?: FR) { + return this.interaction.deferReply(ephemeral ? MessageFlags.Ephemeral : undefined, fetchReply); } /** @@ -88,8 +82,15 @@ export class ModalContext extends editOrReply( body: InteractionCreateBodyRequest | InteractionMessageUpdateBodyRequest, fetchReply?: FR, - ): Promise> { - return this.interaction.editOrReply(body as InteractionCreateBodyRequest, fetchReply); + ) { + return this.interaction.editOrReply(body as InteractionCreateBodyRequest, fetchReply); + } + + /** + * @returns A Promise that resolves to the fetched message + */ + fetchResponse() { + return this.interaction.fetchResponse(); } /** diff --git a/src/structures/Message.ts b/src/structures/Message.ts index d8506a8..3ae886a 100644 --- a/src/structures/Message.ts +++ b/src/structures/Message.ts @@ -173,8 +173,12 @@ export class WebhookMessage extends BaseMessage { super(client, data); } + fetchWebhook() { + return this.client.webhooks.fetch(this.webhookId, this.webhookToken); + } + fetch() { - return this.api.webhooks(this.webhookId)(this.webhookToken).get(); + return this.client.webhooks.fetchMessage(this.webhookId, this.webhookToken, this.id, this.thread?.id); } edit(body: EditMessageWebhook) { diff --git a/src/structures/VoiceState.ts b/src/structures/VoiceState.ts index fd8602a..b5b975c 100644 --- a/src/structures/VoiceState.ts +++ b/src/structures/VoiceState.ts @@ -48,9 +48,7 @@ export class VoiceState extends Base { } async setSuppress(suppress = !this.suppress) { - await this.client.proxy.guilds(this.guildId)['voice-states']['@me'].patch({ - body: { suppress }, - }); + await this.client.voiceStates.setSuppress(this.guildId, suppress); this.suppress = suppress; } @@ -58,10 +56,7 @@ export class VoiceState extends Base { if (typeof date === 'string') date = new Date(date); if (Number.isNaN(date)) return Promise.reject('Invalid date'); date = date.toISOString(); - - await this.client.proxy.guilds(this.guildId)['voice-states']['@me'].patch({ - body: { request_to_speak_timestamp: date }, - }); + await this.client.voiceStates.requestSpeak(this.guildId, date); this.requestToSpeakTimestamp = date; }