Archived
Success announcment (system message)
This commit is contained in:
1 parent
9e78438d0a
commit
4c7e295f12
5 files changed
+40
-8
No files matched your search
+13
-1
@@ -10,7 +10,7 @@ import { EventEmitter } from "events";
|
|||||||
import * as http from "http";
|
import * as http from "http";
|
||||||
import { Command } from "./Command.js";
|
import { Command } from "./Command.js";
|
||||||
import { CommandManager } from "./CommandManager.js";
|
import { CommandManager } from "./CommandManager.js";
|
||||||
import { PermissionsError } from "./errors.js";
|
import { OperationSuccess, PermissionsError } from "./errors.js";
|
||||||
import { HelpMessage } from "./Help.js";
|
import { HelpMessage } from "./Help.js";
|
||||||
import { SystemMessageManager } from "./SystemMessage.js";
|
import { SystemMessageManager } from "./SystemMessage.js";
|
||||||
import {
|
import {
|
||||||
@@ -180,6 +180,12 @@ export class Bot extends EventEmitter {
|
|||||||
},
|
},
|
||||||
m
|
m
|
||||||
);
|
);
|
||||||
|
} else if (e instanceof OperationSuccess) {
|
||||||
|
await this.messages.system.send(
|
||||||
|
"SUCCESS",
|
||||||
|
undefined,
|
||||||
|
m
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
await this.messages.system.send(
|
await this.messages.system.send(
|
||||||
"ERROR",
|
"ERROR",
|
||||||
@@ -224,6 +230,12 @@ export class Bot extends EventEmitter {
|
|||||||
},
|
},
|
||||||
i as CommandInteraction
|
i as CommandInteraction
|
||||||
);
|
);
|
||||||
|
} else if (e instanceof OperationSuccess) {
|
||||||
|
await this.messages.system.send(
|
||||||
|
"SUCCESS",
|
||||||
|
undefined,
|
||||||
|
i as CommandInteraction
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
await this.messages.system.send(
|
await this.messages.system.send(
|
||||||
"ERROR",
|
"ERROR",
|
||||||
|
|||||||
+8
-6
@@ -12,7 +12,7 @@ import {
|
|||||||
ParameterResolvable,
|
ParameterResolvable,
|
||||||
PermissionCheckTypes,
|
PermissionCheckTypes,
|
||||||
} from "./types.js";
|
} from "./types.js";
|
||||||
import { PermissionsError } from "./errors.js";
|
import { OperationSuccess, PermissionsError } from "./errors.js";
|
||||||
import { DefaultParameter, InputParameter, Parameter } from "./Parameter.js";
|
import { DefaultParameter, InputParameter, Parameter } from "./Parameter.js";
|
||||||
|
|
||||||
//CLASSES
|
//CLASSES
|
||||||
@@ -27,6 +27,7 @@ export class Command {
|
|||||||
guilds?: string[];
|
guilds?: string[];
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
slash: boolean;
|
slash: boolean;
|
||||||
|
announceSuccess: boolean;
|
||||||
private function: (
|
private function: (
|
||||||
params: (
|
params: (
|
||||||
query: string,
|
query: string,
|
||||||
@@ -77,6 +78,10 @@ export class Command {
|
|||||||
this.guilds = options.guilds;
|
this.guilds = options.guilds;
|
||||||
this.visible = options.visible !== undefined ? options.visible : true;
|
this.visible = options.visible !== undefined ? options.visible : true;
|
||||||
this.slash = options.slash !== undefined ? options.slash : true;
|
this.slash = options.slash !== undefined ? options.slash : true;
|
||||||
|
this.announceSuccess =
|
||||||
|
options.announceSuccess !== undefined
|
||||||
|
? options.announceSuccess
|
||||||
|
: true;
|
||||||
this.function = options.function;
|
this.function = options.function;
|
||||||
if (!/^[\w-]{1,32}$/.test(this.name)) {
|
if (!/^[\w-]{1,32}$/.test(this.name)) {
|
||||||
throw new Error(`Incorrect command name: ${this.name}`);
|
throw new Error(`Incorrect command name: ${this.name}`);
|
||||||
@@ -147,11 +152,8 @@ export class Command {
|
|||||||
await interaction?.reply({ embeds: [fnResult] });
|
await interaction?.reply({ embeds: [fnResult] });
|
||||||
else if (interaction instanceof CommandInteraction)
|
else if (interaction instanceof CommandInteraction)
|
||||||
await interaction.editReply({ embeds: [fnResult] });
|
await interaction.editReply({ embeds: [fnResult] });
|
||||||
} else if (
|
} else if (this.announceSuccess) {
|
||||||
interaction instanceof CommandInteraction &&
|
throw new OperationSuccess(this);
|
||||||
!interaction.replied
|
|
||||||
) {
|
|
||||||
await interaction.deleteReply();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new PermissionsError(
|
throw new PermissionsError(
|
||||||
|
|||||||
+11
-1
@@ -9,7 +9,7 @@ import {
|
|||||||
import { Command } from "./Command.js";
|
import { Command } from "./Command.js";
|
||||||
import { PermissionsError } from "./errors.js";
|
import { PermissionsError } from "./errors.js";
|
||||||
|
|
||||||
export type MessageType = "PERMISSION" | "ERROR" | "NOT_FOUND";
|
export type MessageType = "PERMISSION" | "ERROR" | "NOT_FOUND" | "SUCCESS";
|
||||||
export interface SystemMessageAppearance {
|
export interface SystemMessageAppearance {
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
title: string;
|
title: string;
|
||||||
@@ -29,6 +29,7 @@ export class SystemMessageManager {
|
|||||||
PERMISSION: SystemMessageAppearance;
|
PERMISSION: SystemMessageAppearance;
|
||||||
ERROR: SystemMessageAppearance;
|
ERROR: SystemMessageAppearance;
|
||||||
NOT_FOUND: SystemMessageAppearance;
|
NOT_FOUND: SystemMessageAppearance;
|
||||||
|
SUCCESS: SystemMessageAppearance;
|
||||||
deleteTimeout: number;
|
deleteTimeout: number;
|
||||||
|
|
||||||
constructor(botName?: string) {
|
constructor(botName?: string) {
|
||||||
@@ -55,6 +56,13 @@ export class SystemMessageManager {
|
|||||||
showTimestamp: true,
|
showTimestamp: true,
|
||||||
footer: botName,
|
footer: botName,
|
||||||
};
|
};
|
||||||
|
this.SUCCESS = {
|
||||||
|
enabled: true,
|
||||||
|
title: "✅ Task completed successfully",
|
||||||
|
accentColor: "#00ff00",
|
||||||
|
showTimestamp: true,
|
||||||
|
footer: botName,
|
||||||
|
};
|
||||||
this.deleteTimeout = Infinity;
|
this.deleteTimeout = Infinity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,6 +156,8 @@ export class SystemMessageManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "SUCCESS":
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (interaction && !(interaction instanceof CommandInteraction)) {
|
if (interaction && !(interaction instanceof CommandInteraction)) {
|
||||||
|
|||||||
@@ -39,3 +39,10 @@ export class MissingParameterError extends ReferenceError {
|
|||||||
return `Your request is missing a "${this.argument.name}" parameter which is not optional`;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,6 +29,7 @@ export interface CommandBuilder {
|
|||||||
guilds?: string[];
|
guilds?: string[];
|
||||||
visible?: boolean;
|
visible?: boolean;
|
||||||
slash?: boolean;
|
slash?: boolean;
|
||||||
|
announceSuccess?: boolean;
|
||||||
function: (
|
function: (
|
||||||
params: (
|
params: (
|
||||||
query: string,
|
query: string,
|
||||||
|
|||||||
Reference in new issue
Block a user