Пример #1
0
        public async Task CanGetStreamById()
        {
            var response = await _twitchManager.GetStreamById(_testAlwaysLiveStreamId);

            Assert.True(response != null && response.stream != null);

            if (response != null)
            {
                Assert.True(response.stream.channel.display_name.Equals("Monstercat"));
            }
        }
Пример #2
0
        public async Task Announce(string channelName)
        {
            if (!IsAdmin)
            {
                return;
            }

            var file   = _botSettings.DirectorySettings.ConfigRootDirectory + _botSettings.DirectorySettings.GuildDirectory + Context.Guild.Id + ".json";
            var server = new DiscordServer();

            if (File.Exists(file))
            {
                server = JsonConvert.DeserializeObject <DiscordServer>(File.ReadAllText(file));
            }

            var twitchId = await _twitchManager.GetTwitchIdByLogin(channelName);

            if (!string.IsNullOrEmpty(twitchId) && twitchId == "0")
            {
                await Context.Channel.SendMessageAsync(channelName + " doesn't exist on Twitch.");

                return;
            }

            var streamResponse = await _twitchManager.GetStreamById(twitchId);

            var stream = streamResponse.stream;

            if (stream == null)
            {
                await Context.Channel.SendMessageAsync(channelName + " isn't online.");

                return;
            }

            string url          = stream.channel.url;
            string name         = StringUtilities.ScrubChatMessage(stream.channel.display_name);
            string avatarUrl    = stream.channel.logo != null ? stream.channel.logo : "https://static-cdn.jtvnw.net/jtv_user_pictures/xarth/404_user_70x70.png";
            string thumbnailUrl = stream.preview.large;

            var message = await _messagingService.BuildMessage(name, stream.game, stream.channel.status, url, avatarUrl,
                                                               thumbnailUrl, Constants.Twitch, stream.channel._id.ToString(), server, server.GoLiveChannel, null);

            await _messagingService.SendMessages(Constants.Twitch, new List <BroadcastMessage> {
                message
            });
        }
Пример #3
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);
        }