Esempio n. 1
0
        public override async Task HandleAsync <T>(ContentRequestNotification notification, ILogger <T> logger)
        {
            RawTweet videoTweet = await twitterRepository.FindByIdAsync(notification.IdOfTweetBeingRepliedTo.Value);

            TweetNotification tweetNotification = new TweetNotification(videoTweet, notification.IdOfRequestingTweet, notification.RequestedBy);

            if (tweetNotification.HasVideo())
            {
                var video   = tweetNotification.GetVideo();
                var request = tweetNotification.GetVideoRequest(video.Id);

                await scraperRepository.CaptureTwitterVideoAndRequestAsync(request, video);

                string response = video.GetResponseContent(settings.BaseUrl, request.RequestedBy);
                //send back response
                await twitterRepository.ReplyToTweetAsync(request.RequestingTweetId, response);

                logger.LogInformation($"Sent back this response -> {response}");
            }
            else
            {
                logger.LogWarning($"The tweet being responded to didn't have a video -> {tweetNotification.TweetWithVideo.id}");
                await base.HandleAsync(notification, logger);
            }
        }
Esempio n. 2
0
        public virtual async Task HandleAsync <T>(ContentRequestNotification notification, ILogger <T> logger)
        {
            if (nextHandler != null)
            {
                await nextHandler.HandleAsync(notification, logger);

                return;
            }
        }
Esempio n. 3
0
        public static ContentRequestNotification CreateRequestNotification(this RawTweet rawTweet)
        {
            var requestNotification = new ContentRequestNotification
            {
                IdOfRequestingTweet     = rawTweet.id,
                IdOfTweetBeingRepliedTo = rawTweet.in_reply_to_status_id,
                RequestedBy             = rawTweet.user.screen_name
            };

            return(requestNotification);
        }
Esempio n. 4
0
        public override async Task HandleAsync <T>(ContentRequestNotification notification, ILogger <T> logger)
        {
            await Task.CompletedTask;

            if (notification.RequestedBy.Equals(settings.StreamListeningKeyword, StringComparison.OrdinalIgnoreCase))
            {
                logger.LogInformation("This is my tweet. Ignoring");
                return;
            }
            {
                await base.HandleAsync(notification, logger);
            }
        }
Esempio n. 5
0
        public override async Task HandleAsync <T>(ContentRequestNotification notification, ILogger <T> logger)
        {
            await Task.CompletedTask;

            if (!notification.IdOfTweetBeingRepliedTo.HasValue) // this tweet is not in response to any tweet
            {
                if (logger.IsEnabled(LogLevel.Warning))
                {
                    logger.LogWarning("Received tweet with id {} that is not a reply to another", notification.IdOfRequestingTweet);
                }
                return;
            }
            else
            {
                await base.HandleAsync(notification, logger);
            }
        }
Esempio n. 6
0
        public override async Task HandleAsync <T>(ContentRequestNotification notification, ILogger <T> logger)
        {
            TwitterVideo twitterVideo;
            bool         exists = scraperRepository.GetIfVideoExists(notification.IdOfTweetBeingRepliedTo.Value, out twitterVideo);

            if (exists)
            {
                logger.LogInformation($"This tweet existed {notification.IdOfTweetBeingRepliedTo.Value}.");

                var request = new TwitterVideoRequest(notification.IdOfRequestingTweet, twitterVideo.Id, notification.RequestedBy);

                await scraperRepository.CaptureTwitterRequestAsync(request);

                string response = twitterVideo.GetResponseContent(settings.BaseUrl, request.RequestedBy);
                //send back response
                await twitterRepository.ReplyToTweetAsync(notification.IdOfRequestingTweet, response);

                return;
            }
            else
            {
                await base.HandleAsync(notification, logger);
            }
        }