예제 #1
0
        public async Task GetNewsArticlesComments()
        {
            await _syncService.SyncNewsAsync().ConfigureAwait(false);

            await _syncService.SyncPopularNewsCommentsAsync(DateTimeOffset.Now.AddDays(-1), 1).ConfigureAwait(false);

            var popularNewsArticle = _newsService.GetPopularNews(DateTimeOffset.Now.AddDays(-1), new PagedRequest(1)).Items.First();
            var comments           = _newsArticleCommentService.GetBestComments(popularNewsArticle.Id, 5);

            Assert.NotEmpty(comments);
            WritePrettyJson(comments);

            SportsContextHelper.DeleteAllNews(_sportsContext);
        }
예제 #2
0
        public override IAliceResponseBase Reply(SportsRequest sportsRequest)
        {
            SportsResponse   response;
            var              fromDate    = DateTimeOffset.Now.AddDays(-1);
            NewsArticleModel newsArticle = null;

            if (sportsRequest.State.Session.NextNewsArticleId != Guid.Empty)
            {
                newsArticle = _newsService.GetById(sportsRequest.State.Session.NextNewsArticleId);
            }

            if (newsArticle == null)
            {
                newsArticle = _newsService.GetPopularNews(fromDate, new PagedRequest(1, 0)).Items.FirstOrDefault();
            }
            IEnumerable <NewsArticleCommentModel> comments = null;

            if (newsArticle != null)
            {
                comments = _newsArticleCommentService.GetBestComments(newsArticle.Id, _sportsSettings.CommentsToDisplay);
            }

            if (comments != null && comments.Any())
            {
                var buttons = new List <AliceButtonModel>()
                {
                    new AliceButtonModel()
                    {
                        Title = Sports_Resources.Command_BestComments_OpenNewsArticle,
                        Url   = newsArticle.Url,
                        Hide  = false
                    }
                };
                string ttsEnding         = string.Empty;
                var    nextNewsArticle   = _newsService.GetNextPopularNewsArticle(fromDate, newsArticle.Id);
                Guid   nextNewsArticleId = Guid.Empty;
                if (nextNewsArticle != null)
                {
                    ttsEnding = $"{AliceHelper.SilenceString500}{Sports_Resources.Tips_BestComments_Next}";
                    buttons.Add(new SportsButtonModel(Sports_Resources.Command_BestComments_Next));
                    nextNewsArticleId = nextNewsArticle.Id;
                }
                buttons.Add(new SportsButtonModel(Sports_Resources.Command_LatestNews));
                buttons.Add(new SportsButtonModel(Sports_Resources.Command_MainNews));

                var text = new StringBuilder($"{Sports_Resources.BestComments_Title_Tts} \"{newsArticle.Title} {GetTitleEnding(newsArticle)}\":");
                var tts  = new StringBuilder($"{Sports_Resources.BestComments_Title_Tts} \"{newsArticle.Title}\"{AliceHelper.SilenceString500}");
                foreach (var comment in comments)
                {
                    string textComment = $"\n\n{EmojiLibrary.SpeechBalloon} {comment.CommentText} {EmojiLibrary.ThumbsUp}{comment.CommentRating}";
                    string textTts     = $"{AliceHelper.SilenceString500}{comment.CommentText}";
                    if (text.Length + textComment.Length <= AliceResponseModel.TextMaxLenght &&
                        tts.Length + textTts.Length + ttsEnding.Length <= AliceResponseModel.TtsMaxLenght)
                    {
                        text.Append(textComment);
                        tts.Append(textTts);
                    }
                }
                tts.Append(ttsEnding);

                response = new SportsResponse(sportsRequest, text.ToString(), tts.ToString(), buttons);
                response.SessionState.NextNewsArticleId = nextNewsArticleId;
                response.SessionState.CurrentScene      = SceneType;
            }
            else
            {
                var noResponseButtons = new List <AliceButtonModel>()
                {
                    new SportsButtonModel(Sports_Resources.Command_LatestNews),
                    new SportsButtonModel(Sports_Resources.Command_MainNews)
                };
                response = new SportsResponse(sportsRequest, Sports_Resources.BestComments_NoComments, noResponseButtons);
            }
            response.SessionState.CurrentScene = SceneType;
            return(response);
        }