public async Task ListLeaderboardParticipants() { using (Context.Channel.EnterTypingState()) { try { _logger.LogInformation("Executing list"); var embeds = new List <Embed>(); var participants = await _participantService.GetAllParticipantsForServerAsync(Context.Guild.Id.ToString()); foreach (var participant in participants) { AthleteDetailed updatedAthleteData = null; try { updatedAthleteData = await _stravaService.GetAthlete(participant); } catch (Exception e) { _logger.LogError(e, $"Failed to fetch athlete while executing list command"); } embeds.Add(_embedBuilderService.BuildAthleteInfoEmbed(participant, updatedAthleteData)); } 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"); } } }
public async Task <IActionResult> GetAthlete() { HttpContext.Items.TryGetValue("access_token", out var accessToken); // TODO: put in another filter then link to ctrl prop? var response = await _stravaService.GetAthlete(accessToken.ToString()); var content = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { return(new BadRequestResult()); } var athlete = JsonConvert.DeserializeObject <Athlete>(content); return(new OkObjectResult(athlete)); }