Adding cache lookup to ban/kick parameter

This commit is contained in:
Noikoio 2018-01-19 00:23:54 -08:00
parent b8abc50703
commit 6953bc8ed3

View file

@ -3,6 +3,7 @@ using Discord.WebSocket;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using Noikoio.RegexBot.ConfigItem; using Noikoio.RegexBot.ConfigItem;
using System; using System;
using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -82,22 +83,21 @@ namespace Noikoio.RegexBot.Module.ModTools.Commands
} }
// Getting SocketGuildUser target // Getting SocketGuildUser target
SocketGuildUser targetobj = null;
// Extract snowflake value from mention (if a mention was given)
Match m = UserMention.Match(targetstr); Match m = UserMention.Match(targetstr);
if (m.Success) targetstr = m.Groups["snowflake"].Value; if (m.Success) targetstr = m.Groups["snowflake"].Value;
SocketGuildUser targetobj = null; var qres = (await EntityCache.EntityCache.QueryAsync(g.Id, targetstr)).FirstOrDefault();
ulong targetuid; if (qres == null)
string targetdisp;
if (ulong.TryParse(targetstr, out targetuid))
{
targetobj = g.GetUser(targetuid);
targetdisp = (targetobj == null ? $"ID {targetuid}" : targetobj.ToString());
}
else
{ {
await SendUsageMessage(msg, ":x: **Unable to determine the target user.**"); await SendUsageMessage(msg, ":x: **Unable to determine the target user.**");
return; return;
} }
ulong targetuid = qres.UserId;
targetobj = g.GetUser(targetuid);
string targetdisp = targetobj?.ToString() ?? $"ID {targetuid}";
if (_mode == CommandMode.Kick && targetobj == null) if (_mode == CommandMode.Kick && targetobj == null)
{ {