From c484753ee15dbe2a5ce9c6297f22fabb52ce3b7e Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 24 Feb 2018 14:59:35 -0500 Subject: New Command system --- commands/Moderation/ban.js | 40 ++++++++++++++++++++++++++++++++++++++++ commands/Moderation/kick.js | 23 +++++++++++++++++++++++ commands/Moderation/purge.js | 30 ++++++++++++++++++++++++++++++ commands/Moderation/softban.js | 40 ++++++++++++++++++++++++++++++++++++++++ commands/Moderation/warn.js | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 165 insertions(+) create mode 100644 commands/Moderation/ban.js create mode 100644 commands/Moderation/kick.js create mode 100644 commands/Moderation/purge.js create mode 100644 commands/Moderation/softban.js create mode 100644 commands/Moderation/warn.js (limited to 'commands/Moderation') diff --git a/commands/Moderation/ban.js b/commands/Moderation/ban.js new file mode 100644 index 0000000..3582bc3 --- /dev/null +++ b/commands/Moderation/ban.js @@ -0,0 +1,40 @@ +exports.run = async (bot, msg, args) => { + if (!msg.member.hasPermission('BAN_MEMBERS')) return msg.reply('You don\'t have permssion to ban members.'); + if (!msg.guild.member(bot.user).hasPermission('BAN_MEMBERS')) return msg.reply('I don\'t have permssion to ban members.'); + + const member = msg.mentions.members.first(); + if (!member) return await msg.reply('Who am I gonna ban?'); + const reason = args.join(' ').slice(3 + member.user.id.length); + + await member.ban({ days: 7, reason: msg.author.tag + (reason ? ': ' + reason : '') }) + .catch(err => { msg.reply('There was an error.'); console.error(err.stack);}); + msg.channel.send(`Alright, I banned **${member.user.tag}**${(reason ? ` for the reason **${reason}**.` : '.')}`); + + const { RichEmbed } = require('discord.js'); + try { + const embed = new RichEmbed() + .setColor(0x00ae86) + .setAuthor(member.user.tag, member.user.avatarURL) + .setTitle(`:hammer: **${member.user.tag}**`) + .setDescription(`*${member.user.tag}* was banned from the server by *${msg.author.tag}*.`) + .addField('Reason', reason ? reason : '*none*') + .addField('Moderator', msg.author.tag) + .setTimestamp() + .setFooter(`${msg.author.tag} banned ${member.user.tag}`, msg.author.avatarURL); + msg.guild.channels.find('name', 'logs').send({ embed }); + } + catch (err) { + console.error(err.stack); + } +}; + +exports.conf = { + aliases: [], + guildOnly: true, +}; + +exports.help = { + name: 'ban', + description: 'Ban a user from this server.', + usage: '@user <...reason>', +}; diff --git a/commands/Moderation/kick.js b/commands/Moderation/kick.js new file mode 100644 index 0000000..040abb5 --- /dev/null +++ b/commands/Moderation/kick.js @@ -0,0 +1,23 @@ +exports.run = async (bot, msg, args) => { + if (!msg.member.hasPermission('KICK_MEMBERS')) return msg.reply('You don\'t have permssion to kick members.'); + if (!msg.guild.member(bot.user).hasPermission('KICK_MEMBERS')) return msg.reply('I don\'t have permssion to kick members.'); + + const member = msg.mentions.members.first(); + if (!member) return await msg.reply('Who am I gonna kick?'); + const reason = args.join(' ').slice(3 + member.user.id.length); + + await member.kick(msg.author.tag + ': ' + (reason ? ': ' + reason : '')) + .catch(err => { msg.reply('There was an error.'); console.error(err.stack);}); + msg.channel.send(`Alright, I kicked **${member.user.tag}**${(reason ? ` for the reason **${reason}**.` : '.')}`); +}; + +exports.conf = { + aliases: [], + guildOnly: true, +}; + +exports.help = { + name: 'kick', + description: 'Kick a user out of the server.', + usage: '@user <...reason>', +}; diff --git a/commands/Moderation/purge.js b/commands/Moderation/purge.js new file mode 100644 index 0000000..0540bb3 --- /dev/null +++ b/commands/Moderation/purge.js @@ -0,0 +1,30 @@ +exports.run = async (bot, msg, args) => { + if (!msg.member.hasPermission('MANAGE_MESSAGES')) return msg.reply('You don\'t have permssion to manage messages.'); + if (!msg.guild.member(bot.user).hasPermission('MANAGE_MESSAGES')) return msg.reply('I don\'t have permssion to manage messages.'); + + const user = msg.mentions.users.first(); + const amount = parseInt(args[0]) ? parseInt(args[0]) : parseInt(args[1]); + + if (!amount) return msg.reply('How many message shall I delete?'); + if (!amount && !user) return msg.reply('Tell me the user and amount or the just the amount of messages to purge.'); + if (amount > 100 || amount < 3) return msg.reply('Choose an amount less than 98 and greater than 1'); + msg.delete(); + + let msgs = await msg.channel.fetchMessages({ limit: amount }); + if (user) { + const filterBy = user ? user.id : bot.user.id; + msgs = msgs.filter(m => m.author.id === filterBy).array().slice(0, amount); + } + msg.channel.bulkDelete(msgs).catch(error => console.log(error.stack)); +}; + +exports.conf = { + aliases: ['prune', 'rm'], + guildOnly: true, +}; + +exports.help = { + name: 'purge', + description: 'Get rid of messages quickly.', + usage: '@user ', +}; diff --git a/commands/Moderation/softban.js b/commands/Moderation/softban.js new file mode 100644 index 0000000..f95e3b8 --- /dev/null +++ b/commands/Moderation/softban.js @@ -0,0 +1,40 @@ +exports.run = async (bot, msg, args) => { + if (!msg.member.hasPermission('BAN_MEMBERS')) return msg.reply('You don\'t have permssion to ban members.'); + if (!msg.guild.member(bot.user).hasPermission('BAN_MEMBERS')) return msg.reply('I don\'t have permssion to ban members.'); + + const member = msg.mentions.members.first(); + if (!member) return await msg.reply('Who am I gonna softban?'); + const reason = args.join(' ').slice(3 + member.user.id.length); + + await member.ban({ days: 7, reason: msg.author.tag + ': ' + (reason ? reason : '') }) + .catch(err => { msg.reply('There was an error.'); console.error(err.stack);}); + await msg.guild.unban(member.user.id).catch(msg.reply('There was an error.')); + msg.channel.send(`Alright, I softbanned **${member.user.tag}**${(reason ? ` for the reason **${reason}**.` : '.')}`); + const { RichEmbed } = require('discord.js'); + try { + const embed = new RichEmbed() + .setColor(0x00ae86) + .setAuthor(member.user.tag, member.user.avatarURL) + .setTitle(`:hammer: **${member.user.tag}**`) + .setDescription(`*${member.user.tag}* was softbanned from the server by *${msg.author.tag}*.`) + .addField('Reason', reason ? reason : '*none*') + .addField('Moderator', msg.author.tag) + .setTimestamp() + .setFooter(`${msg.author.tag} softbanned ${member.user.tag}`, msg.author.avatarURL); + msg.guild.channels.find('name', 'logs').send({ embed }); + } + catch (err) { + console.error(err.stack); + } +}; + +exports.conf = { + aliases: [], + guildOnly: true, +}; + +exports.help = { + name: 'softban', + description: 'Kick the user and delete their messages.', + usage: '@user <...reason>', +}; diff --git a/commands/Moderation/warn.js b/commands/Moderation/warn.js new file mode 100644 index 0000000..75d586c --- /dev/null +++ b/commands/Moderation/warn.js @@ -0,0 +1,32 @@ +exports.run = (bot, msg, args) => { + if (!msg.member.hasPermission('MANAGE_MESSAGES')) return msg.reply('You don\'t have permssion to warn.'); + args.shift(); + const warnReason = args.join(' '); + const victim = msg.mentions.members.first(); + + msg.channel.send(`Successfully logged ${victim.user.tag}'s warning.`); + + const { RichEmbed } = require('discord.js'); + bot.channels.find('name', 'logs').send( + new RichEmbed() + .setColor(0x00ae86) + .setTitle(':warning: Warning') + .setAuthor(victim.user.tag, victim.user.avatarURL) + .addField('Warning Reason', warnReason) + .addField('ID', victim.id, true) + .addField('Created Account', victim.user.createdAt, true) + .setTimestamp() + .setFooter('Warned by: ' + msg.author.tag, msg.author.avatarURL) + ); +}; + +exports.conf = { + aliases: [], + guildOnly: true, +}; + +exports.help = { + name: 'warn', + description: 'Logs a warning to the user.', + usage : '@user ', +}; -- cgit v1.2.3