Migrate mute command
This commit is contained in:
parent
019966f25f
commit
0d3134bf45
6 changed files with 79 additions and 98 deletions
70
src/commands/mute.ts
Normal file
70
src/commands/mute.ts
Normal file
|
@ -0,0 +1,70 @@
|
|||
import { Command, ICommandContext } from "vylbot-core";
|
||||
import ErrorMessages from "../constants/ErrorMessages";
|
||||
import ErrorEmbed from "../helpers/ErrorEmbed";
|
||||
import LogEmbed from "../helpers/LogEmbed";
|
||||
import PublicEmbed from "../helpers/PublicEmbed";
|
||||
|
||||
export default class Mute extends Command {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
super._category = "Moderation";
|
||||
super._roles = [
|
||||
process.env.ROLES_MODERATOR!
|
||||
];
|
||||
}
|
||||
|
||||
public override async execute(context: ICommandContext) {
|
||||
const targetUser = context.message.mentions.users.first();
|
||||
|
||||
if (!targetUser) {
|
||||
const embed = new ErrorEmbed(context, "User does not exist");
|
||||
embed.SendToCurrentChannel();
|
||||
return;
|
||||
}
|
||||
|
||||
const targetMember = context.message.guild?.member(targetUser);
|
||||
|
||||
if (!targetMember) {
|
||||
const embed = new ErrorEmbed(context, "User is not in this server");
|
||||
embed.SendToCurrentChannel();
|
||||
return;
|
||||
}
|
||||
|
||||
const reasonArgs = context.args;
|
||||
reasonArgs.splice(0, 1);
|
||||
|
||||
const reason = reasonArgs.join(" ");
|
||||
|
||||
if (!context.message.guild?.available) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!targetMember.manageable) {
|
||||
const embed = new ErrorEmbed(context, ErrorMessages.InsufficientBotPermissions);
|
||||
embed.SendToCurrentChannel();
|
||||
return;
|
||||
}
|
||||
|
||||
const logEmbed = new LogEmbed(context, "Member Muted");
|
||||
logEmbed.AddUser("User", targetUser, true)
|
||||
logEmbed.AddUser("Moderator", context.message.author);
|
||||
logEmbed.AddReason(reason);
|
||||
|
||||
const publicEmbed = new PublicEmbed(context, "", `${targetUser} has been muted`);
|
||||
publicEmbed.AddReason(reason);
|
||||
|
||||
const mutedRole = context.message.guild.roles.cache.find(role => role.name == process.env.COMMANDS_MUTE_ROLE);
|
||||
|
||||
if (!mutedRole) {
|
||||
const embed = new ErrorEmbed(context, ErrorMessages.RoleNotFound);
|
||||
embed.SendToCurrentChannel();
|
||||
return;
|
||||
}
|
||||
|
||||
await targetMember.roles.add(mutedRole, reason);
|
||||
|
||||
logEmbed.SendToModLogsChannel();
|
||||
publicEmbed.SendToCurrentChannel();
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
export default class ErrorMessages {
|
||||
public static readonly InsufficientBotPermissions = "Unable to do this action, am I missing permissions?";
|
||||
public static readonly CantFindChannel = "Unable to find channel";
|
||||
public static readonly RoleNotFound = "Unable to find role";
|
||||
}
|
|
@ -14,6 +14,11 @@ export default class PublicEmbed extends MessageEmbed {
|
|||
this._context = context;
|
||||
}
|
||||
|
||||
// Detail methods
|
||||
public AddReason(message: String) {
|
||||
super.addField("Reason", message || "*none*");
|
||||
}
|
||||
|
||||
// Send methods
|
||||
public SendToCurrentChannel() {
|
||||
this._context.message.channel.send(this);
|
||||
|
|
|
@ -12,6 +12,7 @@ if (!process.env.ROLES_MODERATOR) throw "ROLES_MODERATOR is required in .env";
|
|||
if (!process.env.CHANNELS_LOGS_MESSAGE) throw "CHANNELS_LOGS_MESSAGE is required in .env";
|
||||
if (!process.env.CHANNELS_LOGS_MEMBER) throw "CHANNELS_LOGS_MEMBER is required in .env";
|
||||
if (!process.env.CHANNELS_LOGS_MOD) throw "CHANNELS_LOGS_MOD is required in .env";
|
||||
if (!process.env.COMMANDS_MUTE_ROLE) throw "COMMANDS_MUTE_ROLE is required in .env";
|
||||
|
||||
const client = new CoreClient();
|
||||
client.start();
|
Loading…
Add table
Add a link
Reference in a new issue