From 5a681a51942b2335bf0010c81c21daf51a09473b Mon Sep 17 00:00:00 2001 From: Alan Beatty Date: Sat, 13 Nov 2021 20:38:01 +0000 Subject: [PATCH] Add support for hackbans on massban Closes #307 --- .../Administration/UserPunishCommands.cs | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/NadekoBot/Modules/Administration/UserPunishCommands.cs b/src/NadekoBot/Modules/Administration/UserPunishCommands.cs index e316777c5..fa3041788 100644 --- a/src/NadekoBot/Modules/Administration/UserPunishCommands.cs +++ b/src/NadekoBot/Modules/Administration/UserPunishCommands.cs @@ -776,23 +776,32 @@ namespace NadekoBot.Modules.Administration return; var missing = new List(); - var banning = new HashSet(); + 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) ?? + IUser 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 IGuildUser is null, try to get IUser + 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; } @@ -820,7 +829,7 @@ namespace NadekoBot.Modules.Administration { try { - await toBan.BanAsync(7); + await ctx.Guild.AddBanAsync(toBan.Id, 7); } catch (Exception ex) {