diff --git a/ChaosBot/Discord/Modules/Admin/RankCheck.cs b/ChaosBot/Discord/Modules/Admin/RankCheck.cs index f71d56d..22d7158 100644 --- a/ChaosBot/Discord/Modules/Admin/RankCheck.cs +++ b/ChaosBot/Discord/Modules/Admin/RankCheck.cs @@ -28,7 +28,9 @@ namespace ChaosBot.Discord.Modules.Admin List rankedUsers = await GetRanksFromEndpoint(Context.Guild.Id); - Dictionary promotionLists = new Dictionary(); + Dictionary> promotionLists = new Dictionary>(); + + EmbedBuilder embedBuilder = new EmbedBuilder {Title = "Pending Promotions"}; if (rankedUsers.Count(u => u.ShouldBeRole != null) > 0) { @@ -42,53 +44,63 @@ namespace ChaosBot.Discord.Modules.Admin string key = $"{rankedUser.IngameRole} Pending Promotion to {rankedUser.ShouldBeRole}"; - if (!promotionLists.TryGetValue(key, out StringBuilder embedContent)) + if (!promotionLists.TryGetValue(key, out List rankedUserList)) { - embedContent = new StringBuilder(); - promotionLists.Add(key, embedContent); + promotionLists.Add(key, new List()); } - embedContent.Append($"{rankedUser.DisplayName}"); - if (rankedUser.DiscordId != null) - embedContent.Append($"linked to <@{rankedUser.DiscordId}>"); + if (rankedUserList == null) + { + promotionLists.Remove(key); + rankedUserList = new List(); + promotionLists.Add(key, rankedUserList); + } + rankedUserList.Add(rankedUser); } catch (Exception ex) { LoggingFacade.Exception(ex); - - string key = "errors"; - if (!promotionLists.TryGetValue(key, out StringBuilder embedContent)) - { - embedContent = new StringBuilder(); - promotionLists.Add(key, embedContent); - } - - embedContent.AppendLine($"Something went wrong checking {rankedUser.DisplayName}"); + await ReplyAsync($"Something went wrong checking {rankedUser.DisplayName}"); } } + + StringBuilder embedContentBuilder = new StringBuilder(); + + foreach (KeyValuePair> promotionList in promotionLists) + { + embedContentBuilder.AppendLine($"**{promotionList.Key}**"); + foreach (LodestoneRankedUser rankedUser in promotionList.Value) + { + string line = $"{rankedUser.DisplayName}"; + string suffix = ""; + if (rankedUser.DiscordId != null) + suffix = $", linked to <@{rankedUser.DiscordId}>"; + embedContentBuilder.AppendLine(line+suffix); + } + + embedContentBuilder.AppendLine(); + } + + string timezoneAbbreviation = string + .Join("", TimeZoneInfo.Local.DisplayName + .Split(' ') + .Select( + (t, i) => + { + if (i == 0) + return t + ' '; + return t.Substring(0, 1); + })); + embedContentBuilder.AppendLine($"Reported Generated by <@{Context.User.Id}> at {DateTime.Now} {timezoneAbbreviation}"); + + embedBuilder.Description = embedContentBuilder.ToString(); } else { - string key = "empty"; - if (!promotionLists.TryGetValue(key, out StringBuilder embedContent)) - { - embedContent = new StringBuilder(); - promotionLists.Add(key, embedContent); - } - - embedContent.AppendLine("No new promotions found!"); + embedBuilder.Description = "No new promotions found!"; } - foreach (KeyValuePair promotionList in promotionLists) - { - EmbedBuilder embedBuilder = new EmbedBuilder(); - - embedBuilder.Title = "Pending Promotions"; - promotionList.Value.Insert(0, $"**{promotionList.Key}**\n"); - embedBuilder.Description = promotionList.Value.ToString(); - - await ReplyAsync(null, false, embedBuilder.Build()); - } + await ReplyAsync(null, false, embedBuilder.Build()); } catch (Exception ex) { @@ -111,6 +123,7 @@ namespace ChaosBot.Discord.Modules.Admin response = await result.Content.ReadAsStringAsync(); + // return new List(); return JsonConvert.DeserializeObject(response).Data; } catch (Exception ex)