Fix rendering of RankCheck command

This commit is contained in:
Daniel_I_Am 2020-09-04 20:32:50 +02:00
parent ebbf2c858a
commit 5923b91f32
No known key found for this signature in database
GPG Key ID: 80C428FCC9743E84

View File

@ -28,7 +28,9 @@ namespace ChaosBot.Discord.Modules.Admin
List<LodestoneRankedUser> rankedUsers = await GetRanksFromEndpoint(Context.Guild.Id);
Dictionary<string, StringBuilder> promotionLists = new Dictionary<string, StringBuilder>();
Dictionary<string, List<LodestoneRankedUser>> promotionLists = new Dictionary<string, List<LodestoneRankedUser>>();
EmbedBuilder embedBuilder = new EmbedBuilder {Title = "Pending Promotions"};
if (rankedUsers.Count(u => u.ShouldBeRole != null) > 0)
{
@ -42,54 +44,64 @@ 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<LodestoneRankedUser> rankedUserList))
{
embedContent = new StringBuilder();
promotionLists.Add(key, embedContent);
promotionLists.Add(key, new List<LodestoneRankedUser>());
}
embedContent.Append($"{rankedUser.DisplayName}");
if (rankedUser.DiscordId != null)
embedContent.Append($"linked to <@{rankedUser.DiscordId}>");
if (rankedUserList == null)
{
promotionLists.Remove(key);
rankedUserList = new List<LodestoneRankedUser>();
promotionLists.Add(key, rankedUserList);
}
rankedUserList.Add(rankedUser);
}
catch (Exception ex)
{
LoggingFacade.Exception(ex);
await ReplyAsync($"Something went wrong checking {rankedUser.DisplayName}");
}
}
string key = "errors";
if (!promotionLists.TryGetValue(key, out StringBuilder embedContent))
StringBuilder embedContentBuilder = new StringBuilder();
foreach (KeyValuePair<string, List<LodestoneRankedUser>> promotionList in promotionLists)
{
embedContent = new StringBuilder();
promotionLists.Add(key, embedContent);
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);
}
embedContent.AppendLine($"Something went wrong checking {rankedUser.DisplayName}");
}
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);
embedBuilder.Description = "No new promotions found!";
}
embedContent.AppendLine("No new promotions found!");
}
foreach (KeyValuePair<string, StringBuilder> 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());
}
}
catch (Exception ex)
{
LoggingFacade.Exception(ex);
@ -111,6 +123,7 @@ namespace ChaosBot.Discord.Modules.Admin
response = await result.Content.ReadAsStringAsync();
// return new List<LodestoneRankedUser>();
return JsonConvert.DeserializeObject<LodestoneRankApi>(response).Data;
}
catch (Exception ex)