public async Task Records(CommandContext ctx, string level, string character, string version) { try { bool gotLvl = SRB2Enums.levelsID.TryGetValue(level.ToUpper(), out SRB2Level srb2Level); bool gotCatFg = SRB2Enums.fgCategoriesID.TryGetValue(character.ToLower(), out string categoryFgID); bool gotCat = SRB2Enums.categoriesID.TryGetValue(character.ToLower(), out string categoryID); bool nights = false; if (gotLvl) { int mapNumber = SRB2Level.GetMapNumber(srb2Level.MapName); if (mapNumber > 49 && mapNumber < 74) { categoryID = "xd1g1j4d"; gotCat = true; nights = true; } else if (!gotCat) { categoryID = "xd1g1j4d"; gotCat = true; } } if (!gotCatFg) { gotCatFg = SRB2Enums.fgCategoriesID.TryGetValue(level.ToLower(), out categoryFgID); } if (!gotLvl && gotCatFg) { string goal; if (categoryFgID == "9d8pmg3k") { goal = SRB2Enums.GetGoal(categoryFgID); } else { goal = SRB2Enums.GetGoal(level); } if (goal != "notfound") { bool gotVer = false; string originalVer = ""; string processedVer = ""; if (categoryFgID == "9d8pmg3k" || categoryFgID == "9d8pm0qk") { originalVer = string.Join(" ", character + version).ToLower(); gotVer = SRB2Enums.versions.TryGetValue(originalVer, out processedVer); } else { originalVer = version; gotVer = SRB2Enums.versions.TryGetValue(originalVer, out processedVer); } if (!gotVer && originalVer != "") { throw new Exception("Wrong / Missing version"); } Leaderboard leaderboard = FullGameLeaderboard(goal, categoryFgID, processedVer, originalVer); DiscordEmbedBuilder.EmbedFooter embedFooter = new DiscordEmbedBuilder.EmbedFooter(); DiscordEmbedBuilder.EmbedThumbnail thumbnailUrl = new DiscordEmbedBuilder.EmbedThumbnail(); int timeSinceStarted = (DateTime.Now - Program.startedAt).Minutes; embedFooter.Text = $"Last updated {timeSinceStarted} minute(s) ago"; Random r = new Random(); int footerImgNum = r.Next(1, 21); embedFooter.IconUrl = $"http://77.68.95.193/footerimgs/{footerImgNum}.png"; var records = new DiscordEmbedBuilder { Title = $"{goal} | ", Thumbnail = thumbnailUrl, Footer = embedFooter, Url = leaderboard.WebLink.AbsoluteUri }; CharacterColor(leaderboard, records); if (categoryFgID == "9d8pmg3k" || categoryFgID == "9d8pm0qk") { string formattedCat = leaderboard.Category.Name.Replace(" ", string.Empty); string url = $"http://77.68.95.193/fgicons/{formattedCat}.png"; thumbnailUrl.Url = url; records.Title += finalVersion; } else { string formattedGoal = goal.Replace(" ", string.Empty).Replace("%", string.Empty); string url = $"http://77.68.95.193/fgicons/{formattedGoal}.png"; thumbnailUrl.Url = url; records.Title += leaderboard.Category.Name + " | " + finalVersion; } string displayedTimeFormat = Program.timeFormat; if (leaderboard.Records.Count != 0) { if (leaderboard.Records.Any(x => x.Times.PrimaryISO.Value.Hours != 0)) { displayedTimeFormat = Program.timeFormatWithHours; } } for (int i = 0; i < leaderboard.Records.Count(); i++) { string playerName = leaderboard.Records[i].Player.Name; string runTime = leaderboard.Records[i].Times.PrimaryISO.Value.ToString(displayedTimeFormat); records.AddField($"{i + 1}. {playerName} | {runTime}", leaderboard.Records[i].WebLink.AbsoluteUri); } await ctx.RespondAsync(embed : records); } } else if (gotCat == true && gotLvl == true) { Leaderboard leaderboard; leaderboard = Program.srcClient.Leaderboards.GetLeaderboardForLevel( Program.srb2Game.ID, srb2Level.SrcID, categoryID, 5 ); DiscordEmbedBuilder.EmbedThumbnail thumbnailUrl = new DiscordEmbedBuilder.EmbedThumbnail(); thumbnailUrl.Url = "http://77.68.95.193/lvlicons/" + srb2Level.FullName.Replace(" ", string.Empty) + ".png"; DiscordEmbedBuilder.EmbedFooter embedFooter = new DiscordEmbedBuilder.EmbedFooter(); int timeSinceStarted = (DateTime.Now - Program.startedAt).Minutes; embedFooter.Text = $"Last updated {timeSinceStarted} minute(s) ago"; Random r = new Random(); int footerImgNum = r.Next(1, 21); embedFooter.IconUrl = $"http://77.68.95.193/footerimgs/{footerImgNum}.png"; var records = new DiscordEmbedBuilder { Title = srb2Level.FullName, Thumbnail = thumbnailUrl, Footer = embedFooter, Url = leaderboard.WebLink.AbsoluteUri }; CharacterColor(leaderboard, records); switch (nights) { case true: records.Color = DiscordColor.Magenta; break; case false: records.Title += " | " + leaderboard.Category.Name; break; } for (int i = 0; i < leaderboard.Records.Count(); i++) { string playerName = leaderboard.Records[i].Player.Name; string runTime = leaderboard.Records[i].Times.GameTimeISO.Value.ToString(Program.timeFormat); records.AddField($"{i + 1}. {playerName} | {runTime}", leaderboard.Records[i].WebLink.AbsoluteUri); } await ctx.RespondAsync(embed : records); } if (!gotLvl && !gotCatFg) { throw new Exception("Wrong / Missing parameter: Level (ILs) / Category (Full-game)"); } } catch (Exception e) { await ctx.RespondAsync("Type !help for more info"); /* await ctx.RespondAsync(e.Source); * await ctx.RespondAsync(e.Message); * await ctx.RespondAsync(e.StackTrace); */ } }
public async Task FgRecords(CommandContext ctx, string category, string character, string version) { try { bool gotCatFg = SRB2Enums.fgCategoriesID.TryGetValue(character.ToLower(), out string categoryFgID); //checking for the character to get the ID off of it if (!gotCatFg) { if (!SRB2Enums.fgCategoriesID.TryGetValue(category.ToLower(), out categoryFgID)) { categoryFgID = "ndx46012"; } // checking for all emblems / srb1 (since they're as the first argument when typing the command), if not defaulting to sonic } string goal; if (categoryFgID == "9d8pmg3k") //all emblems { goal = SRB2Enums.GetGoal(categoryFgID); } else //everything else { goal = SRB2Enums.GetGoal(category); } bool gotVer = false; string originalVer = ""; string processedVer = ""; if (categoryFgID == "9d8pmg3k" || categoryFgID == "9d8pm0qk") { originalVer = string.Join(" ", character + version).ToLower(); gotVer = SRB2Enums.versions.TryGetValue(originalVer, out processedVer); } else { originalVer = version; gotVer = SRB2Enums.versions.TryGetValue(originalVer, out processedVer); } if (!gotVer && originalVer != "") { throw new ParsingException("Wrong / Missing version"); } Leaderboard leaderboard = FullGameLeaderboard(goal, categoryFgID, processedVer, originalVer); DiscordEmbedBuilder.EmbedFooter embedFooter = new DiscordEmbedBuilder.EmbedFooter(); DiscordEmbedBuilder.EmbedThumbnail thumbnailUrl = new DiscordEmbedBuilder.EmbedThumbnail(); embedFooter.Text = Program.s.RandomStat(); Random r = new Random(); int footerImgNum = r.Next(1, 21); embedFooter.IconUrl = $"https://roborecords.org/footerimgs/{footerImgNum}.png"; var records = new DiscordEmbedBuilder { Title = $"{goal} | ", Thumbnail = thumbnailUrl, Footer = embedFooter, Url = leaderboard.WebLink.AbsoluteUri, Color = CharacterColor(leaderboard), }; if (categoryFgID == "9d8pmg3k" || categoryFgID == "9d8pm0qk") { string formattedCat = leaderboard.Category.Name.Replace(" ", string.Empty); string url = $"https://roborecords.org/fgicons/{formattedCat}.png"; thumbnailUrl.Url = url; records.Title += finalVersion; } else { string formattedGoal = goal.Replace(" ", string.Empty).Replace("%", string.Empty); string url = $"https://roborecords.org/fgicons/{formattedGoal}.png"; thumbnailUrl.Url = url; records.Title += leaderboard.Category.Name + " | " + finalVersion; } string displayedTimeFormat = Program.timeFormatWithMinutes; if (leaderboard.Records.Count != 0) { if (leaderboard.Records.Any(x => x.Times.PrimaryISO.Value.Hours != 0)) { displayedTimeFormat = Program.timeFormatWithHours; } } for (int i = 0; i < leaderboard.Records.Count(); i++) { Record currentRecord = leaderboard.Records[i]; string playerName = currentRecord.Player.Name; string runTime = currentRecord.Times.PrimaryISO.Value.ToString(displayedTimeFormat).TrimStart(new Char[] { '0' }); records.AddField($"{i + 1}. {playerName} | {runTime}", "Submitted on " + currentRecord.DateSubmitted.Value.ToString("d") + ", " + DSharpPlus.Formatter.MaskedUrl("Link", currentRecord.WebLink, "Submission Link") ); } await ctx.RespondAsync(embed : records); } catch (ParsingException p) { await ctx.RespondAsync(p.Message); await ctx.RespondAsync("Type !help for more info"); } catch (Exception e) { await ctx.RespondAsync($"Internal Error \n{e.Message} \n{e.Source} \n{e.StackTrace}"); } }