eval command tests
This commit is contained in:
parent
1f533e1e3c
commit
ceb5f6c148
5 changed files with 347 additions and 7 deletions
|
@ -3,6 +3,7 @@ import { TextChannel } from "discord.js";
|
|||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
||||
import { Command } from "../type/command";
|
||||
import { ICommandContext } from "../contracts/ICommandContext";
|
||||
import ICommandReturnContext from "../contracts/ICommandReturnContext";
|
||||
|
||||
export default class Clear extends Command {
|
||||
constructor() {
|
||||
|
@ -14,11 +15,15 @@ export default class Clear extends Command {
|
|||
];
|
||||
}
|
||||
|
||||
public override async execute(context: ICommandContext) {
|
||||
public override async execute(context: ICommandContext): Promise<ICommandReturnContext> {
|
||||
if (context.args.length == 0) {
|
||||
const errorEmbed = new ErrorEmbed(context, "Please specify an amount between 1 and 100");
|
||||
errorEmbed.SendToCurrentChannel();
|
||||
return;
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
embeds: [errorEmbed]
|
||||
};
|
||||
}
|
||||
|
||||
const totalToClear = Number.parseInt(context.args[0]);
|
||||
|
@ -26,12 +31,20 @@ export default class Clear extends Command {
|
|||
if (!totalToClear || totalToClear <= 0 || totalToClear > 100) {
|
||||
const errorEmbed = new ErrorEmbed(context, "Please specify an amount between 1 and 100");
|
||||
errorEmbed.SendToCurrentChannel();
|
||||
return;
|
||||
return {
|
||||
commandContext: context,
|
||||
embeds: [errorEmbed]
|
||||
};
|
||||
}
|
||||
|
||||
await (context.message.channel as TextChannel).bulkDelete(totalToClear);
|
||||
|
||||
const embed = new PublicEmbed(context, "", `${totalToClear} message(s) were removed`);
|
||||
embed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
embeds: [embed]
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
import { ICommandContext } from "../contracts/ICommandContext";
|
||||
import ICommandReturnContext from "../contracts/ICommandReturnContext";
|
||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
||||
import { Command } from "../type/command";
|
||||
|
@ -10,9 +11,12 @@ export default class Evaluate extends Command {
|
|||
super._category = "Owner";
|
||||
}
|
||||
|
||||
public override execute(context: ICommandContext) {
|
||||
public override execute(context: ICommandContext): ICommandReturnContext {
|
||||
if (context.message.author.id != process.env.BOT_OWNERID) {
|
||||
return;
|
||||
return {
|
||||
commandContext: context,
|
||||
embeds: []
|
||||
};
|
||||
}
|
||||
|
||||
const stmt = context.args;
|
||||
|
@ -24,10 +28,20 @@ export default class Evaluate extends Command {
|
|||
|
||||
const embed = new PublicEmbed(context, "", result);
|
||||
embed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
embeds: [embed]
|
||||
};
|
||||
}
|
||||
catch (err: any) {
|
||||
const errorEmbed = new ErrorEmbed(context, err);
|
||||
errorEmbed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
embeds: [errorEmbed]
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue