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/members';
|
||||||
export * from './structures/message';
|
export * from './structures/message';
|
||||||
export * from './structures/message-reaction';
|
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/special/permissions';
|
||||||
export * from './structures/presence';
|
export * from './structures/presence';
|
||||||
export * from './structures/role';
|
export * from './structures/role';
|
||||||
|
@ -24,7 +24,7 @@ import { Member } from './members';
|
|||||||
import { Message } from './message';
|
import { Message } from './message';
|
||||||
import { Permissions } from './special/permissions';
|
import { Permissions } from './special/permissions';
|
||||||
import { Webhook } from './webhook';
|
import { Webhook } from './webhook';
|
||||||
import { CommandInteractionOptionResolver } from './special/command-interaction-option-resolver';
|
import { InteractionOptions } from './special/interaction-options';
|
||||||
import {
|
import {
|
||||||
INTERACTION_ID_TOKEN,
|
INTERACTION_ID_TOKEN,
|
||||||
WEBHOOK_MESSAGE,
|
WEBHOOK_MESSAGE,
|
||||||
@ -329,7 +329,7 @@ export class AutoCompleteInteraction extends BaseInteraction implements Model {
|
|||||||
this.commandType = data.data!.type;
|
this.commandType = data.data!.type;
|
||||||
this.commandGuildId = data.data!.guild_id;
|
this.commandGuildId = data.data!.guild_id;
|
||||||
this.locale = super.locale!;
|
this.locale = super.locale!;
|
||||||
this.options = new CommandInteractionOptionResolver(
|
this.options = new InteractionOptions(
|
||||||
data.data!.options ?? []
|
data.data!.options ?? []
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -340,7 +340,7 @@ export class AutoCompleteInteraction extends BaseInteraction implements Model {
|
|||||||
commandType: ApplicationCommandTypes;
|
commandType: ApplicationCommandTypes;
|
||||||
commandGuildId?: Snowflake;
|
commandGuildId?: Snowflake;
|
||||||
override locale: string;
|
override locale: string;
|
||||||
options: CommandInteractionOptionResolver;
|
options: InteractionOptions;
|
||||||
|
|
||||||
async respondWithChoices(
|
async respondWithChoices(
|
||||||
choices: ApplicationCommandOptionChoice[]
|
choices: ApplicationCommandOptionChoice[]
|
||||||
@ -371,7 +371,7 @@ export class CommandInteraction extends BaseInteraction implements Model {
|
|||||||
this.commandName = data.data!.name;
|
this.commandName = data.data!.name;
|
||||||
this.commandType = data.data!.type;
|
this.commandType = data.data!.type;
|
||||||
this.commandGuildId = data.data!.guild_id;
|
this.commandGuildId = data.data!.guild_id;
|
||||||
this.options = new CommandInteractionOptionResolver(
|
this.options = new InteractionOptions(
|
||||||
data.data!.options ?? []
|
data.data!.options ?? []
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -436,7 +436,7 @@ export class CommandInteraction extends BaseInteraction implements Model {
|
|||||||
commandType: ApplicationCommandTypes;
|
commandType: ApplicationCommandTypes;
|
||||||
commandGuildId?: Snowflake;
|
commandGuildId?: Snowflake;
|
||||||
resolved: CommandInteractionDataResolved;
|
resolved: CommandInteractionDataResolved;
|
||||||
options: CommandInteractionOptionResolver;
|
options: InteractionOptions;
|
||||||
override locale: string;
|
override locale: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,12 +7,11 @@ import { ApplicationCommandOptionTypes } from '@biscuitland/api-types';
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class to get the resolved options for a command
|
* Utility class to get the resolved options for a command
|
||||||
* It is really typesafe
|
|
||||||
* @example const option = ctx.options.getStringOption("name");
|
* @example const option = ctx.options.getStringOption("name");
|
||||||
*/
|
*/
|
||||||
export class CommandInteractionOptionResolver {
|
export class InteractionOptions {
|
||||||
#subcommand?: string;
|
private _subcommand?: string;
|
||||||
#group?: string;
|
private _group?: string;
|
||||||
|
|
||||||
hoistedOptions: DiscordInteractionDataOption[];
|
hoistedOptions: DiscordInteractionDataOption[];
|
||||||
resolved?: DiscordInteractionDataResolved;
|
resolved?: DiscordInteractionDataResolved;
|
||||||
@ -29,7 +28,7 @@ export class CommandInteractionOptionResolver {
|
|||||||
this.hoistedOptions[0]?.type ===
|
this.hoistedOptions[0]?.type ===
|
||||||
ApplicationCommandOptionTypes.SubCommandGroup
|
ApplicationCommandOptionTypes.SubCommandGroup
|
||||||
) {
|
) {
|
||||||
this.#group = this.hoistedOptions[0].name;
|
this._group = this.hoistedOptions[0].name;
|
||||||
this.hoistedOptions = this.hoistedOptions[0].options ?? [];
|
this.hoistedOptions = this.hoistedOptions[0].options ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +36,7 @@ export class CommandInteractionOptionResolver {
|
|||||||
this.hoistedOptions[0]?.type ===
|
this.hoistedOptions[0]?.type ===
|
||||||
ApplicationCommandOptionTypes.SubCommand
|
ApplicationCommandOptionTypes.SubCommand
|
||||||
) {
|
) {
|
||||||
this.#subcommand = this.hoistedOptions[0].name;
|
this._subcommand = this.hoistedOptions[0].name;
|
||||||
this.hoistedOptions = this.hoistedOptions[0].options ?? [];
|
this.hoistedOptions = this.hoistedOptions[0].options ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,20 +248,20 @@ export class CommandInteractionOptionResolver {
|
|||||||
getSubCommand(
|
getSubCommand(
|
||||||
required = true
|
required = true
|
||||||
): [string | undefined, DiscordInteractionDataOption[]] {
|
): [string | undefined, DiscordInteractionDataOption[]] {
|
||||||
if (required && !this.#subcommand) {
|
if (required && !this._subcommand) {
|
||||||
throw new TypeError('Option marked as required was undefined');
|
throw new TypeError('Option marked as required was undefined');
|
||||||
}
|
}
|
||||||
|
|
||||||
return [this.#subcommand, this.hoistedOptions];
|
return [this._subcommand, this.hoistedOptions];
|
||||||
}
|
}
|
||||||
|
|
||||||
getSubCommandGroup(
|
getSubCommandGroup(
|
||||||
required = false
|
required = false
|
||||||
): [string | undefined, DiscordInteractionDataOption[]] {
|
): [string | undefined, DiscordInteractionDataOption[]] {
|
||||||
if (required && !this.#group) {
|
if (required && !this._group) {
|
||||||
throw new TypeError('Option marked as required was undefined');
|
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