Fixed BanCommand not accepting IDs of non-guild users
Also slightly improved the equivalent code for KickCommand
This commit is contained in:
parent
1761980275
commit
2358a8eec4
3 changed files with 30 additions and 26 deletions
|
@ -3,7 +3,7 @@ using Discord.WebSocket;
|
|||
using Newtonsoft.Json.Linq;
|
||||
using Noikoio.RegexBot.ConfigItem;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Noikoio.RegexBot.Feature.ModTools
|
||||
|
@ -56,18 +56,19 @@ namespace Noikoio.RegexBot.Feature.ModTools
|
|||
}
|
||||
}
|
||||
|
||||
// Getting SocketGuildUser kick target (ensuring that it's the parameter)
|
||||
SocketGuildUser targetobj = null;
|
||||
if (UserMention.IsMatch(targetstr))
|
||||
{
|
||||
targetobj = msg.MentionedUsers.ElementAt(0) as SocketGuildUser;
|
||||
}
|
||||
else if (ulong.TryParse(targetstr, out var snowflake))
|
||||
{
|
||||
targetobj = g.GetUser(snowflake);
|
||||
}
|
||||
// Getting SocketGuildUser target
|
||||
Match m = UserMention.Match(targetstr);
|
||||
if (m.Success) targetstr = m.Groups["snowflake"].Value;
|
||||
|
||||
if (targetobj == null)
|
||||
SocketGuildUser targetobj = null;
|
||||
ulong targetuid;
|
||||
string targetdisp;
|
||||
if (ulong.TryParse(targetstr, out targetuid))
|
||||
{
|
||||
targetobj = g.GetUser(targetuid);
|
||||
targetdisp = (targetobj == null ? $"with ID {targetuid}" : targetobj.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
await SendUsageMessage(msg, ":x: **Unable to determine the target user.**");
|
||||
return;
|
||||
|
@ -76,8 +77,8 @@ namespace Noikoio.RegexBot.Feature.ModTools
|
|||
try
|
||||
{
|
||||
if (reason != null) reason = Uri.EscapeDataString(reason); // TODO remove when fixed in library
|
||||
await g.AddBanAsync(targetobj, _purgeDays, reason);
|
||||
await msg.Channel.SendMessageAsync($":white_check_mark: Banned user **{targetobj.ToString()}**.");
|
||||
await g.AddBanAsync(targetuid, _purgeDays, reason);
|
||||
await msg.Channel.SendMessageAsync($":white_check_mark: Banned user **{targetdisp}**.");
|
||||
}
|
||||
catch (Discord.Net.HttpException ex)
|
||||
{
|
||||
|
|
|
@ -38,23 +38,26 @@ namespace Noikoio.RegexBot.Feature.ModTools
|
|||
return;
|
||||
}
|
||||
|
||||
// Getting SocketGuildUser kick target (ensuring that it's the parameter)
|
||||
// Getting SocketGuildUser target
|
||||
Match m = UserMention.Match(targetstr);
|
||||
if (m.Success) targetstr = m.Groups["snowflake"].Value;
|
||||
|
||||
SocketGuildUser targetobj = null;
|
||||
if (UserMention.IsMatch(targetstr))
|
||||
{
|
||||
targetobj = msg.MentionedUsers.ElementAt(0) as SocketGuildUser;
|
||||
}
|
||||
else if (ulong.TryParse(targetstr, out var snowflake))
|
||||
if (ulong.TryParse(targetstr, out var snowflake))
|
||||
{
|
||||
targetobj = g.GetUser(snowflake);
|
||||
if (targetobj == null)
|
||||
{
|
||||
await SendUsageMessage(msg, ":x: **Unable to determine the target user.**");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (targetobj == null)
|
||||
else
|
||||
{
|
||||
await SendUsageMessage(msg, ":x: **Unable to determine the target user.**");
|
||||
await SendUsageMessage(msg, ":x: **The given target is not valid.**");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
if (reason != null) reason = Uri.EscapeDataString(reason); // TODO remove when fixed in library
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp1.1</TargetFramework>
|
||||
<RootNamespace>Noikoio.RegexBot</RootNamespace>
|
||||
<AssemblyVersion>1.1.2.0</AssemblyVersion>
|
||||
<AssemblyVersion>1.1.3.0</AssemblyVersion>
|
||||
<Description>Highly configurable Discord moderation bot</Description>
|
||||
<Authors>Noikoio</Authors>
|
||||
<Company />
|
||||
|
@ -26,4 +26,4 @@
|
|||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
</Project>
|
||||
|
|
Loading…
Reference in a new issue