v3.0 #145

Merged
Vylpes merged 44 commits from develop into main 2022-04-24 14:46:37 +01:00
4 changed files with 38 additions and 60 deletions
Showing only changes of commit be329d709f - Show all commits

View file

@ -1,58 +0,0 @@
// Required components
const { command } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
const embedColor = "0x3050ba";
// Command Class
class clear extends command {
constructor() {
// Set execute method, description, category, and usage
super("clear");
super.description = "Bulk deletes the chat for up to 100 messages";
super.category = "Moderation";
super.usage = "<amount>";
// Set required configs in the config.clear json string
super.requiredConfigs = "modrole";
super.requiredConfigs = "logchannel";
}
// Execute method
clear(context) {
// If the user has the config.clear.modrole role
if (context.message.member.roles.cache.find(role => role.name == context.client.config.clear.modrole)) {
// If the command specifies a number between 1 and 100
if (context.arguments.length > 0 && context.arguments[0] > 0 && context.arguments[0] < 101) {
// Attempt to bulk delete the amount of messages specified as an argument
context.message.channel.bulkDelete(context.arguments[0]).then(() => {
// Public embed
const embed = new MessageEmbed()
.setColor(embedColor)
.setDescription(`${context.arguments[0]} messages were removed`);
// Send the embed into the channel the command was sent in
context.message.channel.send(embed);
}).catch(err => { // If the bot couldn't bulk delete
errorEmbed(context, "An error has occurred");
console.log(err);
});
} else { // If the user didn't give a number valid (between 1 and 100)
errorEmbed(context, "Please specify an amount between 1 and 100");
}
} else { // If the user doesn't have the mod role
errorEmbed(context, `This command requires the \`${context.client.config.clear.modrole}\` role to run`);
}
}
}
// Function to send an error embed
function errorEmbed(context, message) {
const embed = new MessageEmbed()
.setColor(embedColor)
.setDescription(message);
context.message.channel.send(embed);
}
module.exports = clear;

36
src/commands/clear.ts Normal file
View file

@ -0,0 +1,36 @@
import { Command, ICommandContext } from "vylbot-core";
import ErrorEmbed from "../helpers/ErrorEmbed";
import { TextChannel } from "discord.js";
import PublicEmbed from "../helpers/PublicEmbed";
export default class Clear extends Command {
constructor() {
super();
super._category = "Moderation";
super._roles = [
process.env.ROLES_MODERATOR!
];
}
public override async execute(context: ICommandContext) {
if (context.args.length == 0) {
const errorEmbed = new ErrorEmbed(context, "Please specify an amount between 1 and 100");
errorEmbed.SendToCurrentChannel();
return;
}
const totalToClear = Number.parseInt(context.args[0]);
if (!totalToClear || totalToClear <= 0 || totalToClear > 100) {
const errorEmbed = new ErrorEmbed(context, "Please specify an amount between 1 and 100");
errorEmbed.SendToCurrentChannel();
return;
}
await (context.message.channel as TextChannel).bulkDelete(totalToClear);
const embed = new PublicEmbed(context, "", `${totalToClear} message(s) were removed`);
embed.SendToCurrentChannel();
}
}

View file

@ -9,7 +9,7 @@ export default class LogEmbed extends MessageEmbed {
constructor(context: ICommandContext, title: string) {
super();
super.setColor(process.env.ERROR_EMBED!);
super.setColor(process.env.EMBED_COLOUR!);
super.setTitle(title);
this._context = context;

View file

@ -7,7 +7,7 @@ export default class PublicEmbed extends MessageEmbed {
constructor(context: ICommandContext, title: string, description: string) {
super();
super.setColor(process.env.ERROR_EMBED!);
super.setColor(process.env.EMBED_COLOUR!);
super.setTitle(title);
super.setDescription(description);