mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
Added .massban
This commit is contained in:
@@ -4,6 +4,10 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added `.massban` to ban multiple people at once. 30 second cooldown
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Ban `.warnp` will now prune user's messages
|
- Ban `.warnp` will now prune user's messages
|
||||||
|
@@ -9,9 +9,11 @@ using NadekoBot.Services.Database.Models;
|
|||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
using NadekoBot.Modules.Administration.Services;
|
using NadekoBot.Modules.Administration.Services;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using NadekoBot.Modules.Permissions.Services;
|
using NadekoBot.Modules.Permissions.Services;
|
||||||
|
using NadekoBot.Modules.Searches.Common;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Administration
|
namespace NadekoBot.Modules.Administration
|
||||||
@@ -763,6 +765,78 @@ namespace NadekoBot.Modules.Administration
|
|||||||
.ConfigureAwait(false);
|
.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]
|
[NadekoCommand, Aliases]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[UserPerm(GuildPerm.BanMembers)]
|
[UserPerm(GuildPerm.BanMembers)]
|
||||||
@@ -783,7 +857,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
var banningMessageTask = ctx.Channel.EmbedAsync(_eb.Create()
|
var banningMessageTask = ctx.Channel.EmbedAsync(_eb.Create()
|
||||||
.WithDescription(GetText(strs.mass_kill_in_progress(bans.Count())))
|
.WithDescription(GetText(strs.mass_kill_in_progress(bans.Count())))
|
||||||
.AddField(GetText(strs.invalid(missing)), missStr)
|
.AddField(GetText(strs.invalid(missing)), missStr)
|
||||||
.WithOkColor());
|
.WithPendingColor());
|
||||||
|
|
||||||
//do the banning
|
//do the banning
|
||||||
await Task.WhenAll(bans
|
await Task.WhenAll(bans
|
||||||
|
@@ -1193,6 +1193,8 @@ crypto:
|
|||||||
rolelevelreq:
|
rolelevelreq:
|
||||||
- rolelevelreq
|
- rolelevelreq
|
||||||
- rlr
|
- rlr
|
||||||
|
massban:
|
||||||
|
- massban
|
||||||
masskill:
|
masskill:
|
||||||
- masskill
|
- masskill
|
||||||
pathofexile:
|
pathofexile:
|
||||||
|
@@ -2010,6 +2010,10 @@ rolelevelreq:
|
|||||||
desc: "Set a level requirement on a self-assignable role."
|
desc: "Set a level requirement on a self-assignable role."
|
||||||
args:
|
args:
|
||||||
- "5 SomeRole"
|
- "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:
|
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."
|
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:
|
args:
|
||||||
|
@@ -889,6 +889,8 @@
|
|||||||
"self_assign_not_level": "That self-assignable role requires at least server level {0}.",
|
"self_assign_not_level": "That self-assignable role requires at least server level {0}.",
|
||||||
"invalid": "Invalid / Can't be found ({0})",
|
"invalid": "Invalid / Can't be found ({0})",
|
||||||
"mass_kill_in_progress": "Mass Banning and Blacklisting of {0} users is in progress...",
|
"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.",
|
"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",
|
"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}",
|
"club_transfered": "Ownership of the club {0} has been transferred to {1}",
|
||||||
|
Reference in New Issue
Block a user