Add support for hackbans on massban

Closes #307

See merge request Kwoth/nadekobot!187
This commit is contained in:
Kwoth
2021-11-13 20:38:01 +00:00

View File

@@ -776,23 +776,32 @@ namespace NadekoBot.Modules.Administration
return; return;
var missing = new List<string>(); var missing = new List<string>();
var banning = new HashSet<IGuildUser>(); var banning = new HashSet<IUser>();
await ctx.Channel.TriggerTypingAsync(); await ctx.Channel.TriggerTypingAsync();
foreach (var userStr in userStrings) foreach (var userStr in userStrings)
{ {
if (ulong.TryParse(userStr, out var userId)) if (ulong.TryParse(userStr, out var userId))
{ {
var user = await ctx.Guild.GetUserAsync(userId) ?? IUser user = await ctx.Guild.GetUserAsync(userId) ??
await ((DiscordSocketClient)Context.Client).Rest.GetGuildUserAsync(ctx.Guild.Id, userId); await ((DiscordSocketClient)Context.Client).Rest.GetGuildUserAsync(ctx.Guild.Id, userId);
if (user is null) if (user is null)
{ {
missing.Add(userStr); // if IGuildUser is null, try to get IUser
continue; user = await ((DiscordSocketClient)Context.Client).Rest.GetUserAsync(userId);
// only add to missing if *still* null
if (user is null)
{
missing.Add(userStr);
continue;
}
} }
if (!await CheckRoleHierarchy(user)) //Hierachy checks only if the user is in the guild
if (user is IGuildUser gu && !await CheckRoleHierarchy(gu))
{ {
return; return;
} }
@@ -820,7 +829,7 @@ namespace NadekoBot.Modules.Administration
{ {
try try
{ {
await toBan.BanAsync(7); await ctx.Guild.AddBanAsync(toBan.Id, 7);
} }
catch (Exception ex) catch (Exception ex)
{ {