From a637f1df22ea44bbbdabe0187dc54d824595429d Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Tue, 5 Dec 2023 22:49:44 +0200 Subject: [PATCH] My brain is so massive --- @types/Client.ts | 31 ++++++++++++++++++++++++++ src/client/interfaces/CommandOption.ts | 21 +++++++++-------- 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/@types/Client.ts b/@types/Client.ts index 5eed04b..63ce908 100644 --- a/@types/Client.ts +++ b/@types/Client.ts @@ -132,6 +132,37 @@ export type InfractionType = | 'DELETE'; export enum CommandOptionType { + SUB_COMMAND = 'SUB_COMMAND', + SUB_COMMAND_GROUP = 'SUB_COMMAND_GROUP', + ROLES = 'ROLES', // Note plurality, strings can parse users, roles, and channels. + MEMBERS = 'MEMBERS', + USERS = 'USERS', + CHANNELS = 'CHANNELS', + TEXT_CHANNELS = 'TEXT_CHANNELS', + VOICE_CHANNELS = 'VOICE_CHANNELS', + TIME = 'TIME', // timestring + DATE = 'DATE', + COMPONENT = 'COMPONENT', + COMPONENTS = 'COMPONENTS', + COMMAND = 'COMMAND', + COMMANDS = 'COMMANDS', + MODULE = 'MODULE', + STRING = 'STRING', + INTEGER = 'INTEGER', + BOOLEAN = 'BOOLEAN', + MEMBER = 'MEMBER', + USER = 'USER', + TEXT_CHANNEL = 'TEXT_CHANNEL', + VOICE_CHANNEL = 'VOICE_CHANNEL', + CHANNEL = 'CHANNEL', + ROLE = 'ROLE', + MENTIONABLE = 'MENTIONABLE', + NUMBER = 'NUMBER', + FLOAT = 'FLOAT', + POINTS = 'POINTS' +} + +export enum DiscordCommandOptionType { SUB_COMMAND = 1, SUB_COMMAND_GROUP = 2, ROLES = 3, // Note plurality, strings can parse users, roles, and channels. diff --git a/src/client/interfaces/CommandOption.ts b/src/client/interfaces/CommandOption.ts index 80f0c76..5aa7abd 100644 --- a/src/client/interfaces/CommandOption.ts +++ b/src/client/interfaces/CommandOption.ts @@ -1,11 +1,7 @@ /* eslint-disable camelcase */ - -// const { ChannelType } = require("discord.js"); -// const { Util } = require("../../utilities"); - import { Util } from '../../utilities/index.js'; import DiscordClient from '../DiscordClient.js'; -import { CommandOptionChoices, CommandOptionParams, CommandOptionShape, CommandOptionType, DependsOnMode, FormatOpts, FormatParams, RawCommandOption } from '../../../@types/Client.js'; +import { CommandOptionChoices, CommandOptionParams, CommandOptionShape, CommandOptionType, DependsOnMode, DiscordCommandOptionType, FormatOpts, FormatParams, RawCommandOption } from '../../../@types/Client.js'; import { GuildWrapper } from '../components/wrappers/index.js'; import Component from './Component.js'; import Command from './commands/Command.js'; @@ -246,11 +242,11 @@ class CommandOption // console.log('-------PARSE BEGIN---------'); // console.log('1', this.name, this.#rawValue, this.valueOptional); const { removed, value, error, index, params } = await this.types[this.type](); - if (this.valueOptional && error) + if (this.valueOptional && error) { this.#value = this.defaultValue; } - else + else { if (error) return { error, index, params }; @@ -278,13 +274,13 @@ class CommandOption get types () { return { - POINTS: async () => + POINTS: async () => { if (this.slashOption) return { value: this.#rawValue }; let value = null, removed = null; - if (!this.#rawValue) + if (!this.#rawValue) throw new Error('No rawValue supplied'); if (!(this.#rawValue instanceof Array)) throw new Error('Invalid rawValue'); @@ -967,13 +963,16 @@ class CommandOption this.#aliased = val; } - get shape (): CommandOptionShape + get shape (): CommandOptionShape { const cmdType = CommandOptionType[this.#type]; + const type = DiscordCommandOptionType[this.#type]; + if (!type) + throw new Error('Invalid command type: ' + type); return { name: this.#name, description: this.#description, - type: this.#type, + type, required: this.#required, choices: this.#choices, options: this.#options.map((o) => o.shape as CommandOptionShape),