示例#1
0
        private async Task Receiving(ClientWebSocket client)
        {
            var buffer = new byte[1024 * 4];

            while (true)
            {
                var result = await client.ReceiveAsync(new ArraySegment <byte>(buffer), CancellationToken.None);

                var connectionStatus = client.State;
                if (result.MessageType == WebSocketMessageType.Text)
                {
                    var data = Encoding.UTF8.GetString(buffer, 0, result.Count);

                    if (data.Replace(" ", "").ToLower().Contains("{\"online\":true}"))
                    {
                        var payload     = JsonConvert.DeserializeObject <MixerPayload>(data);
                        var channelData = payload.data.channel.Split(':');
                        var channelId   = channelData[1];
                        var channel     = await _mixerManager.GetChannelById(channelId);

                        Logging.LogMixer(channel.token + " has gone online.");
                        await AnnounceLiveChannel(channelId);
                    }
                    else if (data.Replace(" ", "").ToLower().Contains("{\"online\":false}"))
                    {
                        var payload     = JsonConvert.DeserializeObject <MixerPayload>(data);
                        var channelData = payload.data.channel.Split(':');
                        var channelId   = channelData[1];
                        var channel     = await _mixerManager.GetChannelById(channelId);

                        Logging.LogMixer(channel.token + " has gone offline.");
                        await StreamOffline(channelId);
                    }
                }

                else if (result.MessageType == WebSocketMessageType.Close)
                {
                    await client.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None);

                    break;
                }
            }
        }
示例#2
0
        public async Task Live()
        {
            var beam    = BotFiles.GetCurrentlyLiveBeamChannels();
            var hitbox  = BotFiles.GetCurrentlyLiveHitboxChannels();
            var twitch  = BotFiles.GetCurrentlyLiveTwitchChannels();
            var youtube = BotFiles.GetCurrentlyLiveYouTubeChannels();
            var picarto = BotFiles.GetCurrentlyLivePicartoChannels();


            var guildId = Context.Guild.Id;

            var beamLive    = "";
            var hitboxLive  = "";
            var twitchLive  = "";
            var youtubeLive = "";
            var picartoLive = "";

            foreach (var b in beam)
            {
                foreach (var cm in b.ChannelMessages)
                {
                    if (cm.GuildId == guildId)
                    {
                        var channel = await _mixerManager.GetChannelById(b.Name);

                        if (channel != null && channel.online)
                        {
                            beamLive += channel.token + ", ";
                        }

                        break;
                    }
                }
            }

            foreach (var p in picarto)
            {
                foreach (var cm in p.ChannelMessages)
                {
                    if (cm.GuildId == guildId)
                    {
                        var channel = await _mixerManager.GetChannelById(p.Name);

                        if (channel != null && channel.online)
                        {
                            picartoLive += channel.token + ", ";
                        }

                        break;
                    }
                }
            }

            foreach (var h in hitbox)
            {
                foreach (var cm in h.ChannelMessages)
                {
                    if (cm.GuildId == guildId)
                    {
                        hitboxLive += h.Name + ", ";

                        break;
                    }
                }
            }

            foreach (var t in twitch)
            {
                foreach (var cm in t.ChannelMessages)
                {
                    if (cm.GuildId == guildId)
                    {
                        var channel = await _twitchManager.GetStreamById(t.Name);

                        if (channel != null && channel.stream != null)
                        {
                            twitchLive += channel.stream.channel.name + ", ";
                        }

                        break;
                    }
                }
            }

            foreach (var yt in youtube)
            {
                foreach (var cm in yt.ChannelMessages)
                {
                    if (cm.GuildId == guildId)
                    {
                        var channel = await _youtubeManager.GetLiveVideoByChannelId(yt.Name);

                        if (channel != null && channel.items != null && channel.items.Count > 0)
                        {
                            youtubeLive += channel.items[0].snippet.channelTitle + ", ";
                        }

                        break;
                    }
                }
            }

            beamLive    = beamLive.Trim().TrimEnd(',');
            hitboxLive  = hitboxLive.Trim().TrimEnd(',');
            twitchLive  = twitchLive.Trim().TrimEnd(',');
            youtubeLive = youtubeLive.Trim().TrimEnd(',');
            picartoLive = picartoLive.Trim().TrimEnd(',');

            string info = "```Markdown\r\n" +
                          "# Currently Live\r\n" +
                          "- Mixer: " + beamLive + "\r\n" +
                          "- Picarto: " + picartoLive + "\r\n" +
                          "- Smashcast: " + hitboxLive + "\r\n" +
                          "- Twitch: " + twitchLive + "\r\n" +
                          "- YouTube Gaming: " + youtubeLive + "\r\n" +
                          "```\r\n";

            await Context.Channel.SendMessageAsync(info);
        }