public TwitchChatConnection(TwitchCredentials connectingUser, bool isBot = true) { this.connectedUser = connectingUser; this.isBot = isBot; // Connect to IRC Twitch and login with given TwitchCredentials // http://tmi.twitch.tv/servers?channel=riotgames ircClient = new BotIrcClient("irc.twitch.tv", 6667, connectingUser); // Request JOIN/PART notifications for bot account if (isBot) { ircClient.WriteLineThrottle("CAP REQ :twitch.tv/membership"); ircClient.WriteLineThrottle("CAP REQ :twitch.tv/tags"); ircClient.WriteLineThrottle("CAP REQ :twitch.tv/commands"); } ChatMessageReceived += (s, e) => { }; }
private void ConnectBot() { try { botChat.Abort(); } catch (ThreadAbortException) { } catch (Exception) { } // Disable UI elements textBoxBotName.IsEnabled = false; buttonBotConnect.IsEnabled = false; tbChannelName.IsEnabled = false; cbServerIP.IsEnabled = false; cbServerPort.IsEnabled = false; cbAutoConnectBot.IsEnabled = false; btnBotConnect.Content = "Disconnect"; // Twitch Credentials accountBot = new TwitchCredentials(Config.BotUsername, Config.BotOAuthKey); // Start Bot connection and login botChatConnection = new TwitchChatConnection(accountBot); botChatConnection.JoinChannel(Config.ChannelName); // Create threads for the chat connections botChat = new Thread(new ThreadStart(botChatConnection.Run)) { IsBackground = true }; // Start the chat connection threads botChat.Start(); }
public BotIrcClient(string ip, int port, TwitchCredentials user) { // Set vars _throttle = 1550; _lastSend = DateTime.MinValue; _loggedinAs = user; tcpClient = new TcpClient(ip, port); // TODO: connection check > ASYNC TIMEOUT RETURN ERROR inputStream = new StreamReader(tcpClient.GetStream()); outputStream = new StreamWriter(tcpClient.GetStream()); // TODO: make "login" method in TwitchChatConnections to split error handling WriteLine("PASS oauth:" + user.OAuth); WriteLine("NICK " + user.UserName); // TODO: successfull login check > in TwitchChatConnection // Twitch doesnt require to set username/domain/realname //WriteLine("USER " + user.username + " 8 * :" + user.username); }
/// <summary> /// Constructor to be used to parse receoved IRC message. /// </summary> /// <param name="receivedLine">Received IRC message.</param> /// <param name="loggedinAccount">Account that is logged in to the IRC.</param> public IrcMessage(string receivedLine, TwitchCredentials loggedinAccount) { this.timestamp = DateTime.Now; this.messageSource = loggedinAccount; // First get all arguments if starts with @ if (receivedLine.StartsWith("@")) { MatchCollection ircTags = Regex.Matches(receivedLine, @"(?<arg>[\w-]+)=(?<value>[\w:#,-\/]*);?"); foreach (Match m in ircTags) { switch (m.Groups["arg"].Value) { case "color": nameColor = m.Groups["value"].Value; break; case "display-name": displayName = m.Groups["value"].Value; break; case "emotes": emotes = m.Groups["value"].Value; break; case "mod": moderator = (!string.IsNullOrEmpty(m.Groups["value"].Value) && m.Groups["value"].Value == "1"); break; case "subscriber": subscriber = (!string.IsNullOrEmpty(m.Groups["value"].Value) && m.Groups["value"].Value == "1"); break; case "turbo": turbo = (!string.IsNullOrEmpty(m.Groups["value"].Value) && m.Groups["value"].Value == "1"); break; case "user-id": userId = int.Parse(m.Groups["value"].Value); break; case "user-type": switch (m.Groups["value"].Value) { case "mod": userType = uType.MODERATOR; break; case "global_mod": userType = uType.GLOBALMODERATOR; break; case "admin": userType = uType.ADMIN; break; case "staff": userType = uType.STAFF; break; default: userType = uType.VIEWER; break; } break; } } } // Get the base IRC message //Match ircMessage = Regex.Match(receivedLine, @"(?<!\S)(?::(?:(?<author>\w+)!)?(?<host>\S+) )?(?<command>\w+)(?: (?!:)(?<args>.+?))?(?: :(?<message>.+))?$"); Match ircMessage = Regex.Match(receivedLine, @"(?<!\S)(?::(?:(?<author>\w+)!)?(?<host>\S+) )?(?<command>\w+)(?: (?<args>.+?))?(?: :(?<message>.+))?$"); author = ircMessage.Groups["author"].Value; host = ircMessage.Groups["host"].Value; command = ircMessage.Groups["command"].Value; arguments = ircMessage.Groups["args"].Value.Split(' '); message = ircMessage.Groups["message"].Value; }
private void ConnectStreamer() { try { streamerChat.Abort(); } catch (ThreadAbortException) { } catch (Exception) { } // Twitch Credentials accountStreamer = new TwitchCredentials(Config.StreamerUsername, Config.StreamerOAuthKey); // Start Streamer connection and login streamerChatConnection = new TwitchChatConnection(accountStreamer, false); streamerChatConnection.JoinChannel(Config.ChannelName); // Create threads for the chat connections streamerChat = new Thread(new ThreadStart(streamerChatConnection.Run)) { IsBackground = true }; // Start the chat connection threads streamerChat.Start(); // TODO check on success login/connection if (true) { // Disable Settings UI elements textBoxStreamerName.IsEnabled = false; buttonStreamerConnect.IsEnabled = false; cbAutoConnectStreamer.IsEnabled = false; btnStreamerConnect.Content = "Disconnect"; // Enable Twitch Dashboard tab tabMainDashboard.IsEnabled = true; try { client = new TwitchAuthenticatedClient(Config.StreamerOAuthKey, Config.TwitchClientID); txtTitle.Text = Utils.GetClient().GetMyChannel().Status; cbGame.Text = Utils.GetClient().GetMyChannel().Game; tbStreamDelay.Text = Utils.GetClient().GetMyChannel().Delay.ToString(); // Get Streamers Avatar using (WebClient wc = new WebClient()) { BitmapImage logo = new BitmapImage(); logo.BeginInit(); logo.StreamSource = wc.OpenRead(client.GetMyChannel().Logo); logo.CacheOption = BitmapCacheOption.OnLoad; logo.EndInit(); imgLogo.Source = logo; } // Enable partnered elements when partnered if (client.GetMyUser().Partnered) { // Stream delay tbStreamDelay.IsEnabled = true; // Manual Commercials gbManualCommercials.IsEnabled = true; } } catch (Exception ex) { Trace.TraceError(ex.ToString()); } } }