//TODO: Unterschiedliche Zeiten für HD Wahlen erkennen // +Unterfunktionen public Game SetupGame(int id) { HtmlDocument source = web.Load(String.Concat(consthreadlink, id.ToString())); ConstructPost post = GetPostDataFromNode(GetNodesByClass(source.DocumentNode, consclassmessage).First()); Game ret = new Game() { ThreadId = id, SL = post.Author }; GameDay gameday = new GameDay() { Day = 1 }; gameday.LastPostNumber = post.PostNumber; gameday.Start = post.Time; gameday.End = GetLynchTime(post.Postcontent, post.Author, post.PostId, post.Time, id).AddDays(1); ret.Days.Add(gameday); ret.Active = true; ret.PlayerList = GetPlayerList(post.Postcontent, post.Author, post.PostNumber, id); ret.HoursPerDay = GetHoursPerDay(post.Postcontent); ret.WithHD = GetWithHD(post.Postcontent); return(ret); }
private ConstructPost GetPostDataFromNode(HtmlNode node) { ConstructPost ret = new ConstructPost(); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(node.InnerHtml); CleanFromQuotes(ref doc); ret.Author = GetAuthorFromDoc(doc); ret.PostNumber = GetPostNumberFromDoc(doc); ret.PostId = GetAttributeIntFromNode(node, consattrpostid); ret.Time = GetDateTimeFromDoc(doc); ret.Postcontent = doc; return(ret); }
//TODO: Mehr Schlüsselwörter erkennen //TODO: Spieler ersetzen erkennen(ReplacePlayer) private void AnalyzeSLPost(ConstructPost post, ref Game game) { if (post.Postcontent.DocumentNode.InnerText.Contains("Nachtpost") && post.Time > game.CurrentDay().End) { var current = game.CurrentDay(); GameDay gameday = new GameDay() { Day = current.Day + 1, End = current.End.AddHours(game.HoursPerDay), Start = post.Time }; game.Days.Add(gameday); } var plist = String.Join("|", game.PlayerList.Where(x => x.Alive).Select(x => ReplaceSymbols(x.Name))); var alist = String.Join("|", playerNames.Select(x => ReplaceSymbols(x.Value))); Regex regrep = new Regex($@"!replace (?<player1>{plist})?\s*(?<player2>{alist})?", RegexOptions.IgnoreCase); var match = regrep.Match(post.Postcontent.DocumentNode.InnerText); if (match.Success) { if (match.Groups["player1"].Success) { } } Regex reg = new Regex($@"(?<player>{plist})?\s*(wird|ist)(\s*neuer)?\s*(Hauptmann|HD)", RegexOptions.IgnoreCase); match = reg.Match(post.Postcontent.DocumentNode.InnerText); if (match.Success) { if (match.Groups["player"].Success) { game.HD = game.PlayerList.Where(x => x.Name.Equals(match.Groups["player"].Value, StringComparison.InvariantCultureIgnoreCase)).First(); } else { errorList.Add(new Error(conserrorHD, post.Author, post.PostId, game.ThreadId)); } } }
private bool TryGetVote(ConstructPost post, List <Player> playerlist, string votetoken, int gameID, out Player voted) { voted = null; var list = String.Join("|", playerlist.Where(x => x.Alive).Select(x => x.Name)); Regex reg = new Regex(String.Concat(votetoken, "(?<player>", list, ")?"), RegexOptions.RightToLeft | RegexOptions.IgnoreCase); var match = reg.Match(post.Postcontent.DocumentNode.InnerHtml); if (match.Success) { if (match.Groups["player"].Success) { voted = playerlist.Where(x => x.Name.Equals(match.Groups["player"].Value, StringComparison.InvariantCultureIgnoreCase)).First(); return(true); } else { errorList.Add(new Error(conserrorvote, post.Author, post.PostId, gameID)); } } return(false); }