From 06f93e44da958cdc731b0c31e15a3381e3dfa92b Mon Sep 17 00:00:00 2001 From: Daniel-I-Am Date: Tue, 1 Sep 2020 21:42:38 +0200 Subject: [PATCH] Improve formatting on output of the RankCheck command --- ChaosBot/Discord/Modules/Admin/RankCheck.cs | 46 +++++++++++++++------ 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/ChaosBot/Discord/Modules/Admin/RankCheck.cs b/ChaosBot/Discord/Modules/Admin/RankCheck.cs index 4ce07a1..f71d56d 100644 --- a/ChaosBot/Discord/Modules/Admin/RankCheck.cs +++ b/ChaosBot/Discord/Modules/Admin/RankCheck.cs @@ -27,8 +27,8 @@ namespace ChaosBot.Discord.Modules.Admin await Context.Channel.TriggerTypingAsync(); List rankedUsers = await GetRanksFromEndpoint(Context.Guild.Id); - - List embedContent = new List{new StringBuilder()}; + + Dictionary promotionLists = new Dictionary(); if (rankedUsers.Count(u => u.ShouldBeRole != null) > 0) { @@ -39,35 +39,55 @@ namespace ChaosBot.Discord.Modules.Admin // Skip users that shouldn't be upgraded if (rankedUser.ShouldBeRole == null) continue; if (rankedUser.ShouldBeRole == rankedUser.IngameRole) continue; - - if (embedContent.Last().Length >= 1800) - embedContent.Add(new StringBuilder()); - embedContent.Last().Append($"{rankedUser.IngameRole} {rankedUser.DisplayName}"); + string key = $"{rankedUser.IngameRole} Pending Promotion to {rankedUser.ShouldBeRole}"; + + if (!promotionLists.TryGetValue(key, out StringBuilder embedContent)) + { + embedContent = new StringBuilder(); + promotionLists.Add(key, embedContent); + } + + embedContent.Append($"{rankedUser.DisplayName}"); if (rankedUser.DiscordId != null) - embedContent.Last().Append($" [<@{rankedUser.DiscordId}>]"); - embedContent.Last().AppendLine($" -> {rankedUser.ShouldBeRole}"); + embedContent.Append($"linked to <@{rankedUser.DiscordId}>"); } catch (Exception ex) { LoggingFacade.Exception(ex); - embedContent.Last().AppendLine($"Something went wrong checking {rankedUser.DisplayName}"); + + 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}"); } } } else { - embedContent.Last().AppendLine("No new promotions found!"); + string key = "empty"; + if (!promotionLists.TryGetValue(key, out StringBuilder embedContent)) + { + embedContent = new StringBuilder(); + promotionLists.Add(key, embedContent); + } + + embedContent.AppendLine("No new promotions found!"); } - foreach (StringBuilder builder in embedContent) + foreach (KeyValuePair promotionList in promotionLists) { EmbedBuilder embedBuilder = new EmbedBuilder(); embedBuilder.Title = "Pending Promotions"; - embedBuilder.Description = builder.ToString(); + 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)