Archived
Command -> TextCommand
This commit is contained in:
1 parent
996c3733a0
commit
108bfb38d3
8 files changed
+37
-37
No files matched your search
@@ -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,
|
||||
|
||||
+5
-5
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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`);
|
||||
|
||||
@@ -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() {
|
||||
@@ -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}
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
Reference in new issue
Block a user