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); 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) 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}"; 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, new List<LodestoneRankedUser>());
promotionLists.Add(key, embedContent);
} }
embedContent.Append($"{rankedUser.DisplayName}"); if (rankedUserList == null)
if (rankedUser.DiscordId != null) {
embedContent.Append($"linked to <@{rankedUser.DiscordId}>"); promotionLists.Remove(key);
rankedUserList = new List<LodestoneRankedUser>();
promotionLists.Add(key, rankedUserList);
}
rankedUserList.Add(rankedUser);
} }
catch (Exception ex) catch (Exception ex)
{ {
LoggingFacade.Exception(ex); LoggingFacade.Exception(ex);
await ReplyAsync($"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}");
} }
} }
StringBuilder embedContentBuilder = new StringBuilder();
foreach (KeyValuePair<string, List<LodestoneRankedUser>> 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 else
{ {
string key = "empty"; embedBuilder.Description = "No new promotions found!";
if (!promotionLists.TryGetValue(key, out StringBuilder embedContent))
{
embedContent = new StringBuilder();
promotionLists.Add(key, embedContent);
}
embedContent.AppendLine("No new promotions found!");
} }
foreach (KeyValuePair<string, StringBuilder> promotionList in promotionLists) await ReplyAsync(null, false, embedBuilder.Build());
{
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) catch (Exception ex)
{ {
@ -111,6 +123,7 @@ namespace ChaosBot.Discord.Modules.Admin
response = await result.Content.ReadAsStringAsync(); response = await result.Content.ReadAsStringAsync();
// return new List<LodestoneRankedUser>();
return JsonConvert.DeserializeObject<LodestoneRankApi>(response).Data; return JsonConvert.DeserializeObject<LodestoneRankApi>(response).Data;
} }
catch (Exception ex) catch (Exception ex)