diff --git a/src/Bot.ts b/src/Bot.ts index aa038fd..cb745cc 100644 --- a/src/Bot.ts +++ b/src/Bot.ts @@ -10,7 +10,7 @@ import { EventEmitter } from "events"; import * as http from "http"; import { Command } from "./Command.js"; import { CommandManager } from "./CommandManager.js"; -import { PermissionsError } from "./errors.js"; +import { OperationSuccess, PermissionsError } from "./errors.js"; import { HelpMessage } from "./Help.js"; import { SystemMessageManager } from "./SystemMessage.js"; import { @@ -180,6 +180,12 @@ export class Bot extends EventEmitter { }, m ); + } else if (e instanceof OperationSuccess) { + await this.messages.system.send( + "SUCCESS", + undefined, + m + ); } else { await this.messages.system.send( "ERROR", @@ -224,6 +230,12 @@ export class Bot extends EventEmitter { }, i as CommandInteraction ); + } else if (e instanceof OperationSuccess) { + await this.messages.system.send( + "SUCCESS", + undefined, + i as CommandInteraction + ); } else { await this.messages.system.send( "ERROR", diff --git a/src/Command.ts b/src/Command.ts index 747bd09..6340546 100644 --- a/src/Command.ts +++ b/src/Command.ts @@ -12,7 +12,7 @@ import { ParameterResolvable, PermissionCheckTypes, } from "./types.js"; -import { PermissionsError } from "./errors.js"; +import { OperationSuccess, PermissionsError } from "./errors.js"; import { DefaultParameter, InputParameter, Parameter } from "./Parameter.js"; //CLASSES @@ -27,6 +27,7 @@ export class Command { guilds?: string[]; visible: boolean; slash: boolean; + announceSuccess: boolean; private function: ( params: ( query: string, @@ -77,6 +78,10 @@ export class Command { this.guilds = options.guilds; this.visible = options.visible !== undefined ? options.visible : true; this.slash = options.slash !== undefined ? options.slash : true; + this.announceSuccess = + options.announceSuccess !== undefined + ? options.announceSuccess + : true; this.function = options.function; if (!/^[\w-]{1,32}$/.test(this.name)) { throw new Error(`Incorrect command name: ${this.name}`); @@ -147,11 +152,8 @@ export class Command { await interaction?.reply({ embeds: [fnResult] }); else if (interaction instanceof CommandInteraction) await interaction.editReply({ embeds: [fnResult] }); - } else if ( - interaction instanceof CommandInteraction && - !interaction.replied - ) { - await interaction.deleteReply(); + } else if (this.announceSuccess) { + throw new OperationSuccess(this); } } else { throw new PermissionsError( diff --git a/src/SystemMessage.ts b/src/SystemMessage.ts index 407a9bd..2602b83 100644 --- a/src/SystemMessage.ts +++ b/src/SystemMessage.ts @@ -9,7 +9,7 @@ import { import { Command } from "./Command.js"; import { PermissionsError } from "./errors.js"; -export type MessageType = "PERMISSION" | "ERROR" | "NOT_FOUND"; +export type MessageType = "PERMISSION" | "ERROR" | "NOT_FOUND" | "SUCCESS"; export interface SystemMessageAppearance { enabled: boolean; title: string; @@ -29,6 +29,7 @@ export class SystemMessageManager { PERMISSION: SystemMessageAppearance; ERROR: SystemMessageAppearance; NOT_FOUND: SystemMessageAppearance; + SUCCESS: SystemMessageAppearance; deleteTimeout: number; constructor(botName?: string) { @@ -55,6 +56,13 @@ export class SystemMessageManager { showTimestamp: true, footer: botName, }; + this.SUCCESS = { + enabled: true, + title: "✅ Task completed successfully", + accentColor: "#00ff00", + showTimestamp: true, + footer: botName, + }; this.deleteTimeout = Infinity; } @@ -148,6 +156,8 @@ export class SystemMessageManager { } } break; + case "SUCCESS": + break; } } if (interaction && !(interaction instanceof CommandInteraction)) { diff --git a/src/errors.ts b/src/errors.ts index 6d73aae..2e4911f 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -39,3 +39,10 @@ export class MissingParameterError extends ReferenceError { return `Your request is missing a "${this.argument.name}" parameter which is not optional`; } } + +export class OperationSuccess { + command: Command; + constructor(c: Command) { + this.command = c; + } +} diff --git a/src/types.ts b/src/types.ts index 036868b..625765b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -29,6 +29,7 @@ export interface CommandBuilder { guilds?: string[]; visible?: boolean; slash?: boolean; + announceSuccess?: boolean; function: ( params: ( query: string,