public int coolDownSecond = 0; //set higher if needed internal void Connect() { // Secret is used to verify validity of incoming data Console.WriteLine("Connecting..."); client.Initialize(twitchCredentials, JoinedChannel.Channel, _chatCommandIdentifier, _chatCommandIdentifier); twitchAPI.Settings.ClientId = TwitchInfo.ClientId; twitchAPI.Settings.AccessToken = TwitchInfo.ChannelAccessToken; _chatCommands.SetCommandIdentifier(_chatCommandIdentifier); _chatCommands.twitchAPI = twitchAPI; TwitchHelpers.TwitchAPI = twitchAPI; client.OnLog += Client_OnLog; client.OnConnectionError += Client_OnConnectionError; client.OnMessageThrottled += Client_OnMessageThrottled; client.OnMessageReceived += Client_OnMessageReceived; client.OnNewSubscriber += Client_OnNewSubscriber; client.OnReSubscriber += Client_OnReSubscriber; client.OnBeingHosted += Client_OnBeingHosted; client.OnUserJoined += Client_OnUserJoined; client.OnUserLeft += Client_OnUserLeft; client.OnUserTimedout += Client_OnUserTimedout; client.OnUserBanned += Client_OnUserBanned; client.OnConnected += Client_OnConnected; client.OnDisconnected += Client_OnDisconnected; pubSub.OnPubSubServiceConnected += PubSub_OnPubSubServiceConnected; // Err_badauth //pubSub.ListenToFollows(TwitchHelpers.GetUserId(TwitchInfo.ChannelName)); //pubSub.ListenToBitsEvents(TwitchHelpers.GetUserId(TwitchInfo.ChannelName)); pubSub.OnListenResponse += PubSub_OnListenResponse; pubSub.OnFollow += PubSub_OnFollow; pubSub.OnBitsReceived += PubSub_OnBitsReceived; pubSub.OnStreamDown += PubSub_OnStreamDown; pubSub.OnStreamUp += PubSub_OnStreamUp; try { pubSub.Connect(); client.Connect(); moderators = TwitchHelpers.GetMods().Result; editors = TwitchHelpers.GetEditors().Result; } catch (Exception e) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(e.Message); Console.ResetColor(); throw; } LastCommand = DateTime.Now; }
private void Client_OnUserJoined(object sender, OnUserJoinedArgs e) { if (!Measurables.allViewers.Contains(e.Username)) { Measurables.allViewers.Add(e.Username); } Measurables.currentViewers.Add(e.Username); Measurables.viewerCount++; int Id = Convert.ToInt32(TwitchHelpers.GetUserId(e.Username)); var newViewer = Context.ViewerStats.Where(v => v.TwitchID == Id).FirstOrDefault(); if (newViewer == null) { NewViewerConfig newViewerConfig = new NewViewerConfig(); Context.ViewerStats.Add(newViewerConfig.initViewer(e.Username, Id.ToString())); Context.SaveChanges(); } }