Skip to content

Commit

Permalink
Fix orderby on topplays sort
Browse files Browse the repository at this point in the history
  • Loading branch information
minisbett committed Jan 1, 2024
1 parent 2282c10 commit 8de1764
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions huisbot/Embeds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public static Embed ScoreAliases(ScoreAlias[] aliases)

// Build the alias string.
string aliasesStr = "*There are no score aliases. You can add some via `/alias score add`.*";
if (aliases.Length > 0)
if (aliases.Length > 0)
{
aliasesStr = "";
foreach (IGrouping<long, ScoreAlias> group in aliases.GroupBy(x => x.ScoreId))
Expand Down Expand Up @@ -325,14 +325,15 @@ public static Embed ScoreRankings(HuisScore[] allScores, HuisRework rework, Sort
public static Embed TopPlays(OsuUser user, HuisScore[] allScores, HuisRework rework, Sort sort, int page)
{
// Apply the sorting to the scores, since this is done inside the browser on Huis and has no API parameter.
HuisScore[] sortedScores = sort switch
Func<HuisScore, double> selector = sort.Code switch
{
{ Code: "live_pp" } => allScores.OrderBy(x => x.LivePP).ToArray(),
{ Code: "pp_diff", IsAscending: false } => allScores.OrderByDescending(x => x.LocalPP - x.LivePP).ToArray(),
{ Code: "pp_diff", IsAscending: true } => allScores.OrderBy(x => x.LocalPP - x.LivePP).ToArray(),
_ => allScores.OrderBy(x => x.LocalPP).ToArray()
"live_pp" => x => x.LivePP,
"pp_diff" => x => x.LocalPP - x.LivePP,
_ => x => x.LocalPP
};

HuisScore[] sortedScores = (sort.IsAscending ? allScores.OrderBy(selector) : allScores.OrderByDescending(selector)).ToArray();

// Get the scores to be displayed.
HuisScore[] scores = sortedScores.Skip((page - 1) * 10).Take(10).ToArray();

Expand Down
2 changes: 1 addition & 1 deletion huisbot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Program
/// <summary>
/// The version of the application.
/// </summary>
public const string VERSION = "1.6.0";
public const string VERSION = "1.6.1";

/// <summary>
/// The startup time of the application.
Expand Down

0 comments on commit 8de1764

Please sign in to comment.