Fix arbitrary ID banning not working under certain conditions

This commit is contained in:
Noi 2021-09-30 13:47:25 -07:00
parent f16628a44e
commit affaf88425

View file

@ -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