private TwitchChannelApi QueryUserList() { TwitchChannelApi chatters = null; try { string contents; string url = String.Format(@"http://tmi.twitch.tv/group/user/{0}/chatters", channel); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "GET"; using (var response = request.GetResponse()) using (var stream = response.GetResponseStream()) using (var reader = new StreamReader(stream)) { HttpStatusCode statusCode = ((HttpWebResponse)response).StatusCode; if (statusCode == HttpStatusCode.OK) { contents = reader.ReadToEnd(); } else { contents = ""; } } log.DebugFormat("Got viewers list: {0}", contents); chatters = JsonConvert.DeserializeObject <TwitchChannelApi>(contents); } catch (Exception ex) { log.WarnFormat("Failed to parse view list: {0}", ex.ToString()); } return(chatters); }
private void channelListThread() { while (isRunning) { try { log.Debug("Getting viewers list"); TwitchChannelApi viewerList = QueryUserList(); if (viewerList != null) { lock (this) { chattersList = new List <string>(); foreach (string s in viewerList.chatters.moderators) { log.DebugFormat("Adding {0} to chatters list", s); chattersList.Add(s.ToLower()); } foreach (string s in viewerList.chatters.viewers) { log.DebugFormat("Adding {0} to chatters list", s); chattersList.Add(s.ToLower()); } for (int x = 0; x < gymLeaders.Count; x++) { if (chattersList.Contains(gymLeaders[x].Name.ToLower())) { if (!gymLeaders[x].Online.Equals("Open")) { gymLeaders[x].Online = "Online"; } } else { if (gymLeaders[x].offlineCountdown > 0) { gymLeaders[x].offlineCountdown--; } else { gymLeaders[x].Online = "Offline"; } } } } //gymLeaders.CollectionChanged sleepHandle.WaitOne(60 * 1000); //Thread.Sleep(60000); } else { log.Debug("Viewers list is null"); //Thread.Sleep(10000); sleepHandle.WaitOne(10000); } } catch (Exception ex) { log.WarnFormat("Something went wrong processing the channel lists... {0}", ex.ToString()); } } log.Debug("Exiting gym thread"); }