Success announcment (system message)

This commit is contained in:
mmacierzanka committed 2021-08-10 03:01:51 +02:00
1 parent 9e78438d0a
commit 4c7e295f12
5 files changed
+40 -8

No files matched your search

+13 -1
View File
@@ -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",
+8 -6
View File
@@ -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(
+11 -1
View File
@@ -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)) {
+7
View File
@@ -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;
}
}
+1
View File
@@ -29,6 +29,7 @@ export interface CommandBuilder {
guilds?: string[];
visible?: boolean;
slash?: boolean;
announceSuccess?: boolean;
function: (
params: (
query: string,