mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2024-10-02 20:13:13 +00:00
Added .massban
This commit is contained in:
parent
a5f9ac1540
commit
c12b41ddd1
5 changed files with 87 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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<string>();
|
||||
var banning = new HashSet<IGuildUser>();
|
||||
|
||||
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
|
||||
|
|
|
@ -1193,6 +1193,8 @@ crypto:
|
|||
rolelevelreq:
|
||||
- rolelevelreq
|
||||
- rlr
|
||||
massban:
|
||||
- massban
|
||||
masskill:
|
||||
- masskill
|
||||
pathofexile:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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}",
|
||||
|
|
Loading…
Reference in a new issue