async Task <ChatServerDetails> GetChatServerDetails(bool useCreds) { try { string res = await MixerUtils.MakeMixerHttpRequest($"api/v1/chats/{m_channelId}", useCreds); return(JsonConvert.DeserializeObject <ChatServerDetails>(res)); } catch (Exception e) { Logger.Error($"Failed to get channel server info for channel: {m_channelId}", e); } return(null); }
public static void Main(string[] args) { MixerUtils.Init(); Carl c = new Carl(); if (!c.Run(args)) { return; } // Setup the commander dan. Firehose hose = new Firehose(c); c.SubFirehose(hose); CommandDan dan = new CommandDan(c, hose); // Setup message Dan hose = new Firehose(c); c.SubFirehose(hose); MessagesDan messagesDan = new MessagesDan(hose); // Notification Dan hose = new Firehose(c); c.SubFirehose(hose); FriendlyDan friendlyDan = new FriendlyDan(hose); while (true) { Thread.Sleep(500000); } //var host = new WebHostBuilder() // .UseKestrel() // .UseContentRoot(Directory.GetCurrentDirectory()) // .UseIISIntegration() // .UseStartup<Startup>() // .Build(); //host.Run(); }
private async Task <List <int> > GetUserIdsWatchingChannel(int channelId) { const int c_limit = 100; List <int> knownUsers = new List <int>(); int pageCount = 0; while (pageCount < c_channelUserPageLimit) { // Setup the call try { // Get the response string res = await MixerUtils.MakeMixerHttpRequest($"api/v1/chats/{channelId}/users?limit={c_limit}&page={pageCount}&order=userName:asc&fields=userId"); // Parse it. List <ChatUser> users = JsonConvert.DeserializeObject <List <ChatUser> >(res); // Add it to our list. foreach (var user in users) { knownUsers.Add(user.userId); } // If we hit the end, get out. if (users.Count < c_limit) { break; } } catch (Exception e) { Logger.Error($"Failed to query chat users API.", e); break; } pageCount++; } return(knownUsers); }
public bool Run(string[] args) { CarlConfig config = CarlConfig.Get(); if (config != null) { m_chatBotUserId = config.ChatBotUserId; m_chatBotoAuthToken = config.ChatBotOAuthToken; m_viewerCountLimit = config.ViewerCountLimit; } else { Logger.Info("Checking Args..."); if (args.Length < 2) { Logger.Info("Usage: carl <chat bot user Id> <chat bot oauth> (channel viewer count limit - default is 5)"); Logger.Info("User info can be found here: https://dev.mixer.com/tutorials/chatbot.html"); return(false); } if (!int.TryParse(args[0], out m_chatBotUserId)) { Logger.Error("Failed to parse chat bot user id."); return(false); } m_chatBotoAuthToken = args[1]; if (args.Length > 2) { if (!int.TryParse(args[2], out m_viewerCountLimit)) { Logger.Error("Failed to parse viewer count limit."); return(false); } } } Logger.Info($"Starting! Viewer Count Limit:{m_viewerCountLimit}."); // Set the oauth token MixerUtils.SetMixerCreds(m_chatBotoAuthToken); Logger.Info("Setting up discovery"); // Start the discovery process. ChannelDiscover dis = new ChannelDiscover(m_viewerCountLimit, m_channelOverrides); dis.OnChannelOnlineUpdate += OnChannelOnlineUpdate; dis.Run(); Logger.Info("Setting up work master"); // Setup the work master m_masterWorker = new Thread(WorkMasterThread); m_masterWorker.IsBackground = true; m_masterWorker.Start(); Logger.Info("Setting up worker threads"); // Setup the worker threads. int i = 0; while (i < m_workerLimit) { i++; Thread t = new Thread(WorkerThread); t.IsBackground = true; t.Start(); m_workers.Add(t); } // Create our creeper. m_creeperCarl = new CreeperCarl(this); Logger.Info("Running!"); return(true); }
private async Task <List <MixerChannel> > GetOnlineChannels() { List <MixerChannel> channels = new List <MixerChannel>(); // Add the debug overrides if needed. if (m_channelOverrides != null && m_channelOverrides.Count > 0) { foreach (int chanId in m_channelOverrides) { channels.Add(new MixerChannel() { Id = chanId, Token = await MixerUtils.GetChannelName(chanId), ViewersCurrent = 300, Online = true }); } return(channels); } // Always add my channel for debugging. channels.Add(new MixerChannel() { Id = 153416, Token = await MixerUtils.GetChannelName(153416), ViewersCurrent = 300, Online = true, }); int i = 0; while (i < 1000) { try { string response = await MixerUtils.MakeMixerHttpRequest($"api/v1/channels?limit=100&page={i}&order=online:desc,viewersCurrent:desc&fields=token,id,viewersCurrent,online"); List <MixerChannel> chan = JsonConvert.DeserializeObject <List <MixerChannel> >(response); channels.AddRange(chan); // Check if we hit the end. if (chan.Count == 0) { break; } // Check if we are on channels that are under our viewer limit if (chan[0].ViewersCurrent < m_viwersInclusiveLimit) { break; } // Check if we hit the end of online channels. if (!chan[0].Online) { break; } // Sleep a little so we don't hit the API too hard. await Task.Delay(10); } catch (Exception e) { Logger.Error($"Failed to query channel API.", e); break; } i++; } return(channels); }