feat: add AnyContext.followup (#318)

* fix: return support node18

* feat: support AnyContext.followup
This commit is contained in:
Marcos Susaña 2024-12-30 04:00:54 -04:00 committed by GitHub
parent ac2df8133b
commit ff55a78793
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 30 additions and 9 deletions

View File

@ -10,7 +10,11 @@ import type {
WebhookMessageStructure, WebhookMessageStructure,
} from '../../client/transformers'; } from '../../client/transformers';
import type { If, MakeRequired, UnionToTuple, When } from '../../common'; import type { If, MakeRequired, UnionToTuple, When } from '../../common';
import type { InteractionCreateBodyRequest, InteractionMessageUpdateBodyRequest } from '../../common/types/write'; import type {
InteractionCreateBodyRequest,
InteractionMessageUpdateBodyRequest,
MessageWebhookCreateBodyRequest,
} from '../../common/types/write';
import { type AllChannels, ChatInputCommandInteraction, type Message } from '../../structures'; import { type AllChannels, ChatInputCommandInteraction, type Message } from '../../structures';
import { MessageFlags } from '../../types'; import { MessageFlags } from '../../types';
import { BaseContext } from '../basecontext'; import { BaseContext } from '../basecontext';
@ -54,14 +58,6 @@ export class CommandContext<
metadata: CommandMetadata<UnionToTuple<M>> = {} as never; metadata: CommandMetadata<UnionToTuple<M>> = {} as never;
globalMetadata: GlobalMetadata = {}; globalMetadata: GlobalMetadata = {};
get proxy() {
return this.client.proxy;
}
get t() {
return this.client.t(this.interaction?.locale ?? this.client.langs.defaultLang ?? 'en-US');
}
get fullCommandName() { get fullCommandName() {
return this.resolver.fullCommandName; return this.resolver.fullCommandName;
} }
@ -136,6 +132,11 @@ export class CommandContext<
return this.write(body as InteractionCreateBodyRequest, withResponse); return this.write(body as InteractionCreateBodyRequest, withResponse);
} }
followup(body: MessageWebhookCreateBodyRequest) {
if (this.interaction) return this.interaction.followup(body);
return this.messageResponse!.reply(body);
}
async fetchResponse(): Promise< async fetchResponse(): Promise<
If<InferWithPrefix, WebhookMessageStructure | MessageStructure, WebhookMessageStructure> If<InferWithPrefix, WebhookMessageStructure | MessageStructure, WebhookMessageStructure>
> { > {

View File

@ -10,6 +10,7 @@ import type {
InteractionCreateBodyRequest, InteractionCreateBodyRequest,
InteractionMessageUpdateBodyRequest, InteractionMessageUpdateBodyRequest,
MakeRequired, MakeRequired,
MessageWebhookCreateBodyRequest,
ModalCreateBodyRequest, ModalCreateBodyRequest,
UnionToTuple, UnionToTuple,
When, When,
@ -77,6 +78,10 @@ export class EntryPointContext<M extends keyof RegisteredMiddlewares = never> ex
return this.interaction.editOrReply<WR>(body as InteractionCreateBodyRequest, withResponse); return this.interaction.editOrReply<WR>(body as InteractionCreateBodyRequest, withResponse);
} }
followup(body: MessageWebhookCreateBodyRequest) {
return this.interaction.followup(body);
}
fetchResponse(): Promise<WebhookMessageStructure> { fetchResponse(): Promise<WebhookMessageStructure> {
return this.interaction.fetchResponse(); return this.interaction.fetchResponse();
} }

View File

@ -11,6 +11,7 @@ import {
type InteractionCreateBodyRequest, type InteractionCreateBodyRequest,
type InteractionMessageUpdateBodyRequest, type InteractionMessageUpdateBodyRequest,
type MakeRequired, type MakeRequired,
type MessageWebhookCreateBodyRequest,
type ModalCreateBodyRequest, type ModalCreateBodyRequest,
type UnionToTuple, type UnionToTuple,
type When, type When,
@ -101,6 +102,10 @@ export class MenuCommandContext<
return this.interaction.editOrReply<WR>(body as InteractionCreateBodyRequest, withResponse); return this.interaction.editOrReply<WR>(body as InteractionCreateBodyRequest, withResponse);
} }
followup(body: MessageWebhookCreateBodyRequest) {
return this.interaction.followup(body);
}
fetchResponse(): Promise<WebhookMessageStructure> { fetchResponse(): Promise<WebhookMessageStructure> {
return this.interaction.fetchResponse(); return this.interaction.fetchResponse();
} }

View File

@ -23,6 +23,7 @@ import type {
InteractionCreateBodyRequest, InteractionCreateBodyRequest,
InteractionMessageUpdateBodyRequest, InteractionMessageUpdateBodyRequest,
MakeRequired, MakeRequired,
MessageWebhookCreateBodyRequest,
ModalCreateBodyRequest, ModalCreateBodyRequest,
UnionToTuple, UnionToTuple,
When, When,
@ -130,6 +131,10 @@ export class ComponentContext<
return this.interaction.editOrReply<FR>(body as InteractionCreateBodyRequest, fetchReply); return this.interaction.editOrReply<FR>(body as InteractionCreateBodyRequest, fetchReply);
} }
followup(body: MessageWebhookCreateBodyRequest) {
return this.interaction.followup(body);
}
/** /**
* @returns A Promise that resolves to the fetched message * @returns A Promise that resolves to the fetched message
*/ */

View File

@ -12,6 +12,7 @@ import type {
InteractionCreateBodyRequest, InteractionCreateBodyRequest,
InteractionMessageUpdateBodyRequest, InteractionMessageUpdateBodyRequest,
MakeRequired, MakeRequired,
MessageWebhookCreateBodyRequest,
ModalCreateBodyRequest, ModalCreateBodyRequest,
UnionToTuple, UnionToTuple,
When, When,
@ -99,6 +100,10 @@ export class ModalContext<M extends keyof RegisteredMiddlewares = never> extends
return this.interaction.editOrReply<FR>(body as InteractionCreateBodyRequest, fetchReply); return this.interaction.editOrReply<FR>(body as InteractionCreateBodyRequest, fetchReply);
} }
followup(body: MessageWebhookCreateBodyRequest) {
return this.interaction.followup(body);
}
/** /**
* @returns A Promise that resolves to the fetched message * @returns A Promise that resolves to the fetched message
*/ */