Fix rendering of RankCheck command
This commit is contained in:
parent
ebbf2c858a
commit
5923b91f32
@ -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,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<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);
|
||||
|
||||
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<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
|
||||
{
|
||||
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<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());
|
||||
}
|
||||
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<LodestoneRankedUser>();
|
||||
return JsonConvert.DeserializeObject<LodestoneRankApi>(response).Data;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user