diff --git a/CHANGELOG.md b/CHANGELOG.md index c89f128a0..f2a7a5002 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog. ## Unreleased +### Added + +- Added `.massban` to ban multiple people at once. 30 second cooldown + ### Changed - Ban `.warnp` will now prune user's messages diff --git a/src/NadekoBot/Modules/Administration/UserPunishCommands.cs b/src/NadekoBot/Modules/Administration/UserPunishCommands.cs index 5c822e6f2..7c0dc84ca 100644 --- a/src/NadekoBot/Modules/Administration/UserPunishCommands.cs +++ b/src/NadekoBot/Modules/Administration/UserPunishCommands.cs @@ -9,9 +9,11 @@ using NadekoBot.Services.Database.Models; using NadekoBot.Extensions; using NadekoBot.Modules.Administration.Services; using System; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using NadekoBot.Modules.Permissions.Services; +using NadekoBot.Modules.Searches.Common; using Serilog; namespace NadekoBot.Modules.Administration @@ -762,6 +764,78 @@ namespace NadekoBot.Modules.Administration await ctx.Channel.EmbedAsync(toSend) .ConfigureAwait(false); } + + [NadekoCommand, Aliases] + [RequireContext(ContextType.Guild)] + [UserPerm(GuildPerm.BanMembers)] + [BotPerm(GuildPerm.BanMembers)] + [Ratelimit(30)] + public async Task MassBan(params string[] userStrings) + { + if (userStrings.Length == 0) + return; + + var missing = new List(); + var banning = new HashSet(); + + await ctx.Channel.TriggerTypingAsync(); + foreach (var userStr in userStrings) + { + if (ulong.TryParse(userStr, out var userId)) + { + var user = await ctx.Guild.GetUserAsync(userId) ?? + await ((DiscordSocketClient)Context.Client).Rest.GetGuildUserAsync(ctx.Guild.Id, userId); + + if (user is null) + { + missing.Add(userStr); + continue; + } + + if (!await CheckRoleHierarchy(user)) + { + return; + } + + banning.Add(user); + } + else + { + missing.Add(userStr); + } + } + + var missStr = string.Join("\n", missing); + if (string.IsNullOrWhiteSpace(missStr)) + missStr = "-"; + + var toSend = _eb.Create(ctx) + .WithDescription(GetText(strs.mass_ban_in_progress(banning.Count))) + .AddField(GetText(strs.invalid(missing.Count)), missStr) + .WithPendingColor(); + + var banningMessage = await ctx.Channel.EmbedAsync(toSend); + + foreach (var toBan in banning) + { + try + { + await toBan.BanAsync(7); + } + catch (Exception ex) + { + Log.Warning(ex, "Error banning {User} user in {GuildId} server", + toBan.Id, + ctx.Guild.Id); + } + } + + await banningMessage.ModifyAsync(x => x.Embed = _eb.Create() + .WithDescription(GetText(strs.mass_ban_completed(banning.Count()))) + .AddField(GetText(strs.invalid(missing.Count)), missStr) + .WithOkColor() + .Build()).ConfigureAwait(false); + } [NadekoCommand, Aliases] [RequireContext(ContextType.Guild)] @@ -783,7 +857,7 @@ namespace NadekoBot.Modules.Administration var banningMessageTask = ctx.Channel.EmbedAsync(_eb.Create() .WithDescription(GetText(strs.mass_kill_in_progress(bans.Count()))) .AddField(GetText(strs.invalid(missing)), missStr) - .WithOkColor()); + .WithPendingColor()); //do the banning await Task.WhenAll(bans diff --git a/src/NadekoBot/data/aliases.yml b/src/NadekoBot/data/aliases.yml index 8295c6aec..4acca5e01 100644 --- a/src/NadekoBot/data/aliases.yml +++ b/src/NadekoBot/data/aliases.yml @@ -1193,6 +1193,8 @@ crypto: rolelevelreq: - rolelevelreq - rlr +massban: + - massban masskill: - masskill pathofexile: diff --git a/src/NadekoBot/data/strings/commands/commands.en-US.yml b/src/NadekoBot/data/strings/commands/commands.en-US.yml index 4191dc403..a721a662b 100644 --- a/src/NadekoBot/data/strings/commands/commands.en-US.yml +++ b/src/NadekoBot/data/strings/commands/commands.en-US.yml @@ -2010,6 +2010,10 @@ rolelevelreq: desc: "Set a level requirement on a self-assignable role." args: - "5 SomeRole" +massban: + desc: "Bans multiple users at once. Specify a space separated list of IDs of users who you wish to ban." + args: + - "123123123 3333333333 444444444" masskill: desc: "Specify a new-line separated list of `userid reason`. You can use Username#discrim instead of UserId. Specified users will be banned from the current server, blacklisted from the bot, and have all of their flowers taken away." args: diff --git a/src/NadekoBot/data/strings/responses/responses.en-US.json b/src/NadekoBot/data/strings/responses/responses.en-US.json index 421b4a313..1c843d47f 100644 --- a/src/NadekoBot/data/strings/responses/responses.en-US.json +++ b/src/NadekoBot/data/strings/responses/responses.en-US.json @@ -889,6 +889,8 @@ "self_assign_not_level": "That self-assignable role requires at least server level {0}.", "invalid": "Invalid / Can't be found ({0})", "mass_kill_in_progress": "Mass Banning and Blacklisting of {0} users is in progress...", + "mass_ban_in_progress": "Banning {0} users...", + "mass_ban_completed": "Banned {0} users.", "mass_kill_completed": "Mass Banning and Blacklisting of {0} users is complete.", "failed_finding_novel": "Can't find that novel. Make sure you've typed the exact full name, and that it exists on novelupdates.com", "club_transfered": "Ownership of the club {0} has been transferred to {1}",