public void Tick() { if (_networkStream.DataAvailable) { StringBuilder stringBuilder = new StringBuilder(); while (_networkStream.DataAvailable) { byte[] data = new byte[1024]; _networkStream.Read(data, 0, data.Length); stringBuilder.Append(Decode(data)); } string raw = stringBuilder.ToString(); stringBuilder.Clear(); #if DEBUG foreach (Match match in Regex.Matches(raw, "^(.*)$", RegexOptions.Multiline)) { Debug.WriteLine(match.Groups[1]); } #endif //Catch Messages foreach ( Match match in Regex.Matches(raw, "^:(.*)!.*@.*\\.tmi\\.twitch\\.tv PRIVMSG #.* :(.*)$", RegexOptions.Multiline) ) { _messageStore.AddMessage(new ChatMessage(_userMap.GetTwitchUser(match.Groups[1]), match.Groups[2])); } foreach ( Match match in Regex.Matches(raw, "^:(.*)!.*@.*\\.tmi\\.twitch\\.tv JOIN #.*$", RegexOptions.Multiline)) { _messageStore.AddMessage(new JoinPartMessage(_userMap.GetTwitchUser(match.Groups[1]), true)); } foreach ( Match match in Regex.Matches(raw, "^:(.*)!.*@.*\\.tmi\\.twitch\\.tv PART #.*$", RegexOptions.Multiline)) { _messageStore.AddMessage(new JoinPartMessage(_userMap.GetTwitchUser(match.Groups[1]), false)); _userMap.RemoveUser(match.Groups[1]); } if (Regex.Matches(raw, "PING :tmi\\.twitch\\.tv", RegexOptions.Multiline).Count > 0) { Sendcmd("PONG :tmi.twitch.tv"); _messageStore.AddMessage(new PingMessage()); } } }