public async Task checkRun() { var src = Program.Src; var conUser = Context.User; if (conUser is SocketGuildUser user) { // Check if the user has the required role if (!user.Roles.Any(r => r.Name == "Moderator" && !user.Roles.Any(r => r.Name == "Verifier"))) { await ReplyAsync("You don't have the permission for this action."); return; } if (!BotHelper.isConnectionAllowed()) { await ReplyAsync("Error, couldn't log to SRC. Are you sure the token is valid? Perhaps the site is down or laggy."); return; } await ReplyAsync("Dm'ed you the runs awaiting verification. (If any.)"); string gameID = Program.Sadx.ID; IEnumerable <Run> runsList = src.Runs.GetRuns(gameId: gameID, status: RunStatusType.New, embeds: new RunEmbeds(embedPlayers: true)); //RunEmbeds True = no rate limit to get player name. foreach (Run curRun in runsList) { string catName = curRun.Category.Name; string ILCharaName = ""; string bgID = ""; string resultDay = BotHelper.getSubmittedDay(curRun); if (curRun.Level != null) { ILCharaName = " (" + catName + ")"; catName = curRun.Level.Name; } string runTime = curRun.Times.PrimaryISO.Value.ToString(Program.timeFormat); if (curRun.Times.PrimaryISO.Value.Hours != 0) { runTime = curRun.Times.PrimaryISO.Value.ToString(Program.timeFormatWithHours); } string runLink = curRun.WebLink.ToString(); string bgURL = "https://i.imgur.com/"; string ext = ".jpg"; var builder = new EmbedBuilder() .WithThumbnailUrl(bgURL + bgID + ext) .WithTitle(catName + ILCharaName + " run by " + curRun.Player.Name) .WithDescription("Time: " + runTime + "\n" + runLink + "\n" + "Submitted " + resultDay) .WithColor(new Color(33, 176, 252)); var emb = builder.Build(); await Context.User.SendMessageAsync(null, false, emb); } } }
public static async Task ListNewRuns(string gameID, IMessageChannel curChan) { List <string> newRunList = new List <string>(); IEnumerable <Run> runsList = Program.Src.Runs.GetRuns(gameId: gameID, status: RunStatusType.New, embeds: new RunEmbeds(embedPlayers: true)); //RunEmbeds True = no rate limit to get player name. bool listEdited = false; foreach (Run curRun in runsList) { string catName = curRun.Category.Name; string ILCharaName = ""; string bgID = BotHelper.getBGID(curRun.Category.Name); string resultDay = BotHelper.getSubmittedDay(curRun); newRunList.Add(curRun.ID); if (curRun.Level != null) { bgID = BotHelper.getBGID(curRun.Level.Name); string curChara = catName; ILCharaName = " (" + curChara + ")"; catName = curRun.Level.Name; } bgID += ".jpg"; if (isRunListed(curRun.ID, gameID)) { continue; } else { listEdited = true; string runTime = curRun.Times.PrimaryISO.Value.ToString(Program.timeFormat); if (curRun.Times.PrimaryISO.Value.Hours != 0) { runTime = curRun.Times.PrimaryISO.Value.ToString(Program.timeFormatWithHours); } string runLink = curRun.WebLink.ToString(); string bgURL = "https://i.imgur.com/"; var builder = new EmbedBuilder() .WithThumbnailUrl(bgURL + bgID) .WithTitle(catName + ILCharaName + " run by " + curRun.Player.Name) .WithDescription("Time: " + runTime + "\n" + runLink + "\n" + "Submitted " + resultDay) .WithColor(new Color(33, 176, 252)); var emb = builder.Build(); await curChan.SendMessageAsync(null, false, emb); } } if (listEdited) //Update the json file with the new updated list. { if (gameID == BotHelper.getCEID) { Program.runCEList = newRunList; var jsonCE = JsonSerializer.Serialize(Program.runCEList); File.WriteAllText("runCEList.json", jsonCE + Environment.NewLine); Console.WriteLine("Updated Category Extension run list and json file."); } else { Program.runList = newRunList; var json = JsonSerializer.Serialize(Program.runList); File.WriteAllText("runList.json", json + Environment.NewLine); Console.WriteLine("Updated run list and json file."); } } }