Ejemplo n.º 1
0
        public async Task GetFeed_ReturnsFeed()
        {
            var feedReader = new YoutubeFeedReader(_client);

            var feed = await feedReader.GetFeed("https://www.youtube.com/feeds/videos.xml?playlist_id=PLAFX7TSEV7SOqEQKnrrFiV7bUY8kN5Qof");

            Assert.Equal("Solo on .NET", feed.Title);
            Assert.Equal(15, feed.Videos.Count);
        }
Ejemplo n.º 2
0
        public async Task Youtube()
        {
            if (string.IsNullOrWhiteSpace(Context.GuildOwner?.YoutuberId))
            {
                return;
            }

            var video = await YoutubeFeedReader.GetLastestVideoFromFeed(Context.GuildOwner.YoutuberId);

            await ReplyAsync(video.Url);
        }
Ejemplo n.º 3
0
        public async Task AddYoutube(string youtubeId, IGuildChannel guildChannel)
        {
            var video = await YoutubeFeedReader.GetLastestVideoFromFeed(youtubeId);

            if (video is null)
            {
                await ReplyAsync("I am unable to find information for that channel");

                return;
            }

            var youtuber = await _botContext.Youtubers.Include(x => x.YoutubeAlertSubscriptions)
                           .FirstOrDefaultAsync(x => x.Id == youtubeId);


            if (youtuber is null)
            {
                youtuber = new Youtuber
                {
                    Id   = youtubeId,
                    Name = video.User,
                    YoutubeAlertSubscriptions = new List <YoutubeAlertSubscription>()
                };
                _botContext.Youtubers.Add(youtuber);
                JobManager.AddJob(
                    () => new YoutubeMonitoringJob(youtuber.Id, _provider.GetService <SteveBotContext>(),
                                                   Context.Client).Execute(), s => s.WithName(youtubeId).ToRunEvery(60).Seconds());
            }

            if (youtuber.YoutubeAlertSubscriptions.Any(x => x.DiscordChannelId == (long)guildChannel.Id))
            {
                await ReplyAsync($"You already subscribed to {youtuber.Name} in {guildChannel.Name}");

                return;
            }

            youtuber.YoutubeAlertSubscriptions.Add(new YoutubeAlertSubscription
            {
                DiscordChannelId = (long)guildChannel.Id,
                YoutuberId       = youtuber.Id
            });
            var changes = _botContext.SaveChanges();

            if (changes > 0)
            {
                await ReplyAsync($"Alert for {youtuber.Name} added to {guildChannel.Name}");
            }
            else
            {
                await ReplyAsync($"Unable to create Alert for {youtuber.Name}");
            }
        }
Ejemplo n.º 4
0
        public void Execute()
        {
            var youtuber = _botContext.Youtubers.Include(x => x.YoutubeAlertSubscriptions)
                           .FirstOrDefault(x => x.Id == _channelId);

            var video = YoutubeFeedReader.GetLastestVideoFromFeed(_channelId).AsSync(false);

            if (video.DatePublished - youtuber.LatestVideoDate <= TimeSpan.Zero)
            {
                return;
            }

            youtuber.LatestVideoDate = video.DatePublished;

            foreach (var subscription in youtuber.YoutubeAlertSubscriptions)
            {
                var channel = _client.GetChannel((ulong)subscription.DiscordChannelId) as SocketTextChannel;
                channel.SendMessageAsync(video.Url);
            }

            _botContext.SaveChanges();
        }
Ejemplo n.º 5
0
        public void Execute()
        {
            var youtuber = _botContext.Youtubers.Include(x => x.YoutubeAlertSubscriptions)
                           .FirstOrDefault(x => x.Id == _channelId);

            if (youtuber is null)
            {
                Log.Information($"Error getting Youtuber for {_channelId}");
                return;
            }

            var video = YoutubeFeedReader.GetLastestVideoFromFeed(_channelId).AsSync(false);

            if (video is null)
            {
                Log.Information($"Error getting videos for {youtuber.Name}");
                return;
            }
            if (video.DatePublished - youtuber.LatestVideoDate <= TimeSpan.Zero)
            {
                return;
            }

            youtuber.LatestVideoDate = video.DatePublished;

            foreach (var subscription in youtuber.YoutubeAlertSubscriptions)
            {
                var channel = _client.GetChannel((ulong)subscription.DiscordChannelId) as ITextChannel;
                if (channel is null)
                {
                    Log.Information($"Youtube: {youtuber.Name} missing channel {subscription.DiscordChannelId} on server {channel.Guild.Name}");
                    continue;
                }
                channel.SendMessageAsync(video.Url);
            }

            _botContext.SaveChanges();
        }
Ejemplo n.º 6
0
 public RssController(YoutubeFeedReader feedReader, ITunesFeedReader itFeedreader, ZipCastsContext dbContext)
 {
     _ytFeedReader = feedReader;
     _itFeedreader = itFeedreader;
     _dbContext    = dbContext;
 }