From 64e2344a85488a2ae641e00c4ba41ee73e4cc9e2 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Sun, 30 Apr 2017 14:40:19 +0000 Subject: [PATCH] Softban, Server Staff Role --- commands/moderation/ban.js | 2 +- commands/moderation/kick.js | 2 +- commands/moderation/prune.js | 2 +- commands/moderation/softban.js | 66 ++++++++++++++++++++++++++++++++++ commands/moderation/unban.js | 4 +-- commands/moderation/warn.js | 2 +- package.json | 2 +- 7 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 commands/moderation/softban.js diff --git a/commands/moderation/ban.js b/commands/moderation/ban.js index 7b423634..9e6cd365 100644 --- a/commands/moderation/ban.js +++ b/commands/moderation/ban.js @@ -31,7 +31,7 @@ module.exports = class BanCommand extends Command { } hasPermission(msg) { - return msg.member.permissions.has('BAN_MEMBERS'); + return msg.member.permissions.has('BAN_MEMBERS') || msg.member.roles.exists('name', 'Server Staff'); } async run(message, args) { diff --git a/commands/moderation/kick.js b/commands/moderation/kick.js index 5662e6f1..3053128d 100644 --- a/commands/moderation/kick.js +++ b/commands/moderation/kick.js @@ -28,7 +28,7 @@ module.exports = class KickCommand extends Command { } hasPermission(msg) { - return msg.member.permissions.has('KICK_MEMBERS'); + return msg.member.permissions.has('KICK_MEMBERS') || msg.member.roles.exists('name', 'Server Staff'); } async run(message, args) { diff --git a/commands/moderation/prune.js b/commands/moderation/prune.js index c4284887..4efd4766 100644 --- a/commands/moderation/prune.js +++ b/commands/moderation/prune.js @@ -26,7 +26,7 @@ module.exports = class PruneCommand extends Command { } hasPermission(msg) { - return msg.member.permissions.has('MANAGE_MESSAGES'); + return msg.member.permissions.has('MANAGE_MESSAGES') || msg.member.roles.exists('name', 'Server Staff'); } async run(message, args) { diff --git a/commands/moderation/softban.js b/commands/moderation/softban.js new file mode 100644 index 00000000..ffd4efa1 --- /dev/null +++ b/commands/moderation/softban.js @@ -0,0 +1,66 @@ +const { Command } = require('discord.js-commando'); +const { RichEmbed } = require('discord.js'); + +module.exports = class SoftbanCommand extends Command { + constructor(client) { + super(client, { + name: 'softban', + group: 'moderation', + memberName: 'softban', + description: 'Kicks a user and deletes their messages, and logs the softban to the mod_logs.', + guildOnly: true, + args: [{ + key: 'member', + prompt: 'What member do you want to softban?', + type: 'member' + }, { + key: 'reason', + prompt: 'What do you want to set the reason as?', + type: 'string', + validate: reason => { + if (reason.length < 140) { + return true; + } + return `Please keep your reason under 140 characters, you have ${reason.length}.`; + } + }] + }); + } + + hasPermission(msg) { + return msg.member.permissions.has('KICK_MEMBERS') || msg.member.roles.exists('name', 'Server Staff'); + } + + async run(message, args) { + if (!message.channel.permissionsFor(this.client.user).has('BAN_MEMBERS')) + return message.say('This Command requires the `Ban Members` Permission.'); + if (!message.channel.permissionsFor(this.client.user).has('KICK_MEMBERS')) + return message.say('This Command requires the `Kick Members` Permission.'); + const modlogs = message.guild.channels.find('name', message.guild.settings.get('modLog', 'mod_logs')); + if (!modlogs) + return message.say('This Command requires a channel named `mod_logs` or one custom set with the `modchannel` command.'); + if (!modlogs.permissionsFor(this.client.user).has('EMBED_LINKS')) + return message.say('This Command requires the `Embed Links` Permission.'); + const { member, reason } = args; + if (!member.bannable) + return message.say('This member is not bannable. Perhaps they have a higher role than me?'); + try { + try { + await member.send(`You were softbanned from ${message.guild.name}!\nReason: ${reason}.`); + } catch (err) { + await message.say('Failed to send DM to user.'); + } + await member.ban(7); + await message.guild.unban(member.user); + await message.say(':ok_hand:'); + const embed = new RichEmbed() + .setAuthor(message.author.tag, message.author.displayAvatarURL) + .setColor(0xFF0000) + .setTimestamp() + .setDescription(`**Member:** ${member.user.tag} (${member.id})\n**Action:** Ban\n**Reason:** ${reason}`); + return modlogs.send({embed}); + } catch (err) { + return message.say('An Unknown Error Occurred.'); + } + } +}; diff --git a/commands/moderation/unban.js b/commands/moderation/unban.js index 55474e5f..74ccf36c 100644 --- a/commands/moderation/unban.js +++ b/commands/moderation/unban.js @@ -35,7 +35,7 @@ module.exports = class UnbanCommand extends Command { } hasPermission(msg) { - return msg.member.permissions.has('BAN_MEMBERS'); + return msg.member.permissions.has('BAN_MEMBERS') || msg.member.roles.exists('name', 'Server Staff'); } async run(message, args) { @@ -50,7 +50,7 @@ module.exports = class UnbanCommand extends Command { const bans = await message.guild.fetchBans(); if (!bans.has(id)) return message.say('This ID is not in the Guild Banlist.'); - const member = await bans.get(id); + const member = bans.get(id); try { await message.guild.unban(member); await message.say(':ok_hand:'); diff --git a/commands/moderation/warn.js b/commands/moderation/warn.js index 4a344c97..c359af0e 100644 --- a/commands/moderation/warn.js +++ b/commands/moderation/warn.js @@ -27,7 +27,7 @@ module.exports = class WarnCommand extends Command { } hasPermission(msg) { - return msg.member.permissions.has('KICK_MEMBERS'); + return msg.member.permissions.has('KICK_MEMBERS') || msg.member.roles.exists('name', 'Server Staff'); } async run(message, args) { diff --git a/package.json b/package.json index d4d09252..824dbcfe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "17.0.1", + "version": "17.1.0", "description": "A Discord Bot", "main": "shardingmanager.js", "scripts": {