From 108bfb38d31ab769cdfc52517b21e49932d593a2 Mon Sep 17 00:00:00 2001 From: GRZ4NA Date: Sat, 4 Sep 2021 18:36:57 +0200 Subject: [PATCH] Command -> TextCommand --- index.ts | 8 ++++---- src/errors.ts | 10 +++++----- src/managers/CommandManager.ts | 18 +++++++++--------- src/structures/Bot.ts | 6 +++--- src/structures/Help.ts | 6 +++--- src/structures/{Command.ts => TextCommand.ts} | 12 ++++++------ src/types/SystemMessage.ts | 6 +++--- src/types/{Command.ts => TextCommand.ts} | 8 ++++---- 8 files changed, 37 insertions(+), 37 deletions(-) rename src/structures/{Command.ts => TextCommand.ts} (96%) rename src/types/{Command.ts => TextCommand.ts} (95%) diff --git a/index.ts b/index.ts index 7e3fdcb..28cfa3a 100644 --- a/index.ts +++ b/index.ts @@ -1,8 +1,8 @@ import { MessageEmbed } from "discord.js"; import { Bot } from "./src/structures/Bot.js"; -import { Command } from "./src/structures/Command.js"; +import { TextCommand } from "./src/structures/TextCommand.js"; import { InitOptions } from "./src/types/Bot.js"; -import { CommandBuilder, CommandMessageStructure } from "./src/types/Command.js"; +import { TextCommandInit, CommandMessageStructure } from "./src/types/TextCommand.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"; @@ -12,10 +12,10 @@ import { PermissionsError, ParameterTypeError, MissingParameterError, OperationS export default Bot; export { Bot, - Command, + TextCommand, MessageEmbed, InitOptions, - CommandBuilder, + TextCommandInit, CommandMessageStructure, HelpMessageParams, ParameterResolvable, diff --git a/src/errors.ts b/src/errors.ts index d92c11b..a7b0575 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -1,4 +1,4 @@ -import { Command } from "./structures/Command.js"; +import { TextCommand } from "./structures/TextCommand.js"; import { GuildMember } from "discord.js"; import { Parameter } from "./structures/Parameter.js"; import { ParameterType } from "./types/Parameter.js"; @@ -9,9 +9,9 @@ import { ParameterType } from "./types/Parameter.js"; * @exports */ export class PermissionsError extends Error { - private readonly command: Command; + private readonly command: TextCommand; private readonly user: GuildMember | null; - constructor(command: Command, user?: GuildMember | null) { + constructor(command: TextCommand, user?: GuildMember | null) { super(); this.command = command; this.user = user || null; @@ -60,8 +60,8 @@ export class MissingParameterError extends ReferenceError { * @exports */ export class OperationSuccess { - public readonly command: Command; - constructor(c: Command) { + public readonly command: TextCommand; + constructor(c: TextCommand) { this.command = c; } } diff --git a/src/managers/CommandManager.ts b/src/managers/CommandManager.ts index 56ff78f..99c3cf1 100644 --- a/src/managers/CommandManager.ts +++ b/src/managers/CommandManager.ts @@ -1,15 +1,15 @@ import { CommandInteraction, Message } from "discord.js"; import { MissingParameterError } from "../errors.js"; import { BooleanParameter, InputParameter, NumberParameter, ObjectParameter, StringParameter } from "../structures/Parameter.js"; -import { Command } from "../structures/Command.js"; -import { CommandMessageStructure, PhraseOccurrenceData } from "../types/Command.js"; +import { TextCommand } from "../structures/TextCommand.js"; +import { CommandMessageStructure, PhraseOccurrenceData } from "../types/TextCommand.js"; import { applicationState } from "../state.js"; /** * @class Command manager */ export class CommandManager { - private readonly _list: Command[] = []; + private readonly _list: TextCommand[] = []; /** * Prefix used as a way to trigger the bot using messages * @type {string} @@ -34,10 +34,10 @@ export class CommandManager { /** * Retrieves the command by name, alias or keyword * @param {string} phrase - command name, alias or keyword - * @returns {Command | null} Retrieved {@link Command} object from the manager or *null* + * @returns {TextCommand | null} Retrieved {@link Command} object from the manager or *null* */ - public get(phrase: string): Command | null { - let command: Command | null = null; + public get(phrase: string): TextCommand | null { + let command: TextCommand | null = null; this._list.map((c) => { if (c.name == phrase) { command = c; @@ -62,15 +62,15 @@ export class CommandManager { /** * Adds the given {@link Command} to the instance manager with initial processing - * @param {Command} command - {@link Command} instance object + * @param {TextCommand} command - {@link Command} instance object * @returns {boolean} Whether this command has been added successfully */ - public add(command: Command): boolean { + public add(command: TextCommand): boolean { try { if (applicationState.running) { throw new Error("Cannot add command while the application is running"); } - if (!(command instanceof Command)) { + if (!(command instanceof TextCommand)) { throw new TypeError("Inavlid argument type"); } const nameOccurrence: PhraseOccurrenceData | null = this.findPhraseOccurrence(command.name); diff --git a/src/structures/Bot.ts b/src/structures/Bot.ts index ee821e8..dfa914b 100644 --- a/src/structures/Bot.ts +++ b/src/structures/Bot.ts @@ -2,12 +2,12 @@ import axios from "axios"; import { Client, CommandInteraction, GuildMember, Intents, Message } from "discord.js"; import { EventEmitter } from "events"; import * as http from "http"; -import { Command } from "./Command.js"; +import { TextCommand } from "./TextCommand.js"; import { CommandManager } from "../managers/CommandManager.js"; import { OperationSuccess, PermissionsError } from "../errors.js"; import { HelpMessage } from "./Help.js"; import { SystemMessageManager } from "../managers/SystemMessage.js"; -import { CommandMessageStructure } from "../types/Command.js"; +import { CommandMessageStructure } from "../types/TextCommand.js"; import { InitOptions } from "../types/Bot.js"; import { HelpMessageParams } from "../types/HelpMessage.js"; import { applicationState } from "../state.js"; @@ -132,7 +132,7 @@ export class Bot extends EventEmitter { console.log("✔"); } if (this.messages.help.enabled === true) { - const helpMsg: Command = new HelpMessage(this.commands, this.messages.help, this.name); + const helpMsg: TextCommand = new HelpMessage(this.commands, this.messages.help, this.name); this.commands.add(helpMsg); } applicationState.running = true; diff --git a/src/structures/Help.ts b/src/structures/Help.ts index 8eafe36..706ae24 100644 --- a/src/structures/Help.ts +++ b/src/structures/Help.ts @@ -1,9 +1,9 @@ import { MessageEmbed } from "discord.js"; -import { Command } from "./Command.js"; +import { TextCommand } from "./TextCommand.js"; import { CommandManager } from "../managers/CommandManager.js"; import { HelpMessageParams } from "../types/HelpMessage.js"; -export class HelpMessage extends Command { +export class HelpMessage extends TextCommand { constructor(cmdManager: CommandManager, params: HelpMessageParams, botName?: string) { super({ name: "help", @@ -26,7 +26,7 @@ export class HelpMessage extends Command { helpMsg.setFooter(botName || ""); if (helpMsg != null) { if (p("command_name")) { - const cmd: Command | null = cmdManager.get(p("command_name")?.toString() || ""); + const cmd: TextCommand | null = cmdManager.get(p("command_name")?.toString() || ""); 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`); diff --git a/src/structures/Command.ts b/src/structures/TextCommand.ts similarity index 96% rename from src/structures/Command.ts rename to src/structures/TextCommand.ts index 64d2ee8..835bde1 100644 --- a/src/structures/Command.ts +++ b/src/structures/TextCommand.ts @@ -1,5 +1,5 @@ import { Permissions, Message, MessageEmbed, CommandInteraction, GuildMember, ReplyMessageOptions, PermissionResolvable } from "discord.js"; -import { CommandBuilder } from "../types/Command.js"; +import { TextCommandInit } from "../types/TextCommand.js"; import { ParameterResolvable } from "../types/Parameter.js"; import { PermissionCheckTypes } from "../types/permissions.js"; import { OperationSuccess, PermissionsError } from "../errors.js"; @@ -9,7 +9,7 @@ import { DefaultParameter, InputParameter, Parameter } from "./Parameter.js"; * @class Class that represents a command instance * @exports */ -export class Command { +export class TextCommand { /** * Command name * @type {string} @@ -81,9 +81,9 @@ export class Command { /** * Command constructor * @constructor - * @param {CommandBuilder} options - {@link CommandBuilder} + * @param {TextCommandInit} options - {@link CommandBuilder} */ - constructor(options: CommandBuilder) { + constructor(options: TextCommandInit) { this.name = options.name.split(" ").join("_"); if (options.parameters == "no_input" || !options.parameters) { this.parameters = []; @@ -92,7 +92,7 @@ export class Command { } else { this.parameters = options.parameters.map((ps) => new Parameter(ps)); } - this.aliases = Command.processPhrase(options.aliases); + this.aliases = TextCommand.processPhrase(options.aliases); this.description = options.description || "No description"; this.usage = options.usage || this.generateUsageFromArguments(); this.permissionCheck = options.permissionCheck == "ALL" || options.permissionCheck == "ANY" ? options.permissionCheck : "ANY"; @@ -170,7 +170,7 @@ export class Command { } /** - * Converts {@link Command} instance to object that is recognized by the Discord API + * Converts {@link TextCommand} instance to object that is recognized by the Discord API * @returns {Object} object */ public toObject() { diff --git a/src/types/SystemMessage.ts b/src/types/SystemMessage.ts index f6cc5cf..3ec86a7 100644 --- a/src/types/SystemMessage.ts +++ b/src/types/SystemMessage.ts @@ -1,5 +1,5 @@ import { ColorResolvable, GuildMember, User } from "discord.js"; -import { Command } from "../structures/Command.js"; +import { TextCommand } from "../structures/TextCommand.js"; import { PermissionsError } from "../errors.js"; /** @@ -61,9 +61,9 @@ export interface SystemMessageAppearance { export interface SystemMessageData { /** * A {@link Command} instance - * @type {Command} + * @type {TextCommand} */ - command?: Command; + command?: TextCommand; /** * Phrase received from a Discord channel * @type {string} diff --git a/src/types/Command.ts b/src/types/TextCommand.ts similarity index 95% rename from src/types/Command.ts rename to src/types/TextCommand.ts index 990fcf8..602e7fa 100644 --- a/src/types/Command.ts +++ b/src/types/TextCommand.ts @@ -1,14 +1,14 @@ import { CommandInteraction, ReplyMessageOptions, PermissionResolvable, Message, MessageEmbed } from "discord.js"; import { ParameterSchema, ParameterResolvable } from "./Parameter.js"; import { InputParameter } from "../structures/Parameter.js"; -import { Command } from "../structures/Command.js"; +import { TextCommand } from "../structures/TextCommand.js"; import { PermissionCheckTypes } from "./permissions.js"; /** * @interface * Options for building a {@link Command} object */ -export interface CommandBuilder { +export interface TextCommandInit { /** * Command name * @type {string} @@ -78,13 +78,13 @@ export interface CommandBuilder { } export interface CommandMessageStructure { - command: Command; + command: TextCommand; parameters: InputParameter[]; } export type GetMode = "ALL" | "PREFIX" | "NO_PREFIX"; export interface PhraseOccurrenceData { - command: Command; + command: TextCommand; type: "NAME" | "ALIAS"; }