mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-03 05:26:07 +00:00
refactor: interaction options
This commit is contained in:
parent
4d779e6bb2
commit
750be16ee9
@ -11,7 +11,7 @@ export * from './structures/invite';
|
||||
export * from './structures/members';
|
||||
export * from './structures/message';
|
||||
export * from './structures/message-reaction';
|
||||
export * from './structures/special/command-interaction-option-resolver';
|
||||
export * from './structures/special/interaction-options';
|
||||
export * from './structures/special/permissions';
|
||||
export * from './structures/presence';
|
||||
export * from './structures/role';
|
||||
|
@ -24,7 +24,7 @@ import { Member } from './members';
|
||||
import { Message } from './message';
|
||||
import { Permissions } from './special/permissions';
|
||||
import { Webhook } from './webhook';
|
||||
import { CommandInteractionOptionResolver } from './special/command-interaction-option-resolver';
|
||||
import { InteractionOptions } from './special/interaction-options';
|
||||
import {
|
||||
INTERACTION_ID_TOKEN,
|
||||
WEBHOOK_MESSAGE,
|
||||
@ -329,7 +329,7 @@ export class AutoCompleteInteraction extends BaseInteraction implements Model {
|
||||
this.commandType = data.data!.type;
|
||||
this.commandGuildId = data.data!.guild_id;
|
||||
this.locale = super.locale!;
|
||||
this.options = new CommandInteractionOptionResolver(
|
||||
this.options = new InteractionOptions(
|
||||
data.data!.options ?? []
|
||||
);
|
||||
}
|
||||
@ -340,7 +340,7 @@ export class AutoCompleteInteraction extends BaseInteraction implements Model {
|
||||
commandType: ApplicationCommandTypes;
|
||||
commandGuildId?: Snowflake;
|
||||
override locale: string;
|
||||
options: CommandInteractionOptionResolver;
|
||||
options: InteractionOptions;
|
||||
|
||||
async respondWithChoices(
|
||||
choices: ApplicationCommandOptionChoice[]
|
||||
@ -371,7 +371,7 @@ export class CommandInteraction extends BaseInteraction implements Model {
|
||||
this.commandName = data.data!.name;
|
||||
this.commandType = data.data!.type;
|
||||
this.commandGuildId = data.data!.guild_id;
|
||||
this.options = new CommandInteractionOptionResolver(
|
||||
this.options = new InteractionOptions(
|
||||
data.data!.options ?? []
|
||||
);
|
||||
|
||||
@ -436,7 +436,7 @@ export class CommandInteraction extends BaseInteraction implements Model {
|
||||
commandType: ApplicationCommandTypes;
|
||||
commandGuildId?: Snowflake;
|
||||
resolved: CommandInteractionDataResolved;
|
||||
options: CommandInteractionOptionResolver;
|
||||
options: InteractionOptions;
|
||||
override locale: string;
|
||||
}
|
||||
|
||||
|
@ -7,12 +7,11 @@ import { ApplicationCommandOptionTypes } from '@biscuitland/api-types';
|
||||
|
||||
/**
|
||||
* Utility class to get the resolved options for a command
|
||||
* It is really typesafe
|
||||
* @example const option = ctx.options.getStringOption("name");
|
||||
*/
|
||||
export class CommandInteractionOptionResolver {
|
||||
#subcommand?: string;
|
||||
#group?: string;
|
||||
export class InteractionOptions {
|
||||
private _subcommand?: string;
|
||||
private _group?: string;
|
||||
|
||||
hoistedOptions: DiscordInteractionDataOption[];
|
||||
resolved?: DiscordInteractionDataResolved;
|
||||
@ -29,7 +28,7 @@ export class CommandInteractionOptionResolver {
|
||||
this.hoistedOptions[0]?.type ===
|
||||
ApplicationCommandOptionTypes.SubCommandGroup
|
||||
) {
|
||||
this.#group = this.hoistedOptions[0].name;
|
||||
this._group = this.hoistedOptions[0].name;
|
||||
this.hoistedOptions = this.hoistedOptions[0].options ?? [];
|
||||
}
|
||||
|
||||
@ -37,7 +36,7 @@ export class CommandInteractionOptionResolver {
|
||||
this.hoistedOptions[0]?.type ===
|
||||
ApplicationCommandOptionTypes.SubCommand
|
||||
) {
|
||||
this.#subcommand = this.hoistedOptions[0].name;
|
||||
this._subcommand = this.hoistedOptions[0].name;
|
||||
this.hoistedOptions = this.hoistedOptions[0].options ?? [];
|
||||
}
|
||||
|
||||
@ -249,20 +248,20 @@ export class CommandInteractionOptionResolver {
|
||||
getSubCommand(
|
||||
required = true
|
||||
): [string | undefined, DiscordInteractionDataOption[]] {
|
||||
if (required && !this.#subcommand) {
|
||||
if (required && !this._subcommand) {
|
||||
throw new TypeError('Option marked as required was undefined');
|
||||
}
|
||||
|
||||
return [this.#subcommand, this.hoistedOptions];
|
||||
return [this._subcommand, this.hoistedOptions];
|
||||
}
|
||||
|
||||
getSubCommandGroup(
|
||||
required = false
|
||||
): [string | undefined, DiscordInteractionDataOption[]] {
|
||||
if (required && !this.#group) {
|
||||
if (required && !this._group) {
|
||||
throw new TypeError('Option marked as required was undefined');
|
||||
}
|
||||
|
||||
return [this.#group, this.hoistedOptions];
|
||||
return [this._group, this.hoistedOptions];
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user