예제 #1
0
        public async Task ListLeaderboardParticipants()
        {
            using (Context.Channel.EnterTypingState())
            {
                try
                {
                    _logger.LogInformation("Executing list");
                    var embeds       = new List <Embed>();
                    var participants = _participantService.GetAllParticipantsForServerAsync(Context.Guild.Id.ToString());
                    foreach (var participant in participants)
                    {
                        var(policy, context) = _stravaAuthenticationService.GetUnauthorizedPolicy(participant.StravaId);
                        try
                        {
                            var athlete = await policy.ExecuteAsync(x => _athleteService.Get(participant.StravaId), context);

                            embeds.Add(_embedBuilderService.BuildAthleteInfoEmbed(participant, athlete));
                        }
                        catch (ApiException e)
                        {
                            _logger.LogWarning(e, $"Failed to fetch athlete info for {participant.DiscordUserId}");
                        }
                    }

                    if (!embeds.Any())
                    {
                        embeds.Add(
                            new EmbedBuilder()
                            .WithTitle("No participants found")
                            .WithCurrentTimestamp()
                            .Build()
                            );
                    }

                    foreach (var embed in embeds)
                    {
                        await ReplyAsync(embed : embed);
                    }
                }
                catch (Exception e)
                {
                    _logger.LogError(e, "list failed");
                }
            }
        }