public async Task GetImageLeaderboardImplementationAsync(string image, string location, ServiceCategory?category, Division?division, Tier?tier, int pageNumber) { using (Context.Channel.EnterTypingState()) { if (!ScoreRetrievalService.Metadata.SupportsInexpensiveDetailQueries) { throw new InvalidOperationException("Image-specific queries cannot be performed on online score providers. Please use datasource to specify an offline score provider."); } System.Collections.Generic.IEnumerable <ScoreboardSummaryEntry> teams = (await ScoreRetrievalService.GetScoreboardAsync(new ScoreboardFilterInfo(division, tier)).ConfigureAwait(false))?.TeamList; if (teams == null) { throw new Exception("Error obtaining scoreboard."); } if (category.HasValue) { var catVal = category.Value; teams = teams.Where(t => t.Category == catVal); } if (location != null) { teams = teams.Where(t => t.Location == location); } string filterDesc = Utilities.JoinNonNullNonEmpty(", ", !division.HasValue ? null : division.Value.ToStringCamelCaseToSpace() + " Division", !tier.HasValue ? null : tier.Value.ToStringCamelCaseToSpace() + " Tier", !category.HasValue ? null : category.Value.ToCanonicalName(), LocationResolutionService.GetFullNameOrNull(location)); var downloadTasks = teams.Select(t => ScoreRetrievalService.GetDetailsAsync(t.TeamId)).ToArray(); try { await Task.WhenAll(downloadTasks).ConfigureAwait(false); } catch { // oh well? } await ReplyAsync( message : ScoreEmbedBuilder.CreateImageLeaderboardEmbed(downloadTasks.Where(t => t.IsCompletedSuccessfully).Select( t => new System.Collections.Generic.KeyValuePair <ScoreboardSummaryEntry, ScoreboardImageDetails>(t.Result.Summary, t.Result.Images.SingleOrDefault(i => i.ImageName.Equals(image, StringComparison.InvariantCultureIgnoreCase)))) .Where(kvp => kvp.Value != null).OrderByDescending(kvp => kvp.Value.Score).ThenBy(kvp => kvp.Value.PlayTime), filterDescription: filterDesc, pageNumber: pageNumber)).ConfigureAwait(false); } }