public bool ShouldJoin(IMatch match) { if (match.Format == MagicFormat.PennyDreadful) { var rotation = DecksiteApi.GetCachedRotationAsync().GetAwaiter().GetResult(); var diff = TimeSpan.FromSeconds(rotation.Diff); if (diff.TotalHours < 24) { if (File.Exists("suppress_hype.txt")) { return(false); } return(true); } if (File.Exists("suppress_hype.txt")) { try { File.Delete("suppress_hype.txt"); } catch (IOException) { Console.WriteLine("[Error] Could not delete suppress_hype.txt?"); } } } return(false); }
public async Task RetireAsync() { var person = await API.DecksiteApi.GetPersonAsync(Context.User.Id.ToString()); if (string.IsNullOrEmpty(person.Name)) { await ReplyAsync("I don't know who you are. Please message me on MTGO, or https://pennydreadfulmagic.com/link your account first."); return; } var run = await DecksiteApi.GetRunAsync(person.Name); if (run == null) { await ReplyAsync($"You do not have an active deck in {DecksiteApi.CurrentLeagueName()}."); return; } var res = await run.RetireAsync(); if (res) { await ReplyAsync($"Your deck {run.Name} has been retired from the {run.CompetitionName}"); } else { await ReplyAsync($"Unable to retire your deck. Please message Katelyn on discord."); } }
public async Task <string> RunAsync(string user, IMatch game, string[] args) { DecksiteApi.Deck run; try { run = await DecksiteApi.GetRunAsync(user); } catch (WebException) { return("Error contacting PDM website."); } if (run == null) { return($"You do not have an active deck in {DecksiteApi.CurrentLeagueName()}."); } var res = await run.RetireAsync(); if (res) { return($"Your deck {run.Name} has been retired from the {run.CompetitionName}"); } else { return($"Unable to retire your deck. Please message Katelyn on discord."); } }
public async void ProcessWinner(string winner, int gameID) { match.Winners.GetRecordData(out var first, out var record); if (first.Wins == 2 && HostRun != null && LeagueRunOpp != null) { var WinningRun = HostRun.Person.Equals(winner, StringComparison.InvariantCultureIgnoreCase) ? HostRun : LeagueRunOpp; var LosingRun = (new DecksiteApi.Deck[] { HostRun, LeagueRunOpp }).Single(d => d != WinningRun); if (Features.PublishResults && await DecksiteApi.UploadResultsAsync(WinningRun, LosingRun, record, match.MatchID)) { await DiscordService.SendToLeagueAsync($":trophy: {WinningRun.Person} {record} {LosingRun.Person}"); } else { try { var winnerMention = await DiscordFunctions.MentionOrElseNameAsync(WinningRun.Person); var losingMention = await DiscordFunctions.MentionOrElseNameAsync(LosingRun.Person); await DiscordService.SendToLeagueAsync($":trophy: {winnerMention} {record} {losingMention} (Please verify and report manually)"); } catch (Exception c) { await DiscordService.SendToLeagueAsync($":trophy: {WinningRun.Person} {record} {LosingRun.Person} (Please verify and report manually)"); Console.WriteLine(c); await DiscordService.SendToTestAsync(c.ToString()); } } } }
public static async Task <ulong?> DiscordIDAsync(string username) { if (MtgoToDiscordMapping.ContainsKey(username)) { return(MtgoToDiscordMapping[username]); } var person = await DecksiteApi.GetPersonAsync(username); return(MtgoToDiscordMapping[username] = person.discord_id); }
public async Task CheckPopularCards() { var cards = await DecksiteApi.PopularCardsAsync(); Assert.IsNotEmpty(cards); var first = cards.First(); Assert.IsNotEmpty(first.name); foreach (var item in cards) { Assert.IsNotNull(item.id); } }
public Task <IGameObserver> GetInstanceForMatchAsync(IMatch match) { if (ShouldJoin(match)) { Task.Factory.StartNew(async() => { await Task.Delay(TimeSpan.FromSeconds(2)); var rotation = await DecksiteApi.GetRotationAsync(); match.SendChat($"Penny Dreadful rotates in {rotation.FriendlyDiff}! Get hyped!"); }).GetAwaiter(); return(Task.FromResult <IGameObserver>(this)); } return(Task.FromResult <IGameObserver>(null)); }
public async Task <string> RunAsync(string player, IMatch game, string[] args) { DecksiteApi.Deck run; try { run = await DecksiteApi.GetRunAsync(player); } catch (WebException) { return("Error contacting PDM website."); } if (run == null) { return($"You do not have an active deck in {DecksiteApi.CurrentLeagueName()}."); } return($"Your deck '{run.Name}' is currently {run.Wins}-{run.Losses}"); }
public async Task EveryMinuteAsync() { foreach (var file in Directory.EnumerateFiles("Logs")) { var age = DateTime.Now.Subtract(File.GetLastWriteTime(file)); if (age.TotalMinutes < 60) { continue; } var id = int.Parse(Path.GetFileNameWithoutExtension(file)); if (await DecksiteApi.LogUploadedAsync(id)) { var destFileName = Path.Combine("Logs", "Archive", id + ".txt"); if (File.Exists(destFileName)) { Console.WriteLine($"Reuploading {id} to logsite..."); File.Delete(destFileName); await DecksiteApi.UploadLogAsync(id); return; } Console.WriteLine($"Archiving log for {id}..."); File.Move(file, destFileName); return; } try { Console.WriteLine($"Uploading {id} to logsite..."); await DecksiteApi.UploadLogAsync(id); return; } catch (UriFormatException) { // This log is too long. Console.WriteLine($"Upload failed."); var destFileName = Path.Combine("Logs", "Failed", id + ".txt"); File.Move(file, destFileName); } } }
private static async Task SendLogToChannelAsync(ISocketMessageChannel channel, string id) { var file = Path.Combine("Logs", id + ".txt"); if (!File.Exists(file)) { file = Path.Combine("Logs", "Archive", id + ".txt"); } if (!File.Exists(file)) { file = Path.Combine("Logs", "Failed", id + ".txt"); } if (File.Exists(file)) { await channel.TriggerTypingAsync(); try { await DecksiteApi.UploadLogAsync(int.Parse(id)); await channel.SendMessageAsync($"https://logs.pennydreadfulmagic.com/match/{id}/"); } catch (Exception e) { var contents = File.ReadAllLines(file); var caption = $"Format={contents[0]}, Comment=\"{contents[1]}\", Players=[{contents[3]}]"; await channel.SendFileAsync(file, caption); Console.WriteLine($"Couldn't upload to logsite, {e}"); } } else { await channel.TriggerTypingAsync(); await channel.SendMessageAsync($"Could not find log for MatchID {id}"); } }
public async Task TestPersonApi(string name) { var person = await DecksiteApi.GetPersonAsync(name); Assert.AreEqual(person.Name, name); }
public async Task <string> RunAsync(string player, IMatch game, string[] args) { var rotation = await DecksiteApi.GetRotationAsync(); return($"[sU]The next rotation is in {rotation.FriendlyDiff}"); }
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); } }