2022-09-05 18:10:04 +01:00
|
|
|
import { AuditType } from "../constants/AuditType";
|
2022-04-24 14:46:37 +01:00
|
|
|
import ErrorMessages from "../constants/ErrorMessages";
|
|
|
|
import { ICommandContext } from "../contracts/ICommandContext";
|
|
|
|
import ICommandReturnContext from "../contracts/ICommandReturnContext";
|
2022-09-05 18:10:04 +01:00
|
|
|
import Audit from "../entity/Audit";
|
2022-04-24 14:46:37 +01:00
|
|
|
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
|
|
|
import LogEmbed from "../helpers/embeds/LogEmbed";
|
|
|
|
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
|
|
|
import { Command } from "../type/command";
|
|
|
|
|
|
|
|
export default class Kick extends Command {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
super.Category = "Moderation";
|
|
|
|
super.Roles = [
|
|
|
|
"moderator"
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
2022-06-05 14:11:01 +01:00
|
|
|
await embed.SendToCurrentChannel();
|
2022-04-24 14:46:37 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
commandContext: context,
|
|
|
|
embeds: [embed]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const targetMember = context.message.guild?.members.cache.find(x => x.user.id == targetUser.id);
|
|
|
|
|
|
|
|
if (!targetMember) {
|
|
|
|
const embed = new ErrorEmbed(context, "User is not in this server");
|
2022-06-05 14:11:01 +01:00
|
|
|
await embed.SendToCurrentChannel();
|
2022-04-24 14:46:37 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
commandContext: context,
|
|
|
|
embeds: [embed]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const reasonArgs = context.args;
|
|
|
|
reasonArgs.splice(0, 1)
|
|
|
|
|
|
|
|
const reason = reasonArgs.join(" ");
|
|
|
|
|
|
|
|
if (!context.message.guild?.available) {
|
|
|
|
return {
|
|
|
|
commandContext: context,
|
|
|
|
embeds: []
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!targetMember.kickable) {
|
|
|
|
const embed = new ErrorEmbed(context, ErrorMessages.InsufficientBotPermissions);
|
2022-06-05 14:11:01 +01:00
|
|
|
await embed.SendToCurrentChannel();
|
2022-04-24 14:46:37 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
commandContext: context,
|
|
|
|
embeds: [embed]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const logEmbed = new LogEmbed(context, "Member Kicked");
|
|
|
|
logEmbed.AddUser("User", targetUser, true);
|
|
|
|
logEmbed.AddUser("Moderator", context.message.author);
|
|
|
|
logEmbed.AddReason(reason);
|
|
|
|
|
|
|
|
const publicEmbed = new PublicEmbed(context, "", `${targetUser} has been kicked`);
|
|
|
|
|
|
|
|
await targetMember.kick(`Moderator: ${context.message.author.tag}, Reason: ${reason || "*none*"}`);
|
|
|
|
|
|
|
|
await logEmbed.SendToModLogsChannel();
|
2022-06-05 14:11:01 +01:00
|
|
|
await publicEmbed.SendToCurrentChannel();
|
2022-09-05 18:10:04 +01:00
|
|
|
|
|
|
|
if (context.message.guild) {
|
|
|
|
const audit = new Audit(targetUser.id, AuditType.Kick, reason, context.message.author.id, context.message.guild.id);
|
|
|
|
|
|
|
|
await audit.Save(Audit, audit);
|
|
|
|
}
|
2022-04-24 14:46:37 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
commandContext: context,
|
|
|
|
embeds: [logEmbed, publicEmbed]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|