Improve formatting on output of the RankCheck command

This commit is contained in:
Daniel_I_Am 2020-09-01 21:42:38 +02:00
parent f48fd77c77
commit 06f93e44da
No known key found for this signature in database
GPG Key ID: 80C428FCC9743E84

View File

@ -28,7 +28,7 @@ namespace ChaosBot.Discord.Modules.Admin
List<LodestoneRankedUser> rankedUsers = await GetRanksFromEndpoint(Context.Guild.Id);
List<StringBuilder> embedContent = new List<StringBuilder>{new StringBuilder()};
Dictionary<string, StringBuilder> promotionLists = new Dictionary<string, StringBuilder>();
if (rankedUsers.Count(u => u.ShouldBeRole != null) > 0)
{
@ -40,32 +40,52 @@ namespace ChaosBot.Discord.Modules.Admin
if (rankedUser.ShouldBeRole == null) continue;
if (rankedUser.ShouldBeRole == rankedUser.IngameRole) continue;
if (embedContent.Last().Length >= 1800)
embedContent.Add(new StringBuilder());
string key = $"{rankedUser.IngameRole} Pending Promotion to {rankedUser.ShouldBeRole}";
embedContent.Last().Append($"{rankedUser.IngameRole} {rankedUser.DisplayName}");
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<string, StringBuilder> 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());
}