minor fixes

This commit is contained in:
Yuzu 2022-10-12 17:59:36 -05:00
parent 6c6f982100
commit 06c4cd15c0
2 changed files with 35 additions and 2 deletions

View File

@ -306,6 +306,13 @@ export abstract class BaseInteraction implements Model {
return this.sendFollowUp(data); return this.sendFollowUp(data);
} }
/**
* internal usage only, same as respond but doesn't tries to follow up
* */
async respond_(resp: InteractionResponse): Promise<void> {
if (!this.responded) return this.respond(resp) as Promise<undefined>;
}
// start custom methods // start custom methods
async respondWith( async respondWith(
@ -328,6 +335,31 @@ export abstract class BaseInteraction implements Model {
}); });
} }
/**
* taken from Detritus
* try respond, try edit, try follow up
* */
async editOrReply(resp: InteractionResponseWithData & EditWebhookMessage) {
if (this.responded) {
return this.editReply(resp);
}
let type: InteractionResponseTypes = InteractionResponseTypes.ChannelMessageWithSource;
switch (this.type) {
case InteractionTypes.ApplicationCommand:
type = InteractionResponseTypes.ChannelMessageWithSource;
break;
case InteractionTypes.MessageComponent:
type = InteractionResponseTypes.UpdateMessage;
break;
}
const result = await this.respond({ type, data: resp });
return result;
}
// end custom methods // end custom methods
} }

View File

@ -21,6 +21,7 @@ import {
WEBHOOK_MESSAGE, WEBHOOK_MESSAGE,
WEBHOOK_MESSAGE_ORIGINAL, WEBHOOK_MESSAGE_ORIGINAL,
} from '@biscuitland/api-types'; } from '@biscuitland/api-types';
import { NewEmbed } from './embed';
export type ExecuteWebhookOptions = WebhookOptions & export type ExecuteWebhookOptions = WebhookOptions &
CreateMessage & { avatarUrl?: string; username?: string }; CreateMessage & { avatarUrl?: string; username?: string };
@ -87,7 +88,7 @@ export class Webhook implements Model {
const data = { const data = {
content: options?.content, content: options?.content,
embeds: options?.embeds, embeds: options?.embeds?.map(NewEmbed),
tts: options?.tts, tts: options?.tts,
allowed_mentions: options?.allowedMentions, allowed_mentions: options?.allowedMentions,
components: options?.components, components: options?.components,
@ -158,7 +159,7 @@ export class Webhook implements Model {
: WEBHOOK_MESSAGE_ORIGINAL(this.id, this.token), : WEBHOOK_MESSAGE_ORIGINAL(this.id, this.token),
{ {
content: options?.content, content: options?.content,
embeds: options?.embeds, embeds: options?.embeds?.map(NewEmbed),
file: options?.files, file: options?.files,
components: options?.components, components: options?.components,
allowed_mentions: options?.allowedMentions && { allowed_mentions: options?.allowedMentions && {