public ChannelViewModel(TwitchIrcClient irc, string channelName) { _irc = irc; _irc.MessageReceived += MessageReceived; _irc.UserParted += UserParted; _irc.UserJoined += UserJoined; _irc.NamesReceived += NamesReceived; _irc.UserStateReceived += UserStateReceived; _channelName = channelName; _irc.Join(_channelName); SendCommand = new DelegateCommand(Send); PartCommand = new DelegateCommand(Part); using (var wc = new TwitchApiClient()) { _badges = Json.Helper.Parse <BadgesResult>(wc.DownloadData(string.Format("https://api.twitch.tv/kraken/chat/{0}/badges", channelName))); } }
public void StartBot() { string server = BotSettings.TwitchIRC; logger.Debug("Connecting to IRC..."); Console.WriteLine("Connecting..."); Console.WriteLine(""); using (var client = new TwitchIrcClient()) { client.FloodPreventer = new IrcStandardFloodPreventer(4, 2000); client.Registered += IrcClient_Registered; // Wait until connection has succeeded or timed out. using (var registeredEvent = new ManualResetEventSlim(false)) { //Group chat - for whisper (not using) //byte[]ip = {199,9,253,119}; //IPAddress p = new IPAddress(ip); //IPEndPoint i = new IPEndPoint(p, 443); using (var connectedEvent = new ManualResetEventSlim(false)) { client.Connected += (sender2, e2) => connectedEvent.Set(); client.Registered += (sender2, e2) => registeredEvent.Set(); client.Connect(server, false, new IrcUserRegistrationInfo() { NickName = BotSettings.UserName, Password = BotSettings.OAuthChat, UserName = BotSettings.UserName }); if (!connectedEvent.Wait(3000)) { isConnectedToIRC = false; DisplayConnectionError(server); OpenSettingsWindow(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Press Enter to restart Bot and apply new settings.."); Console.WriteLine(); Console.ReadLine(); Restart = true; } } if (!registeredEvent.Wait(3000)) { if (isConnectedToIRC) { isConnectedToIRC = false; DisplayConnectionError(server); OpenSettingsWindow(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Press Enter to restart Bot and apply new settings."); Console.WriteLine(); Console.ReadLine(); Restart = true; } } } if (isConnectedToIRC) { logger.Debug("Connected, about to join channel."); twitchAPI = new TwitchAPI(BotSettings.BotOAuth, BotSettings.BotClientID); client.SendRawMessage("CAP REQ :twitch.tv/membership"); //request to have Twitch IRC send join/part & modes. client.Join(MAINCHANNEL); HandleEventLoop(client); } } }