Skip to content

Commit

Permalink
softBan command now accepts user ID
Browse files Browse the repository at this point in the history
  • Loading branch information
Sankarsan Kampa committed Jan 27, 2018
1 parent af0d904 commit ac37f7b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion changes.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
],
"improved": [
"Are you a Patreon creator and hosting Bastion yourself? The `patrons` command will now show your patrons and not the patrons of the Bastion bot project.",
"`clearWarn`, `removeAllRoles`, `deafen`, `kick`, `mute`, `textMute`, `textUnMute`, `unDeafen`, `unMute` and `warn` commands can be used with the ID of the user. No need to mention them anymore.",
"`clearWarn`, `deafen`, `kick`, `mute`, `removeAllRoles`, `softBan`, `textMute`, `textUnMute`, `unDeafen`, `unMute` and `warn` commands can be used with the ID of the user. No need to mention them anymore.",
"Under-the-hood improvements"
],
"added": [],
Expand Down
31 changes: 19 additions & 12 deletions modules/moderation/softBan.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@

exports.exec = async (Bastion, message, args) => {
try {
let user = message.mentions.users.first();
let user;
if (message.mentions.users.size) {
user = message.mentions.users.first();
}
else if (args.id) {
user = await Bastion.fetchUser(args.id);
}
if (!user) {
/**
* The command was ran with invalid parameters.
Expand All @@ -26,14 +32,11 @@ exports.exec = async (Bastion, message, args) => {
return Bastion.emit('error', Bastion.strings.error(message.guild.language, 'forbidden'), Bastion.strings.error(message.guild.language, 'noPermission', true, 'soft-ban', user), message.channel);
}

let reason = args.slice(1).join(' ');
if (reason.length < 1) {
reason = 'No reason given';
}
args.reason = args.reason.join(' ');

await member.ban({
days: 7,
reason: reason
reason: args.reason
});

await message.guild.unban(user.id).catch(e => {
Expand Down Expand Up @@ -64,7 +67,7 @@ exports.exec = async (Bastion, message, args) => {
message.channel.send({
embed: {
color: Bastion.colors.RED,
description: `${message.author.tag} soft-banned ${user.tag} with reason **${reason}**`,
description: `${message.author.tag} soft-banned ${user.tag} with reason **${args.reason}**`,
footer: {
text: `ID ${user.id}`
}
Expand All @@ -77,13 +80,13 @@ exports.exec = async (Bastion, message, args) => {
* Logs moderation events if it is enabled
* @fires moderationLog
*/
Bastion.emit('moderationLog', message.guild, message.author, this.help.name, user, reason);
Bastion.emit('moderationLog', message.guild, message.author, this.help.name, user, args.reason);

let DMChannel = await user.createDM();
DMChannel.send({
embed: {
color: Bastion.colors.RED,
description: `${message.author.tag} soft-banned you from **${message.guild.name}** server with reason **${reason}**`
description: `${message.author.tag} soft-banned you from **${message.guild.name}** server with reason **${args.reason}**`
}
}).catch(e => {
Bastion.log.error(e);
Expand All @@ -96,14 +99,18 @@ exports.exec = async (Bastion, message, args) => {

exports.config = {
aliases: [ 'sb' ],
enabled: true
enabled: true,
argsDefinitions: [
{ name: 'id', type: String, defaultOption: true },
{ name: 'reason', alias: 'r', type: String, multiple: true, defaultValue: [ 'No reason given.' ] }
]
};

exports.help = {
name: 'softBan',
botPermission: 'BAN_MEMBERS',
userTextPermission: 'BAN_MEMBERS',
userVoicePermission: '',
usage: 'softBan @user-mention [Reason]',
example: [ 'softBan @user#0001 Reason for soft ban.' ]
usage: 'softBan <@USER_MENTION | USER_ID> -r [Reason]',
example: [ 'softBan @user#001 -r Spamming in support channel.', 'softBan 167147569575323761 -r Reputed spammer.' ]
};

0 comments on commit ac37f7b

Please sign in to comment.