Ban command tests
This commit is contained in:
parent
12168b52c4
commit
1f533e1e3c
3 changed files with 597 additions and 5 deletions
src
|
@ -4,6 +4,7 @@ import LogEmbed from "../helpers/embeds/LogEmbed";
|
|||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
||||
import { Command } from "../type/command";
|
||||
import { ICommandContext } from "../contracts/ICommandContext";
|
||||
import ICommandReturnContext from "../contracts/ICommandReturnContext";
|
||||
|
||||
export default class Ban extends Command {
|
||||
constructor() {
|
||||
|
@ -15,13 +16,16 @@ export default class Ban extends Command {
|
|||
];
|
||||
}
|
||||
|
||||
public override async execute(context: ICommandContext) {
|
||||
public override async execute(context: ICommandContext): Promise<ICommandReturnContext> {
|
||||
const targetUser = context.message.mentions.users.first();
|
||||
|
||||
if (!targetUser) {
|
||||
const embed = new ErrorEmbed(context, "User does not exist");
|
||||
embed.SendToCurrentChannel();
|
||||
return;
|
||||
return {
|
||||
commandContext: context,
|
||||
embeds: [embed],
|
||||
};
|
||||
}
|
||||
|
||||
const targetMember = context.message.guild?.member(targetUser);
|
||||
|
@ -29,7 +33,10 @@ export default class Ban extends Command {
|
|||
if (!targetMember) {
|
||||
const embed = new ErrorEmbed(context, "User is not in this server");
|
||||
embed.SendToCurrentChannel();
|
||||
return;
|
||||
return {
|
||||
commandContext: context,
|
||||
embeds: [embed],
|
||||
};
|
||||
}
|
||||
|
||||
const reasonArgs = context.args;
|
||||
|
@ -38,13 +45,19 @@ export default class Ban extends Command {
|
|||
const reason = reasonArgs.join(" ");
|
||||
|
||||
if (!context.message.guild?.available) {
|
||||
return;
|
||||
return {
|
||||
commandContext: context,
|
||||
embeds: [],
|
||||
};
|
||||
}
|
||||
|
||||
if (!targetMember.bannable) {
|
||||
const embed = new ErrorEmbed(context, ErrorMessages.InsufficientBotPermissions);
|
||||
embed.SendToCurrentChannel();
|
||||
return;
|
||||
return {
|
||||
commandContext: context,
|
||||
embeds: [embed],
|
||||
};
|
||||
}
|
||||
|
||||
const logEmbed = new LogEmbed(context, "Member Banned");
|
||||
|
@ -58,5 +71,10 @@ export default class Ban extends Command {
|
|||
|
||||
logEmbed.SendToModLogsChannel();
|
||||
publicEmbed.SendToCurrentChannel();
|
||||
|
||||
return {
|
||||
commandContext: context,
|
||||
embeds: [logEmbed, publicEmbed],
|
||||
};
|
||||
}
|
||||
}
|
7
src/contracts/ICommandReturnContext.ts
Normal file
7
src/contracts/ICommandReturnContext.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
import { MessageEmbed } from "discord.js";
|
||||
import { ICommandContext } from "./ICommandContext";
|
||||
|
||||
export default interface ICommandReturnContext {
|
||||
commandContext: ICommandContext,
|
||||
embeds: MessageEmbed[]
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue