public void AddToQueue(string twitchName, string ign) { if (InvokeRequired) { Invoke(new Action(() => AddToQueue(twitchName, ign))); } else { lock (QueuedUsers) { foreach (DataGridViewRow row in QueuedUsers.Rows) { if (row.Cells[0].Value.ToString() == twitchName) { row.Cells[1].Value = ign; TwitchChatManager.HandleChatMessage("", string.Format("@{0} your ign has been changed to '{1}, position #{2}'", twitchName, ign, row.Index + 1), false); return; } } } QueuedUsers.Rows.Add(twitchName, ign); QueuedUsers.Rows[QueuedUsers.Rows.Count - 1].ReadOnly = true; TwitchChatManager.HandleChatMessage("", string.Format("@{0} your are now in queue with ign '{1}', position #{2}", twitchName, ign, QueuedUsers.Rows.Count), false); } }
//Reads all the data from the IRC server public void Listen() { string Data = ""; try { while (_runThread && (Data = _reader.ReadLine()) != null) { //Initializing vars string _nick = ""; string _type = ""; string _channel = ""; string _message = ""; string[] ex; //Writes to console and main terminal Console.WriteLine(Data); //Respond PINGs with PONGs and the same message ex = Data.Split(new char[] { ' ' }, 5); if (ex[0] == "PING") { var pingpongmsg = "PONG " + ex[1] + "\r\n"; _writer.WriteLine(pingpongmsg); _writer.Flush(); Console.WriteLine(pingpongmsg); } //Splitting message and the meta data string[] split1 = Data.Split(':'); if (ex[0] != "PING" && split1.Length > 1) { //Splitting nick, type, chan and message string[] split2 = split1[1].Split(' '); //Nick consists of various things - we only want the nick itself if (split2[0] != null) { _nick = split2[0]; _nick = _nick.Split('!')[0]; } if (split2[1] != null) { //Type = PRIVMSG for normal messages. Only thing we need _type = split2[1]; } if (split2[2] != null) { //Channel posted to _channel = split2[2]; } //Get message if (split1.Length > 2) { for (var i = 2; i < split1.Length; i++) { if (i == 2) { _message += split1[i] + " "; } else { _message += ":" + split1[i] + " "; } } } if (_nick != "tmi.twitch.tv" && _nick != Properties.Settings.Default["TwitchBotUsername"].ToString().ToLower() + ".tmi.twitch.tv") { TwitchChatManager.HandleChatMessage(_nick, _message); } } } } catch (Exception e) { Console.Write(e.ToString()); //_listen.Abort(); } }