예제 #1
0
        public override async Task <GetReviewsResponse> GetReviews(GetReviewsRequest request, ServerCallContext context)
        {
            try
            {
                var response        = new GetReviewsResponse();
                var reviewQueryRepo = _queryFactory.MongoQueryRepository <Domain.Review>();
                var reviews         =
                    await reviewQueryRepo.FindListByFieldAsync(r =>
                                                               r.ReviewProduct.Id == request.ProductId.ConvertTo <Guid>());

                if (reviews == null)
                {
                    throw new CoreException($"Couldn't find the review with productId#{request.ProductId}.");
                }

                response.Reviews.AddRange(
                    reviews
                    .Select(x => x.ToDto())
                    .ToList());

                return(response);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                throw new RpcException(new Status(StatusCode.Internal, ex.Message));
            }
        }
예제 #2
0
        public override Task <GetReviewsResponse> GetReviews(GetReviewsRequest req, ServerCallContext context)
        {
            Console.WriteLine("Incoming get reviews request: Episode = {0} ", req.Episode);

            var resp = new GetReviewsResponse();

            if (_data.TryGetValue(req.Episode, out List <Review> reviews))
            {
                resp.Reviews.AddRange(reviews);
            }

            return(Task.FromResult(resp));
        }
예제 #3
0
        public override async Task <GetReviewsResponse> GetReviews(GetReviewsRequest request, ServerCallContext context)
        {
            var reviewQueryRepo = _queryFactory.MongoQueryRepository <Domain.Review>();
            var reviews         =
                await reviewQueryRepo.FindListByFieldAsync(r =>
                                                           r.ReviewProduct.Id == request.ProductId.ConvertTo <Guid>());

            if (reviews == null)
            {
                throw new CoreException($"Couldn't find the review with productId#{request.ProductId}.");
            }

            var response = new GetReviewsResponse();

            response.Reviews.AddRange(
                reviews
                .Select(x => x.ToDto())
                .ToList());

            return(response);
        }
예제 #4
0
        public async Task GatherReviews(string product, uint appId, CancellationToken token)
        {
            logger.LogInformation("Gathering reviews for app {0}", appId);

            GetReviewsResponse response = await steam.GetReviews(new GetReviewsRequest(appId) { Filter = ReviewFilter.Recent }, token);

            logger.LogInformation("Got {0} recent reviews", response.Reviews.Count);

            IDictionary <uint, Review> reviews = response.Reviews.ToDictionary(x => x.RecommendationId, x => x);

            uint[] recentReviewIds = reviews.Keys.ToArray();

            uint[] seenReviewIds = (await seenItemRepository.GetSeenItems(recentReviewIds.Select(x => x.ToString()).ToArray(), token)).Select(x => uint.Parse(x)).ToArray();

            uint[] unseenReviewIds = recentReviewIds.Except(seenReviewIds).ToArray();
            logger.LogInformation("Of which {0} are unseen", unseenReviewIds.Length);

            Review[] unseenReviews = reviews.Where(x => unseenReviewIds.Contains(x.Key))
                                     .Select(x => x.Value)
                                     .OrderBy(x => x.Created)
                                     .ToArray();

            foreach (Review unseenReview in unseenReviews)
            {
                var reviewContent = unseenReview.Comment.Truncate(512);

                string reviewUrl = $"https://steamcommunity.com/profiles/{unseenReview.Author.SteamId}/recommended/{appId}";

                logger.LogInformation("Posting review {0} to Slack", reviewUrl);

                TranslationResult translationResponse = null;
                try
                {
                    translationResponse = await translation.TranslateTextAsync(reviewContent, "en", null, null, token);
                }
                catch (GoogleApiException e)
                {
                    logger.LogError(e, "Encountered error translating review.");
                }

                var reviewFlags = new List <string>
                {
                    unseenReview.SteamPurchase ? "Steam Activation" : "Key Activation",
                    unseenReview.WrittenDuringEarlyAccess ? "Early Access" : "Released"
                };

                if (unseenReview.ReceivedForFree)
                {
                    reviewFlags.Add("Received for Free");
                }

                var fields = new List <Field>
                {
                    new Field
                    {
                        Title = $"Original Text ({translationResponse?.DetectedSourceLanguage ?? "unknown"})",
                        Value = reviewContent,
                        Short = false
                    },
                    new Field
                    {
                        Title = "Play Time Total",
                        Value = unseenReview.Author.PlayTimeForever.Humanize(),
                        Short = true
                    },
                    new Field
                    {
                        Title = "Play Time Last 2 Weeks",
                        Value = unseenReview.Author.PlayTimeLastTwoWeeks.Humanize(),
                        Short = true
                    },
                    new Field
                    {
                        Title = "Games Owned",
                        Value = unseenReview.Author.NumGamesOwned.ToString("N"),
                        Short = true
                    },
                    new Field
                    {
                        Title = "Type",
                        Value = string.Join(", ", reviewFlags)
                    }
                };

                if (translationResponse != null && translationResponse.DetectedSourceLanguage != "en")
                {
                    fields.Insert(1, new Field
                    {
                        Title = $"Auto-Translated Text",
                        Value = translationResponse.TranslatedText,
                        Short = false
                    });
                }

                await slack.IncomingWebHook(new IncomingWebHookRequest
                {
                    Username    = $"{product}",
                    Attachments = new List <Attachment>
                    {
                        new Attachment
                        {
                            AuthorIcon = "https://steamcommunity-a.akamaihd.net/public/shared/images/userreviews/" + (unseenReview.VotedUp ? "icon_thumbsUp.png" : "icon_thumbsDown.png"),
                            AuthorName = (unseenReview.VotedUp ? "Recommended" : "Not Recommended") + " (open review)",
                            AuthorLink = reviewUrl,
                            Fields     = fields
                        }
                    }
                }, token);

                logger.LogInformation("Inserting review {0} into DynamoDB", unseenReview.RecommendationId);
                await seenItemRepository.SetItemSeen(unseenReview.RecommendationId.ToString(), token);
            }

            logger.LogInformation("Finished posting reviews.");
        }