From 9cdab68c64e9aa8718e43cc80e1a6e9c4243fd60 Mon Sep 17 00:00:00 2001 From: "Sean \"Solao Bajiuik\" Stoves" Date: Thu, 6 Aug 2020 20:24:15 -0400 Subject: [PATCH] Adding RankCheck command --- ChaosBot/Discord/Modules/Admin/RankCheck.cs | 110 ++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 ChaosBot/Discord/Modules/Admin/RankCheck.cs diff --git a/ChaosBot/Discord/Modules/Admin/RankCheck.cs b/ChaosBot/Discord/Modules/Admin/RankCheck.cs new file mode 100644 index 0000000..a2643ed --- /dev/null +++ b/ChaosBot/Discord/Modules/Admin/RankCheck.cs @@ -0,0 +1,110 @@ +using System; +using Discord; +using Discord.Commands; +using System.Threading.Tasks; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Reflection; +using System.Text; +using Antlr4.Runtime.Misc; +using ChaosBot.Discord.PreConditions; +using ChaosBot.Lodestone; +using Microsoft.AspNetCore.Http; +using Newtonsoft.Json; +using NLog; + +namespace ChaosBot.Discord.Modules.Admin +{ + public class RankCheck : ModuleBase + { + private static readonly ILogger _logger = Program.Logger; + + [Command("rankCheck")] + [Alias("rc")] + [CheckCommandPerm("Admin")] + public async Task rankCheck() + { + try + { + List ranks = await GetRank(); + + var sb = new StringBuilder(); + var embed = new EmbedBuilder(); + + embed.WithColor(new Color(255, 255, 0)); + embed.Title = $"Pending Promotions"; + sb.AppendLine(); + sb.AppendLine(); + + sb.AppendLine($"**Recruits Pending Promotion to Initiate**"); + if(ranks.FindAll(x => x.IngameRole == ERole.Recruit).Any()) + { + 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, $"linked to <@{lsID.DiscordId}>")); + } + } + else + sb.AppendLine($"None at this time."); + + sb.AppendLine(); + sb.AppendLine($"**Initiates Pending Promotion to Member**"); + if (ranks.FindAll(x => x.IngameRole == ERole.Initiate).Any()) + { + 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, $"linked to <@{lsID.DiscordId}>")); + } + } + else + sb.AppendLine($"None at this time."); + + sb.AppendLine(); + sb.AppendLine($"Report Generated by {Context.User.Mention} at {DateTime.Now.ToString("dddd, dd MMMM yyyy h:mm tt")}."); + + /* + * Add the string to the Embed + */ + embed.Description = sb.ToString(); + + /* + * Reply with the Embed created above + */ + await ReplyAsync(null, false, embed.Build()); + } + catch (Exception ex) + { + _logger.Error($"{MethodBase.GetCurrentMethod().ReflectedType.FullName}: Exception [{ex}] thrown, <[{ex.Message}]>."); + } + } + + public async Task> GetRank() + { + string response = null; + + try + { + using (var client = new HttpClient()) + { + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13; + + var result = await client.GetAsync("https://www.ffxivhelix.com/rapi/clogiclodestone/v1/users"); + result.EnsureSuccessStatusCode(); + + response = await result.Content.ReadAsStringAsync(); + } + } + catch (Exception ex) + { + _logger.Error( + $"{MethodBase.GetCurrentMethod().ReflectedType.FullName}: Exception [{ex}] thrown, <[{ex.Message}]>."); + } + + return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(JsonConvert.DeserializeObject(response).Data)); + } + } +} \ No newline at end of file