add n?ban and fix n?kick

master
Kit Kasune 4 years ago
parent 4b1f962982
commit 669332adbe
  1. 73
      commands/ban.js
  2. 18
      commands/kick.js
  3. 12
      handle/command.js

@ -0,0 +1,73 @@
const Discord = require('discord.js');
const Mod = require('../models/mod');
const {Tag} = require('../util/tag');
const {TagFilter} = require('../util/tagfilter');
module.exports = {
name: "ban",
aliases: [],
meta: {
category: 'Moderation',
description: "Bans a member from the server!",
syntax: '`ban <@member|memberID> [reason]`',
extra: null,
guildOnly: true
},
help: new Discord.MessageEmbed()
.setTitle("Help -> Member Banning")
.setDescription("This command bans a member from the server permanently, making it so they cannot rejoin. *Yikes*")
.addField("Syntax", "`ban <@member|memberID> [reason]`")
.addField("Permissions", "You'll want to have the `ban members` permission in your server or be an administrator to do this!"),
async execute(message, msg, args, cmd, prefix, mention, client) {
if (!args.length) {return message.channel.send(`Syntax: \`${prefix}ban <@member|memberID> [reason]\``);}
if (!message.member.permissions.has("BAN_MEMBERS")) {return message.channel.send("You don't have permissions to do that!");}
if (!message.guild.me.permissions.has("BAN_MEMBERS")) {return message.channel.send("I don't have permissions to ban members in your server.");}
let user = message.guild.members.cache.get(args[0]) || message.mentions.members.first();
if (!user) {return message.channel.send("You must mention a user to ban, or provide their ID.");}
if (user.roles.highest.position >= message.member.roles.highest.position) {return message.channel.send("You don't have permissions to ban that member as they are above you in the roles list.");}
if (user.roles.highest.position >= message.guild.me.roles.highest.position) {return message.channel.send("I can't ban that member as their highest role is above mine! (Or the same as mine, too)");}
if (!user.bannable) {return message.channel.send("Hmm, it seems like I can't ban that member. This is probably a permissions issue. Or maybe they were already banned?");}
let options = new TagFilter([
new Tag(['r', 'reason'], 'reason', 'append'),
new Tag(['n', 'notes'], 'notes', 'append'),
new Tag(['d', 'days', 'm', 'messages'], 'days', 'append')
]).test(args.join(" "));
let reason; let days;
if (options.reason && options.reason.length) {reason = options.reason;}
if (options.days && options.days.length) {
if (isNaN(Number(options.days)) || Number(options.days) < 0 || Number(options.days) > 7 || options.days.includes('.')) {return message.channel.send("The `days` option must be a whole number between 0 and 7.");}
days = Number(options.days);
}
if (options.notes && options.notes.length > 250) {return message.channel.send("I mean I get it, they pissed you off, but do you really need to give me that much info on why you're banning them? I can't keep track of all that!");}
else {if (args[1] && !options.days /*&& (!options.notes || !options.notes.length)*/ && (!options.reason || !options.reason.length)) {args.shift(); reason = args.join(" ");}}
if (reason && reason.length > 250) {return message.channel.send("I mean I get it, they pissed you off, but do you really need to give me that much info on why you're banning them? I can't keep track of all that!");}
return user.ban({reason: reason})
.then(async () => {
/*let mh = await Mod.findOne({gid: message.guild.id}) || new Mod({gid: message.guild.id});
let mhcases = mh.cases;
mhcases.push({
members: [user.id],
punishment: "Banned",
reason: reason ? reason : "",
status: "Closed",
moderators: [message.author.id],
notes: options.notes,
history: [`${new Date().toISOString()} - ${message.author.username} - Created case`, `${new Date().toISOString()} - ${message.author.username} - Banned ${client.users.cache.get(user.id).username}`],
issued: new Date().toUTCString()
});
mh.cases = mhcases;
mh.save();*/
return message.channel.send(`The hammer of justice has spoken!${reason ? ` Reason for banning: ${reason}` : ''}`);
})
.catch(() => {return message.channel.send("Something went wrong while trying to ban that user! If the problem persists, contact my devs.");});
}
};

@ -22,27 +22,29 @@ module.exports = {
.addField("Notice", "This command requires you to have `kick` permissions in the server."), .addField("Notice", "This command requires you to have `kick` permissions in the server."),
async execute(message, msg, args, cmd, prefix, mention, client) { async execute(message, msg, args, cmd, prefix, mention, client) {
if (!args.length) {return message.channel.send(`Syntax: \`${prefix}kick <@user|userID> [reason]\``);} if (!args.length) {return message.channel.send(`Syntax: \`${prefix}kick <@user|userID> [reason]\``);}
if (!message.member.permissions.has("KICK_MEMBERS")) {return message.channel.send("You don't have permissions to do that!");} if (!message.member.permissions.has("KICK_MEMBERS")) {return message.channel.send("You don't have permissions to do that!");}
if (!message.guild.me.permissions.has("KICK_MEMBERS")) {return message.channel.send("I don't have permissions to kick members in your server.");} if (!message.guild.me.permissions.has("KICK_MEMBERS")) {return message.channel.send("I don't have permissions to kick members in your server.");}
let user = message.guild.members.cache.get(args[0]) || message.mentions.members.first(); let user = message.guild.members.cache.get(args[0]) || message.mentions.members.first();
if (!user) {return message.channel.send("You must mention a user to kick, or provide their ID.");} if (!user) {return message.channel.send("You must mention a user to kick, or provide their ID.");}
if (user.roles.highest.position >= message.member.roles.highest.position) {return message.channel.send("You don't have permissions to kick that member as they are above you in the roles list.");} if (user.roles.highest.position >= message.member.roles.highest.position) {return message.channel.send("You don't have permissions to kick that member as they are above you in the roles list.");}
if (user.roles.highest.position >= message.guild.me.roles.highest.position) {return message.channel.send("I can't kick that member as their highest role is above mine! (Or the same as mine, too)");} if (user.roles.highest.position >= message.guild.me.roles.highest.position) {return message.channel.send("I can't kick that member as their highest role is above mine! (Or the same as mine, too)");}
if (!user.kickable) {return message.channel.send("For some reason, I can't kick that user!");} if (!user.kickable) {return message.channel.send("For some reason, I can't kick that user!");}
let options = new TagFilter([ let options = new TagFilter([
new Tag(['r', 'reason'], 'reason', 'append'), new Tag(['r', 'reason'], 'reason', 'append')/*,
new Tag(['n', 'notes'], 'notes', 'append') new Tag(['n', 'notes'], 'notes', 'append')*/
]).test(args.join(" ")); ]).test(args.join(" "));
let reason; let reason;
if (options.notes && options.notes.length) {
if (options.reason && options.reason.length) {reason = options.reason;} if (options.reason && options.reason.length) {reason = options.reason;}
if (options.notes.length > 250) {return message.channel.send("Hey, listen, let's not write an essay on why you're kicking that member!");} //if (options.notes && options.notes.length > 250) {return message.channel.send("Hey, listen, let's not write an essay on why you're kicking that member!");}
}
else {if (args[1]) {args.shift(); reason = args.join(" ");}} else {if (args[1]) {args.shift(); reason = args.join(" ");}}
if (reason && reason.length > 250) {return message.channel.send("Hey, listen, let's not write an essay on why you're kicking that member!");} if (reason && reason.length > 250) {return message.channel.send("Hey, listen, let's not write an essay on why you're kicking that member!");}
return user.kick(reason) return user.kick(reason)
.then(async () => { .then(async () => {
let mh = await Mod.findOne({gid: message.guild.id}) || new Mod({gid: message.guild.id}); /*let mh = await Mod.findOne({gid: message.guild.id}) || new Mod({gid: message.guild.id});
let mhcases = mh.cases; let mhcases = mh.cases;
mhcases.push({ mhcases.push({
@ -57,9 +59,9 @@ module.exports = {
}); });
mh.cases = mhcases; mh.cases = mhcases;
mh.save(); mh.save();*/
return message.channel.send("I got em outta here!"); return message.channel.send(`I got em outta here!${reason ? ` Reason for kicking: ${reason}` : ''}`);
}) })
.catch(() => {return message.channel.send("Something went wrong while trying to kick that user! If the problem persists, contact my devs.");}); .catch(() => {return message.channel.send("Something went wrong while trying to kick that user! If the problem persists, contact my devs.");});
} }

@ -1,16 +1,28 @@
const Discord = require('discord.js'); const Discord = require('discord.js');
const fs = require('fs'); const fs = require('fs');
const chalk = require('chalk'); const chalk = require('chalk');
//const ora = require('ora');
module.exports = client => { module.exports = client => {
var commands = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); var commands = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
//console.log('');
//let cora = ora(`${chalk.white("Loading commands into client.")} ${chalk.blue("[")}${chalk.blueBright("0")}${chalk.blue("/")}${chalk.blueBright(`${commands.length}`)}${chalk.blue("]")}`).start();
//let num = 0;
console.log(`\n${chalk.gray('[BOOT]')} >> ${chalk.blue('Getting Commands...')}\n`); console.log(`\n${chalk.gray('[BOOT]')} >> ${chalk.blue('Getting Commands...')}\n`);
for (let commandf of commands) { for (let commandf of commands) {
//num++;
//cora.text = `${chalk.white("Loading commands into client.")} ${chalk.blue("[")}${chalk.blueBright(`${num}`)}${chalk.blue("/")}${chalk.blueBright(`${commands.length}`)}${chalk.blue("]")}`;
if (Object.keys(require.cache).includes(require.resolve(`../commands/${commandf}`))) {delete require.cache[require.resolve(`../commands/${commandf}`)];} if (Object.keys(require.cache).includes(require.resolve(`../commands/${commandf}`))) {delete require.cache[require.resolve(`../commands/${commandf}`)];}
var command = require(`../commands/${commandf}`); var command = require(`../commands/${commandf}`);
client.commands.set(command.name, command); client.commands.set(command.name, command);
if (command.aliases) {command.aliases.forEach(a => client.aliases.set(a, command.name));} if (command.aliases) {command.aliases.forEach(a => client.aliases.set(a, command.name));}
console.log(`${chalk.gray('[LOG] ')} >> ${chalk.blueBright('Loaded Command')} ${chalk.white(command.name)} ${chalk.blueBright('with')} ${chalk.white(command.aliases && command.aliases.length ? command.aliases.length : 0)} ${chalk.blueBright('aliases')}`); console.log(`${chalk.gray('[LOG] ')} >> ${chalk.blueBright('Loaded Command')} ${chalk.white(command.name)} ${chalk.blueBright('with')} ${chalk.white(command.aliases && command.aliases.length ? command.aliases.length : 0)} ${chalk.blueBright('aliases')}`);
} }
/*cora.stop(); cora.clear();
console.log(`${chalk.gray('[BOOT]')} >> ${chalk.blue('Getting Commands...')}\n`);
Array.from(client.commands.values()).forEach(command => {
console.log(`${chalk.gray('[LOG] ')} >> ${chalk.blueBright('Loaded Command')} ${chalk.white(command.name)} ${chalk.blueBright('with')} ${chalk.white(command.aliases && command.aliases.length ? command.aliases.length : 0)} ${chalk.blueBright('aliases')}`);
});*/
console.log(`\n${chalk.gray('[BOOT]')} >> ${chalk.blue('Loaded all Commands')}`); console.log(`\n${chalk.gray('[BOOT]')} >> ${chalk.blue('Loaded all Commands')}`);
}; };
Loading…
Cancel
Save