diff --git a/index.ts b/index.ts index e27607e..a637b3b 100644 --- a/index.ts +++ b/index.ts @@ -1,9 +1,9 @@ import { Bot } from "./src/structures/Bot.js"; -import { TextCommand } from "./src/structures/TextCommand.js"; +import { ChatCommand } from "./src/structures/ChatCommand.js"; import { MessageCommand } from "./src/structures/MessageCommand.js"; import { UserCommand } from "./src/structures/UserCommand.js"; import { InitOptions } from "./src/types/Bot.js"; -import { TextCommandInit, CommandMessageStructure } from "./src/types/TextCommand.js"; +import { ChatCommandInit, CommandMessageStructure } from "./src/types/ChatCommand.js"; import { HelpMessageParams } from "./src/types/HelpMessage.js"; import { ParameterResolvable, ParameterType, ParameterSchema } from "./src/types/Parameter.js"; import { SystemMessageAppearance, SystemMessageData } from "./src/types/SystemMessage.js"; @@ -13,11 +13,11 @@ import { PermissionsError, ParameterTypeError, MissingParameterError, OperationS export default Bot; export { Bot, - TextCommand, + ChatCommand, MessageCommand, UserCommand, InitOptions, - TextCommandInit, + ChatCommandInit, CommandMessageStructure, HelpMessageParams, ParameterResolvable, diff --git a/src/managers/CommandManager.old.ts b/src/managers/CommandManager.old.ts index fbe2b76..c5cffba 100644 --- a/src/managers/CommandManager.old.ts +++ b/src/managers/CommandManager.old.ts @@ -3,8 +3,8 @@ import { CommandInteraction, Message } from "discord.js"; import { BaseCommand } from "../structures/BaseCommand.js"; import { MissingParameterError } from "../errors.js"; import { BooleanParameter, InputParameter, NumberParameter, ObjectParameter, StringParameter } from "../structures/Parameter.js"; -import { TextCommand } from "../structures/TextCommand.js"; -import { CommandMessageStructure } from "../types/TextCommand.js"; +import { ChatCommand } from "../structures/ChatCommand.js"; +import { CommandMessageStructure } from "../types/ChatCommand.js"; import { applicationState } from "../state.js"; import { MessageCommand } from "../structures/MessageCommand.js"; import { CommandType, PhraseOccurrenceData } from "../types/BaseCommand.js"; @@ -15,7 +15,7 @@ import { CommandResolvable, CommandStructure } from "../types/commands.js"; * @class Command manager */ export class CommandManager { - private readonly _chatCommandsList: TextCommand[] = []; + private readonly _chatCommandsList: ChatCommand[] = []; private readonly _messagesCommandsList: MessageCommand[] = []; private readonly _userCommandsList: UserCommand[] = []; @@ -44,7 +44,7 @@ export class CommandManager { /** * Retrieves the command by name, alias or keyword * @param {string} phrase - command name, alias or keyword - * @returns {TextCommand | MessageCommand | UserCommand | null} Retrieved extension of {@link BaseCommand} object from the manager or *null* + * @returns {ChatCommand | MessageCommand | UserCommand | null} Retrieved extension of {@link BaseCommand} object from the manager or *null* */ public get(phrase: string, type: T): CommandStructure | null { let command: CommandStructure | null = null; @@ -103,7 +103,7 @@ export class CommandManager { if (applicationState.running) { throw new Error("Cannot add a command while the application is running"); } - if (command instanceof TextCommand) { + if (command instanceof ChatCommand) { const nameOccurrence: PhraseOccurrenceData | null = this.findPhraseOccurrence(command.type, command.name); if (nameOccurrence) { throw new Error(`The name "${command.name}" has already been registered as ${nameOccurrence.type} in the "${nameOccurrence.command.name}" command.`); @@ -175,7 +175,7 @@ export class CommandManager { paramsList.splice(0, 1); } const parameters: InputParameter[] = []; - command instanceof TextCommand && + command instanceof ChatCommand && command.parameters.map((p, i) => { if (!p.optional && !paramsList[i]) { throw new MissingParameterError(p); @@ -224,7 +224,7 @@ export class CommandManager { if (i.options?.data) { const paramsList = i.options.data; const parameters: InputParameter[] = []; - cmd instanceof TextCommand && + cmd instanceof ChatCommand && cmd.parameters.map((p) => { const inputParam = paramsList.find((d) => d.name == p.name); if (!p.optional && !inputParam) { diff --git a/src/structures/Bot.ts b/src/structures/Bot.ts index 273eb8e..34ac907 100644 --- a/src/structures/Bot.ts +++ b/src/structures/Bot.ts @@ -1,12 +1,12 @@ import { Client, CommandInteraction, GuildMember, Intents, Message } from "discord.js"; import { EventEmitter } from "events"; import * as http from "http"; -import { TextCommand } from "./TextCommand.js"; +import { ChatCommand } from "./ChatCommand.js"; import { CommandManager } from "../managers/CommandManager.old.js"; import { OperationSuccess, PermissionsError } from "../errors.js"; import { HelpMessage } from "./Help.js"; import { SystemMessageManager } from "../managers/SystemMessage.js"; -import { CommandMessageStructure } from "../types/TextCommand.js"; +import { CommandMessageStructure } from "../types/ChatCommand.js"; import { InitOptions } from "../types/Bot.js"; import { HelpMessageParams } from "../types/HelpMessage.js"; import { applicationState } from "../state.js"; @@ -138,7 +138,7 @@ export class Bot extends EventEmitter { console.log("✔"); } if (this.messages.help.enabled === true) { - const helpMsg: TextCommand = new HelpMessage(this.commands, this.messages.help, this.name); + const helpMsg: ChatCommand = new HelpMessage(this.commands, this.messages.help, this.name); this.commands.add(helpMsg); } applicationState.running = true; diff --git a/src/structures/TextCommand.ts b/src/structures/ChatCommand.ts similarity index 91% rename from src/structures/TextCommand.ts rename to src/structures/ChatCommand.ts index 431c1f9..92673db 100644 --- a/src/structures/TextCommand.ts +++ b/src/structures/ChatCommand.ts @@ -1,13 +1,13 @@ import { Message, CommandInteraction } from "discord.js"; import { BaseCommand } from "./BaseCommand.js"; -import { TextCommandInit } from "../types/TextCommand.js"; +import { ChatCommandInit } from "../types/ChatCommand.js"; import { DefaultParameter, InputParameter, Parameter } from "./Parameter.js"; import { TextCommandObject, TextCommandOptionChoiceObject, TextCommandOptionObject } from "../types/api.js"; /** * @class Class that represents a command instance */ -export class TextCommand extends BaseCommand { +export class ChatCommand extends BaseCommand { /** * List of parameters that can passed to this command * @type {Array} {@link Parameter} @@ -49,13 +49,13 @@ export class TextCommand extends BaseCommand { /** * Command constructor * @constructor - * @param {TextCommandInit} o - {@link CommandBuilder} + * @param {ChatCommandInit} o - {@link CommandBuilder} */ - constructor(o: TextCommandInit) { - if (!TextCommand.nameRegExp.test(o.name)) { + constructor(o: ChatCommandInit) { + if (!ChatCommand.nameRegExp.test(o.name)) { throw new Error("Incorrect command name. Text and slash commands must match this regular expression: ^[w-]{1,32}$"); } - if (o.description && !TextCommand.descriptionRegExp.test(o.description)) { + if (o.description && !ChatCommand.descriptionRegExp.test(o.description)) { throw new Error("Command descriptions must be 1-100 characters long"); } super("CHAT", { @@ -73,7 +73,7 @@ export class TextCommand extends BaseCommand { } else { this.parameters = o.parameters.map((ps) => new Parameter(ps)); } - this.aliases = TextCommand.processPhrase(o.aliases); + this.aliases = ChatCommand.processPhrase(o.aliases); this.description = o.description || "No description"; this.usage = o.usage || this.generateUsageFromArguments(); this.visible = o.visible !== undefined ? o.visible : true; @@ -94,7 +94,7 @@ export class TextCommand extends BaseCommand { } /** - * Converts {@link TextCommand} instance to object that is recognized by the Discord API + * Converts {@link ChatCommand} instance to object that is recognized by the Discord API * @returns {Object} object */ public toObject(): TextCommandObject { @@ -189,17 +189,17 @@ export class TextCommand extends BaseCommand { return usageTemplate; } - public static isCommand(o: any): o is TextCommand { + public static isCommand(o: any): o is ChatCommand { return ( "description" in o && typeof o.description === "string" && - TextCommand.descriptionRegExp.test(o.description) && + ChatCommand.descriptionRegExp.test(o.description) && "parameters" in o && Array.isArray(o.parameters) && "visible" in o && typeof o.visible === "boolean" && BaseCommand.isCommand(o) && - TextCommand.nameRegExp.test(o.name) + ChatCommand.nameRegExp.test(o.name) ); } } diff --git a/src/structures/Help.ts b/src/structures/Help.ts index 83f7b93..2a08e7e 100644 --- a/src/structures/Help.ts +++ b/src/structures/Help.ts @@ -1,9 +1,9 @@ import { MessageEmbed } from "discord.js"; -import { TextCommand } from "./TextCommand.js"; +import { ChatCommand } from "./ChatCommand.js"; import { CommandManager } from "../managers/CommandManager.old.js"; import { HelpMessageParams } from "../types/HelpMessage.js"; -export class HelpMessage extends TextCommand { +export class HelpMessage extends ChatCommand { constructor(cmdManager: CommandManager, params: HelpMessageParams, botName?: string) { super({ name: "help", @@ -29,7 +29,7 @@ export class HelpMessage extends TextCommand { helpMsg.setFooter(botName || ""); if (helpMsg != null) { if (p("command_name")) { - const cmd: TextCommand | null = cmdManager.get(p("command_name")?.toString() || "", "CHAT"); + const cmd: ChatCommand | null = cmdManager.get(p("command_name")?.toString() || "", "CHAT"); if (cmd) { if (Array.isArray(cmd.guilds) && cmd.guilds.length > 0 && !cmd.guilds.find((g) => i?.guild?.id === g)) { throw new ReferenceError(`Command "${cmd.name}" is not available`); @@ -66,7 +66,7 @@ export class HelpMessage extends TextCommand { cmdManager.getList("CHAT").map((c) => { if ( - c instanceof TextCommand && + c instanceof ChatCommand && c.visible && ((Array.isArray(c.guilds) && c.guilds.length > 0 && c.guilds.find((g) => i?.guild?.id === g)) || !Array.isArray(c.guilds) || c.guilds.length === 0) ) { diff --git a/src/types/TextCommand.ts b/src/types/ChatCommand.ts similarity index 98% rename from src/types/TextCommand.ts rename to src/types/ChatCommand.ts index 46dbd57..4852a0e 100644 --- a/src/types/TextCommand.ts +++ b/src/types/ChatCommand.ts @@ -9,7 +9,7 @@ import { BaseCommand } from "../structures/BaseCommand.js"; * @interface * Options for building a {@link Command} object */ -export interface TextCommandInit { +export interface ChatCommandInit { /** * Command name * @type {string} diff --git a/src/types/commands.ts b/src/types/commands.ts index 2040b2c..60663a1 100644 --- a/src/types/commands.ts +++ b/src/types/commands.ts @@ -1,8 +1,8 @@ import { BaseCommand } from "../structures/BaseCommand.js"; -import { TextCommand } from "../structures/TextCommand.js"; +import { ChatCommand } from "../structures/ChatCommand.js"; import { MessageCommand } from "../structures/MessageCommand.js"; import { UserCommand } from "../structures/UserCommand.js"; -export type CommandStructure = T extends "MESSAGE" ? MessageCommand : T extends "USER" ? UserCommand : T extends "CHAT" ? TextCommand : BaseCommand; +export type CommandStructure = T extends "MESSAGE" ? MessageCommand : T extends "USER" ? UserCommand : T extends "CHAT" ? ChatCommand : BaseCommand; -export type CommandResolvable = BaseCommand | TextCommand | MessageCommand | UserCommand; +export type CommandResolvable = BaseCommand | ChatCommand | MessageCommand | UserCommand;