From affaf88425b095b1bb8fed75d4d78c1108fb94f9 Mon Sep 17 00:00:00 2001 From: Noi Date: Thu, 30 Sep 2021 13:47:25 -0700 Subject: [PATCH] Fix arbitrary ID banning not working under certain conditions --- .../Module/ModCommands/Commands/BanKick.cs | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/RegexBot/Module/ModCommands/Commands/BanKick.cs b/RegexBot/Module/ModCommands/Commands/BanKick.cs index aa7beaf..2727764 100644 --- a/RegexBot/Module/ModCommands/Commands/BanKick.cs +++ b/RegexBot/Module/ModCommands/Commands/BanKick.cs @@ -124,27 +124,31 @@ namespace Noikoio.RegexBot.Module.ModCommands.Commands return; } - // Hierarchy check - if ((msg.Author as SocketGuildUser).Hierarchy <= targetobj.Hierarchy) + // Checks for existing (found) users: + if (targetobj != null) { - // Block kick attempts if the invoking user is at or above the target in role hierarchy - await SendUsageMessageAsync(msg.Channel, ":x: You are not allowed to kick this user."); - return; + // Bot check + if (targetobj.IsBot) + { + await SendUsageMessageAsync(msg.Channel, ":x: I will not do that. Please kick bots manually."); + return; + } + // Hierarchy check + if ((msg.Author as SocketGuildUser).Hierarchy <= targetobj.Hierarchy) + { + // Block kick attempts if the invoking user is at or above the target in role hierarchy + await SendUsageMessageAsync(msg.Channel, ":x: You are not allowed to kick this user."); + return; + } } - // Bot check - if (targetobj.IsBot) - { - await SendUsageMessageAsync(msg.Channel, ":x: I will not do that. Please kick bots manually."); - return; - } - + // Send out message var notifyTask = SendNotificationMessage(targetobj, reason); // Do the action try { - string reasonlog = $"Invoked by {msg.Author.ToString()}."; + string reasonlog = $"Invoked by {msg.Author}."; if (reason != null) reasonlog += $" Reason: {reason}"; await notifyTask; #if !DEBUG