public async Task GetServiceLeaderboardImplementationAsync(string category, Tier?tier, int pageNumber) { using (Context.Channel.EnterTypingState()) { CompleteScoreboardSummary teamScore = await ScoreRetrievalService.GetScoreboardAsync(new ScoreboardFilterInfo(Division.AllService, tier)).ConfigureAwait(false); if (teamScore == null) { throw new Exception("Error obtaining scoreboard."); } // validate category string realCategory = teamScore.TeamList.Where(t => CategoryEquals(t, category)).Select(t => t.Category).Distinct().SingleIfOne(); if (realCategory == null) { throw new ArgumentException("The given category was not found - it was either ambiguous or invalid.", nameof(category)); } await ReplyAsync(ScoreEmbedBuilder.CreateTopLeaderboardEmbed(teamScore, pageNumber: pageNumber, customFilter: new ScoreboardMessageBuilderService.CustomFiltrationInfo() { Predicate = t => t.Category == realCategory, FilterDescription = realCategory }, timeZone: await Preferences.GetTimeZoneAsync(Context.Guild, Context.User).ConfigureAwait(false))).ConfigureAwait(false); } }
public async Task GetTeamWithPercentileAsync(double rank, DivisionWithCategory?divAndCat = null, Tier?tier = null) { using (Context.Channel.EnterTypingState()) { if (rank < 1) { throw new ArgumentOutOfRangeException(nameof(rank)); } var teams = await ScoreRetrievalService.GetScoreboardAsync(new ScoreboardFilterInfo(divAndCat?.Division, tier, divAndCat?.Category, null)).ConfigureAwait(false); // teams list in descending order int expectedIndex = ((int)Math.Round(((100 - rank) / 100) * teams.TeamList.Count)).Clamp(0, teams.TeamList.Count); ScoreboardDetails teamScore = await ScoreRetrievalService.GetDetailsAsync(teams.TeamList[expectedIndex].TeamId).ConfigureAwait(false); if (teamScore == null) { throw new Exception("Error obtaining team score."); } await ReplyAsync(string.Empty, embed : ScoreEmbedBuilder.CreateTeamDetailsEmbed(teamScore, completeScoreboard : await ScoreRetrievalService.GetScoreboardAsync(new ScoreboardFilterInfo(null, null)).ConfigureAwait(false), peerFilter : CompetitionRoundLogicService.GetPeerFilter(ScoreRetrievalService.Round, teamScore.Summary), timeZone : await Preferences.GetTimeZoneAsync(Context.Guild, Context.User).ConfigureAwait(false)).Build()).ConfigureAwait(false); } }
public async Task GetTeamAsync(TeamId teamId) { using (Context.Channel.EnterTypingState()) { ScoreboardDetails teamScore = await ScoreRetrievalService.GetDetailsAsync(teamId).ConfigureAwait(false); if (teamScore == null) { throw new Exception("Error obtaining team score."); } await ReplyAsync(string.Empty, embed : ScoreEmbedBuilder.CreateTeamDetailsEmbed(teamScore, CompetitionRoundLogicService.GetRankingInformation(ScoreRetrievalService.Round, await ScoreRetrievalService.GetScoreboardAsync(new ScoreboardFilterInfo(teamScore.Summary.Division, null)).ConfigureAwait(false), teamScore.Summary)).Build()).ConfigureAwait(false); } }
public async Task GetLeaderboardAsync(Division division, Tier tier, int pageNumber = 1) { using (Context.Channel.EnterTypingState()) { CompleteScoreboardSummary teamScore = await ScoreRetrievalService.GetScoreboardAsync(new ScoreboardFilterInfo(division, tier)).ConfigureAwait(false); if (teamScore == null) { throw new Exception("Error obtaining scoreboard."); } await ReplyAsync(ScoreEmbedBuilder.CreateTopLeaderboardEmbed(teamScore, pageNumber: pageNumber, timeZone: await Preferences.GetTimeZoneAsync(Context.Guild, Context.User).ConfigureAwait(false))).ConfigureAwait(false); } }
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); } }
public async Task GetTeamAsync(TeamId teamId) { using (Context.Channel.EnterTypingState()) { ScoreboardDetails teamScore = await ScoreRetrievalService.GetDetailsAsync(teamId).ConfigureAwait(false); if (teamScore == null) { throw new Exception("Error obtaining team score."); } await ReplyAsync(string.Empty, embed : ScoreEmbedBuilder.CreateTeamDetailsEmbed(teamScore, completeScoreboard : await ScoreRetrievalService.GetScoreboardAsync(ScoreboardFilterInfo.NoFilter).ConfigureAwait(false), peerFilter : CompetitionRoundLogicService.GetPeerFilter(ScoreRetrievalService.Round, teamScore.Summary), timeZone : await Preferences.GetTimeZoneAsync(Context.Guild, Context.User).ConfigureAwait(false)).Build()).ConfigureAwait(false); } }
public async Task GeneratePeerLeaderboardAsync(TeamId team) { using (Context.Channel.EnterTypingState()) { ScoreboardDetails teamDetails = await ScoreRetrievalService.GetDetailsAsync(team).ConfigureAwait(false); if (teamDetails == null) { throw new Exception("Error obtaining team score."); } CompleteScoreboardSummary peerScoreboard = await ScoreRetrievalService.GetScoreboardAsync(CompetitionRoundLogicService.GetPeerFilter(ScoreRetrievalService.Round, teamDetails.Summary)).ConfigureAwait(false); await ReplyAsync(ScoreEmbedBuilder.CreatePeerLeaderboardEmbed(teamDetails.TeamId, peerScoreboard, timeZone: await Preferences.GetTimeZoneAsync(Context.Guild, Context.User).ConfigureAwait(false))).ConfigureAwait(false); } }
public async Task GetLocationLeaderboardImplementationAsync(string location, ScoreboardFilterInfo filterInfo, int pageNumber) { using (Context.Channel.EnterTypingState()) { CompleteScoreboardSummary teamScore = await ScoreRetrievalService.GetScoreboardAsync(filterInfo).ConfigureAwait(false); if (teamScore == null) { throw new Exception("Error obtaining scoreboard."); } await ReplyAsync(ScoreEmbedBuilder.CreateTopLeaderboardEmbed(teamScore, pageNumber: pageNumber, customFilter: new ScoreboardMessageBuilderService.CustomFiltrationInfo() { Predicate = t => t.Location == location, FilterDescription = location // TODO full name of state? }, timeZone: await Preferences.GetTimeZoneAsync(Context.Guild, Context.User).ConfigureAwait(false))).ConfigureAwait(false); } }
public async Task GetTeamWithRankAsync(int rank, Division?division = null, Tier?tier = null) { using (Context.Channel.EnterTypingState()) { if (rank < 1) { throw new ArgumentOutOfRangeException(nameof(rank)); } var teams = await ScoreRetrievalService.GetScoreboardAsync(new ScoreboardFilterInfo(division, tier)).ConfigureAwait(false); var team = teams.TeamList[rank - 1]; ScoreboardDetails teamScore = await ScoreRetrievalService.GetDetailsAsync(team.TeamId).ConfigureAwait(false); if (teamScore == null) { throw new Exception("Error obtaining team score."); } await ReplyAsync(string.Empty, embed : ScoreEmbedBuilder.CreateTeamDetailsEmbed(teamScore, CompetitionRoundLogicService.GetRankingInformation(ScoreRetrievalService.Round, await ScoreRetrievalService.GetScoreboardAsync(new ScoreboardFilterInfo(teamScore.Summary.Division, null)).ConfigureAwait(false), teamScore.Summary)).Build()).ConfigureAwait(false); } }
public async Task GetTeamWithRankAsync(int rank, string location, DivisionWithCategory?divisionAndCat, Tier?tier) { using (Context.Channel.EnterTypingState()) { if (rank < 1) { throw new ArgumentOutOfRangeException(nameof(rank)); } var filter = new ScoreboardFilterInfo(divisionAndCat?.Division, tier, divisionAndCat?.Category, location); var teams = await ScoreRetrievalService.GetScoreboardAsync(filter).ConfigureAwait(false); System.Collections.Generic.IEnumerable <ScoreboardSummaryEntry> teamList = teams.TeamList; var team = teamList.Skip(rank - 1).First(); ScoreboardDetails teamScore = await ScoreRetrievalService.GetDetailsAsync(team.TeamId).ConfigureAwait(false); if (teamScore == null) { throw new Exception("Error obtaining team score."); } string classSpec = Utilities.JoinNonNullNonEmpty(", ", LocationResolutionService.GetFullNameOrNull(location), filter.Division.HasValue ? (filter.Division.Value.ToStringCamelCaseToSpace() + " Division") : null, filter.Category?.ToCanonicalName(), tier.HasValue ? (tier.Value.ToStringCamelCaseToSpace() + " Tier") : null); await ReplyAsync( "**" + Utilities.AppendOrdinalSuffix(rank) + " place " + (classSpec.Length == 0 ? "overall" : "in " + classSpec) + ": " + team.TeamId + "**", embed : ScoreEmbedBuilder.CreateTeamDetailsEmbed(teamScore, completeScoreboard : await ScoreRetrievalService.GetScoreboardAsync(new ScoreboardFilterInfo(null, null)).ConfigureAwait(false), peerFilter : CompetitionRoundLogicService.GetPeerFilter(ScoreRetrievalService.Round, team), timeZone : await Preferences.GetTimeZoneAsync(Context.Guild, Context.User).ConfigureAwait(false)).Build()).ConfigureAwait(false); } }