Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
        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);
        }