Updating RankCheck to utilize either Web API discord Linking or Discord App Linking

This commit is contained in:
Sean "Solao Bajiuik" Stoves 2020-08-06 23:28:34 -04:00
parent 7d31e5a217
commit ae70fba075

View File

@ -11,6 +11,7 @@ using System.Text;
using Antlr4.Runtime.Misc;
using ChaosBot.Discord.PreConditions;
using ChaosBot.Lodestone;
using ChaosBot.Models;
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;
using NLog;
@ -46,7 +47,30 @@ namespace ChaosBot.Discord.Modules.Admin
foreach (var lsID in ranks.FindAll(x => x.IngameRole == ERole.Recruit))
{
if ((lsID.ShouldBeRole != lsID.IngameRole) && (lsID.ShouldBeRole != null))
sb.AppendLine(string.Format("{0} {1}", lsID.DisplayName, (lsID.DiscordId != null ? $"linked to <@{lsID.DiscordId}>)" : "")));
{
if(lsID.DiscordId != null)
sb.AppendLine(string.Format("{0}{1}", lsID.DisplayName, (lsID.DiscordId != null ? $", linked to <@{lsID.DiscordId}>)" : "")));
else
{
ulong lodeId = Convert.ToUInt64(lsID.LodestoneId);
using (ChaosbotContext dbContext = new ChaosbotContext())
{
IQueryable<LodestoneCharacter> ctxlsChars = dbContext.LodestoneCharacter;
List<LodestoneCharacter> lsChar = ctxlsChars
.Where(x => x.DiscordGuildId.Equals(Context.Guild.Id))
.Where(x => x.LodestoneId.Equals(lodeId)).ToList();
if (lsChar.Any())
{
sb.AppendLine(string.Format("{0}{1}", lsID.DisplayName, $", linked to <@{lsChar.First().DiscordUserId.ToString()}>"));
}
else
{
sb.AppendLine(string.Format("{0}", lsID.DisplayName));
}
}
}
}
}
}
else
@ -59,7 +83,30 @@ namespace ChaosBot.Discord.Modules.Admin
foreach (var lsID in ranks.FindAll(x => x.IngameRole == ERole.Initiate))
{
if ((lsID.ShouldBeRole != lsID.IngameRole) && (lsID.ShouldBeRole != null))
sb.AppendLine(string.Format("{0} {1}", lsID.DisplayName, (lsID.DiscordId != null ? $"linked to <@{lsID.DiscordId}>)" : "")));
{
if(lsID.DiscordId != null)
sb.AppendLine(string.Format("{0}{1}", lsID.DisplayName, (lsID.DiscordId != null ? $", linked to <@{lsID.DiscordId}>)" : "")));
else
{
ulong lodeId = Convert.ToUInt64(lsID.LodestoneId);
using (ChaosbotContext dbContext = new ChaosbotContext())
{
IQueryable<LodestoneCharacter> ctxlsChars = dbContext.LodestoneCharacter;
List<LodestoneCharacter> lsChar = ctxlsChars
.Where(x => x.DiscordGuildId.Equals(Context.Guild.Id))
.Where(x => x.LodestoneId.Equals(lodeId)).ToList();
if (lsChar.Any())
{
sb.AppendLine(string.Format("{0}{1}", lsID.DisplayName, $", linked to <@{lsChar.First().DiscordUserId.ToString()}>"));
}
else
{
sb.AppendLine(string.Format("{0}", lsID.DisplayName));
}
}
}
}
}
}
else