public string HandleLine(GameLogLine gameLogLine) { foreach (var name in gameLogLine.Cards) { if (HostRun == null || LeagueRunOpp == null) { return(null); } var InList = HostRun.ContainsCard(name) || LeagueRunOpp.ContainsCard(name) || BaseLegalityChecker.IsRearFace(name); if (!InList) { HostRun = LeagueRunOpp = null; match.Log("[League] Invalid Match"); return($"[sD][sR] {name} was not on a submitted league decklist. This is not a league match."); } } if (gameLogLine.Line.EndsWith("has lost the game due to inaction.")) { //DiscordService.SendLogToChannelAsync() } return(null); }
private async Task <bool> CheckForLeagueAsync() { if (match.Players.Length != 2) { return(false); } await Task.Delay(TimeSpan.FromSeconds(2)); // Sometimes PDBot gets into a game before one of the players. If this happens, they miss the message. var desc = match.Comments.ToLower(); var loud = desc.Contains("league"); try { HostRun = await DecksiteApi.GetRunAsync(match.Players[0]); } catch (Exception) { match.Log($"[League] Unable to reach PDM"); if (loud) { match.SendChat($"[sD][sR] Error contacting pennydreadfulmagic.com, Please @[Report] manually!"); } return(false); } if (HostRun == null) { match.Log($"[League] Host doesn't have active run"); if (loud) { match.SendChat($"[sD][sR] This is not a valid @[League] pairing!"); match.SendChat($"[sD][sR] {match.Players[0]}, you do not have an active run."); } return(false); } var opp = match.Players[1]; try { LeagueRunOpp = await DecksiteApi.GetRunAsync(opp); } catch (Exception) { match.Log($"[League] Unable to reach PDM"); if (loud) { match.SendChat($"[sD][sR] Error contacting pennydreadfulmagic.com, Please @[Report] manually!"); } return(false); } if (HostRun.CanPlay.Contains(opp, StringComparer.InvariantCultureIgnoreCase)) { if (loud) { match.SendChat($"[sD] Good luck in your @[League] match!"); } else { match.SendChat($"[sD] If this is a league match, don't forget to @[Report]!"); } match.Log($"[League] {HostRun} ({HostRun.Id}) vs {LeagueRunOpp} ({LeagueRunOpp.Id})"); if (File.Exists(Path.Combine("Updates", "urgent.txt"))) { match.SendChat("[sD] PDBot will be going down for scheduled maintenance. Please @[Report] this league match manually."); HostRun = null; } else if (!Features.PublishResults) { match.SendChat("[sD] Due to a Magic Online bug, PDBot is unable to tell which player is which. Please @[Report] this league match manually."); HostRun = null; } if (match.MinutesPerPlayer != 25) { match.SendChat($"[sAdept] This match has a {match.MinutesPerPlayer} timer. If you are not comfortable with this, say !notleague"); } return(true); } else { if (loud) { match.SendChat($"[sD][sR] This is not a valid @[League] pairing!"); } if (HostRun == null) { if (loud) { match.SendChat($"[sD][sR] {match.Players[0]}, you do not have an active run."); } match.Log($"[League] {match.Players[0]} doesn't have active run"); } else if (LeagueRunOpp == null) { if (loud) { match.SendChat($"[sD][sR] {opp}, you do not have an active run."); } match.Log($"[League] {opp} doesn't have active run"); } else { if (loud) { match.SendChat($"[sD][sR] You have both already played each other with these decks."); } match.Log($"[League] Duplicate Pairing: {HostRun} ({HostRun.Id}) vs {LeagueRunOpp} ({LeagueRunOpp.Id})"); } HostRun = null; LeagueRunOpp = null; return(false); } }