public async Task ShowParticipantStats()
        {
            using (Context.Channel.EnterTypingState())
            {
                try
                {
                    var participant =
                        await _participantService
                        .GetParticipantOrDefault(Context.Guild.Id.ToString(), Context.User.Id.ToString());

                    if (participant == null)
                    {
                        await ReplyAsync("It seems like you're not part of the leaderboard. Try joining it.");
                    }

                    var start      = DateTime.Now.AddDays(-7);
                    var activities = await _stravaService.FetchActivitiesForParticipant(participant, start);

                    await ReplyAsync(embed : _embedBuilderService.BuildParticipantStatsForCategoryEmbed(participant,
                                                                                                        activities, Constants.LeaderboardRideType.RealRide, start, DateTime.Now));

                    await ReplyAsync(embed : _embedBuilderService.BuildParticipantStatsForCategoryEmbed(participant,
                                                                                                        activities, Constants.LeaderboardRideType.VirtualRide, start, DateTime.Now));
                }
                catch (Exception e)
                {
                    _logger.LogError(e, "stats failed");
                }
            }
        }
示例#2
0
        public async Task ShowParticipantStats()
        {
            using (Context.Channel.EnterTypingState())
            {
                try
                {
                    var participant = _participantService.GetParticipantOrDefault(Context.Guild.Id.ToString(), Context.User.Id.ToString());
                    if (participant == null)
                    {
                        await ReplyAsync("It seems like you're not part of the leaderboard. Try joining it.");

                        return;
                    }

                    var start = DateTime.Now.AddDays(-7);

                    var(policy, context) = _stravaAuthenticationService.GetUnauthorizedPolicy(participant.StravaId);
                    var activities = await policy.ExecuteAsync(x => _activityService.GetForStravaUser(participant.StravaId, start), context);

                    var participantWithActivities = new ParticipantWithActivities {
                        Participant = participant, Activities = activities
                    };

                    var realRideCategoryResult = _leaderboardService.GetTopResultsForCategory(
                        new List <ParticipantWithActivities> {
                        participantWithActivities
                    },
                        new RealRideCategory());

                    await ReplyAsync(embed : _embedBuilderService.BuildParticipantStatsForCategoryEmbed(realRideCategoryResult,
                                                                                                        $"'{new RealRideCategory().Name}' leaderboard for '{start:yyyy MMMM dd} - {DateTime.Now:yyyy MMMM dd}'"));

                    var virtualRideCategoryResult = _leaderboardService.GetTopResultsForCategory(
                        new List <ParticipantWithActivities> {
                        participantWithActivities
                    },
                        new VirtualRideCategory());

                    await ReplyAsync(embed : _embedBuilderService.BuildParticipantStatsForCategoryEmbed(virtualRideCategoryResult,
                                                                                                        $"'{new VirtualRideCategory().Name}' leaderboard for '{start:yyyy MMMM dd} - {DateTime.Now:yyyy MMMM dd}'"));
                }
                catch (Exception e)
                {
                    _logger.LogError(e, "stats failed");
                }
            }
        }