Skip to content

Commit

Permalink
Merge pull request #18 from minisbett/master
Browse files Browse the repository at this point in the history
release: version 2.3.1
  • Loading branch information
minisbett authored Jul 28, 2024
2 parents 52ab11a + 3ea33f9 commit 293dcee
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 47 deletions.
10 changes: 10 additions & 0 deletions huisbot/Models/Huis/HuisRework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,14 @@ public string RulesetName
_ => "Unknown"
};
}

public override int GetHashCode()
{
return Id.GetHashCode();
}

public override bool Equals(object? obj)
{
return obj is HuisRework rework && Id == rework.Id;
}
}
2 changes: 1 addition & 1 deletion huisbot/Modules/Alias.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public async Task HandleAddAsync(
}

// Get the score.
OsuScore? score = await GetScoreAsync(0 /* TODO: Support for other rulsets */, scoreId.ToString());
OsuScore? score = await GetScoreAsync(scoreId.ToString());
if (score is null)
return;

Expand Down
6 changes: 3 additions & 3 deletions huisbot/Modules/Huis/Simulate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public async Task HandleAsync(
// If a score was specified, get the score and fill the unset parameters with it's attributes.
if (scoreId is not null)
{
OsuScore? score = await GetScoreAsync(rework.RulesetId, scoreId);
OsuScore? score = await GetScoreAsync(scoreId);
if (score is null)
return;

Expand Down Expand Up @@ -104,7 +104,7 @@ public async Task HandleAsync(
};

// Display the simulation progress in an embed to the user.
IUserMessage msg = await FollowupAsync(embed: Embeds.Simulating(rework, refRework, false, rework.Id == refRework.Id));
IUserMessage msg = await FollowupAsync(embed: Embeds.Simulating(rework, refRework, false, rework == refRework));

// Get the local result from the Huis API and check whether it was successful.
HuisSimulationResponse? localScore = await SimulateScoreAsync(request);
Expand All @@ -113,7 +113,7 @@ public async Task HandleAsync(

// If the requested rework is the same as the reference, simulation is done here.
HuisSimulationResponse? refScore = localScore;
if (rework.Id != refRework.Id)
if (rework != refRework)
{
// Switch the request to target the reference rework and update the simulation progress embed.
request.Rework = refRework;
Expand Down
4 changes: 2 additions & 2 deletions huisbot/Modules/ModuleBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public async Task<bool> QueuePlayerAsync(OsuUser player, int reworkId, ulong dis
/// </summary>
/// <param name="scoreId">An identifier for the score. (Score ID or alias)</param>
/// <returns>The score.</returns>
public async Task<OsuScore?> GetScoreAsync(int rulesetId, string scoreId)
public async Task<OsuScore?> GetScoreAsync(string scoreId)
{
// If the identifier is not a number, try to find a score alias.
if (!scoreId.All(char.IsDigit))
Expand All @@ -315,7 +315,7 @@ public async Task<bool> QueuePlayerAsync(OsuUser player, int reworkId, ulong dis
scoreId = alias.ScoreId.ToString();
}
// Get the score from the osu! API. If it failed or the score was not found, notify the user.
NotFoundOr<OsuScore>? score = await _osu.GetScoreAsync(rulesetId, long.Parse(scoreId));
NotFoundOr<OsuScore>? score = await _osu.GetScoreAsync(long.Parse(scoreId));
if (score is null)
await ModifyOriginalResponseAsync(x => x.Embed = Embeds.InternalError("Failed to get the score from the osu! API."));
else if (!score.Found)
Expand Down
6 changes: 4 additions & 2 deletions huisbot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
using Newtonsoft.Json;
using System.Globalization;

namespace huisbot;

public class Program
{
/// <summary>
/// The version of the application.
/// </summary>
public const string VERSION = "2.3.0";
public const string VERSION = "2.3.1";

/// <summary>
/// The startup time of the application.
Expand Down Expand Up @@ -172,4 +174,4 @@ public static async Task MainAsync(string[] args)
// Run the host.
await host.RunAsync();
}
}
}
20 changes: 5 additions & 15 deletions huisbot/Services/OsuApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,30 +198,20 @@ public async Task<bool> EnsureAccessTokenAsync()
}

/// <summary>
/// Returns the score with the specified ID in the specified ruleset.
/// Returns the score with the specified ID.
/// </summary>
/// <param name="rulesetId">The ruleset ID.</param>
/// <param name="scoreId">The score ID.</param>
/// <returns>The score with the specified ID./returns>
public async Task<NotFoundOr<OsuScore>?> GetScoreAsync(int rulesetId, long scoreId)
public async Task<NotFoundOr<OsuScore>?> GetScoreAsync(long scoreId)
{
// Make sure a valid access token exists. If not, return null.
if (!await EnsureAccessTokenAsync())
return null;

// Get the string version of the ruleset ID.
string ruleset = rulesetId switch
{
1 => "taiko",
2 => "fruits",
3 => "mania",
_ => "osu"
};

try
{
// Get the score from the API and check whether a 404 was returned. If so, the score was not found.
HttpResponseMessage response = await _http.GetAsync($"api/v2/scores/{ruleset}/{scoreId}");
HttpResponseMessage response = await _http.GetAsync($"api/v2/scores/{scoreId}");
if (response.StatusCode == HttpStatusCode.NotFound)
return NotFoundOr<OsuScore>.NotFound;

Expand All @@ -231,8 +221,8 @@ public async Task<bool> EnsureAccessTokenAsync()
}
catch (Exception ex)
{
_logger.LogError("Failed to get the score with ID {Id} in ruleset {Ruleset} from the osu! API: {Message}",
scoreId, rulesetId, ex.Message);
_logger.LogError("Failed to get the score with ID {Id} from the osu! API: {Message}",
scoreId, ex.Message);
return null;
}
}
Expand Down
50 changes: 26 additions & 24 deletions huisbot/Utilities/Discord/Embeds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public static Embed Info(bool osuV1Available, bool osuV2Available, bool huisAvai
public static Embed Simulating(HuisRework local, HuisRework reference, bool localDone, bool localOnly = false)
{
// Build the status string.
string status = localDone ? "*Calculating reference score...*" : "*Calculating local score...*";
string status = localDone ? "*Calculating reference score...*" : "*Calculating local score...*";
status += $"\n\n{new DEmoji(localDone ? "" : "")} {local.Name}";
if (!localOnly)
status += $"\n{new DEmoji(localDone ? "" : "🕐")} {reference.Name}";
Expand All @@ -195,24 +195,29 @@ public static Embed Simulating(HuisRework local, HuisRework reference, bool loca
/// <summary>
/// Returns an embed for displaying the difference between two simulated scores.
/// </summary>
/// <param name="local">The first simulated score for comparison.</param>
/// <param name="live">The second simulated for score for comparison.</param>
/// <param name="local">The local simulated score for comparison.</param>
/// <param name="reference">The simulated reference for score for comparison.</param>
/// <param name="rework">The rework.</param>
/// <param name="beatmap">The beatmap.</param>
/// <returns>An embed for displaying a calculated score</returns>
public static Embed SimulatedScore(HuisSimulationResponse local, HuisSimulationResponse live, HuisRework rework, HuisRework referenceRework, OsuBeatmap beatmap)
/// <returns>An embed for displaying a the simulated score in comparison to the reference score.</returns>
public static Embed SimulatedScore(HuisSimulationResponse local, HuisSimulationResponse reference, HuisRework rework, HuisRework refRework, OsuBeatmap beatmap)
{
// Construct the PP info string.
string ppStr = $"▸ **PP**: {GetPPDifferenceText(live.PerformanceAttributes.PP, local.PerformanceAttributes.PP)}";
ppStr += $"\n▸ **Aim**: {GetPPDifferenceText(live.PerformanceAttributes.AimPP, local.PerformanceAttributes.AimPP)}";
ppStr += $"\n▸ **Tap**: {GetPPDifferenceText(live.PerformanceAttributes.TapPP, local.PerformanceAttributes.TapPP)}";
ppStr += $"\n▸ **Acc**: {GetPPDifferenceText(live.PerformanceAttributes.AccPP, local.PerformanceAttributes.AccPP)}";
string ppStr = $"▸ **PP**: {GetPPDifferenceText(reference.PerformanceAttributes.PP, local.PerformanceAttributes.PP)}";
ppStr += $"\n▸ **Aim**: {GetPPDifferenceText(reference.PerformanceAttributes.AimPP, local.PerformanceAttributes.AimPP)}";
ppStr += $"\n▸ **Tap**: {GetPPDifferenceText(reference.PerformanceAttributes.TapPP, local.PerformanceAttributes.TapPP)}";
ppStr += $"\n▸ **Acc**: {GetPPDifferenceText(reference.PerformanceAttributes.AccPP, local.PerformanceAttributes.AccPP)}";
if (local.PerformanceAttributes.FLPP is not null)
ppStr += $"\n▸ **FL**: {GetPPDifferenceText(live.PerformanceAttributes.FLPP ?? 0, local.PerformanceAttributes.FLPP.Value)}";
ppStr += $"\n▸ **FL**: {GetPPDifferenceText(reference.PerformanceAttributes.FLPP ?? 0, local.PerformanceAttributes.FLPP.Value)}";
if (local.PerformanceAttributes.CogPP is not null)
ppStr += $"\n▸ **Cog**: {GetPPDifferenceText(live.PerformanceAttributes.CogPP ?? 0, local.PerformanceAttributes.CogPP.Value)}";
ppStr += $"\n▸ **Cog**: {GetPPDifferenceText(reference.PerformanceAttributes.CogPP ?? 0, local.PerformanceAttributes.CogPP.Value)}";

// Construct some more strings for the embed.
double refDiff = reference.DifficultyAttributes.DifficultyRating;
double localDiff = local.DifficultyAttributes.DifficultyRating;
string comparison1 = localDiff == refDiff ? localDiff.ToString("N2") : $"{refDiff:N2}{localDiff:N2}";
string comparison2 = rework == refRework ? "PP Overview" : "PP Comparison (Ref → Local)";
string comparison3 = rework == refRework ? rework.Name! : $"{refRework.Name}{rework.Name}";
string hits = $"{local.Score.Statistics.Count300} {_emojis["300"]} {local.Score.Statistics.Count100} {_emojis["100"]} {local.Score.Statistics.Count50} {_emojis["50"]} {local.Score.Statistics.Misses} {_emojis["miss"]}";
string combo = $"{local.Score.MaxCombo}/{beatmap.MaxCombo}x";
string stats1 = $"{beatmap.CircleCount} {_emojis["circles"]} {beatmap.SliderCount} {_emojis["sliders"]} {beatmap.SpinnerCount} {_emojis["spinners"]}";
Expand All @@ -227,12 +232,12 @@ public static Embed SimulatedScore(HuisSimulationResponse local, HuisSimulationR

return BaseEmbed
.WithColor(new Color(0x4061E9))
.WithTitle($"{beatmap.Artist} - {beatmap.Title} [{beatmap.Version}]{local.Score.Mods.PlusString} ({live.DifficultyAttributes.DifficultyRating:N2}{local.DifficultyAttributes.DifficultyRating:N2}★)")
.AddField("PP Comparison (Reference → Local)", $"{ppStr}\n\n{visualizer}{osu}\n{huisRework}{github}", true)
.WithTitle($"{beatmap.Artist} - {beatmap.Title} [{beatmap.Version}]{local.Score.Mods.PlusString} ({comparison1}★)")
.AddField(comparison2, $"{ppStr}\n\n{visualizer}{osu}\n{huisRework}{github}", true)
.AddField("Score Info", $"{local.Score.Accuracy:N2}% ▸ {combo}\n{hits}\n{stats1}\n{stats2}\n{stats3}\n{stats4}", true)
.WithUrl($"https://osu.ppy.sh/b/{beatmap.Id}")
.WithImageUrl($"https://assets.ppy.sh/beatmaps/{beatmap.SetId}/covers/[email protected]")
.WithFooter($"{referenceRework.Name}{rework.Name}{BaseEmbed.Footer.Text}", BaseEmbed.Footer.IconUrl)
.WithFooter($"{comparison3}{BaseEmbed.Footer.Text}", BaseEmbed.Footer.IconUrl)
.Build();
}

Expand Down Expand Up @@ -479,19 +484,16 @@ public static Embed Feedback(IUser user, HuisRework rework, string text) => Base
/// <returns>A string representing the difference between two PP values.</returns>
private static string GetPPDifferenceText(double oldPP, double newPP)
{
// Round the PP values if they're above 1000, as that's irrelevant info and hurts the display flexibility.
if (oldPP >= 1000)
oldPP = Math.Round(oldPP);
if (newPP >= 1000)
newPP = Math.Round(newPP);

// Calculate the difference between the two PP values. If it's less than 0.01, the PP values are the same.
double difference = newPP - oldPP;
if (Math.Abs(difference) < 0.01)
// Round the PP values, as decimals are irrelevant info and hurts the display flexibility.
oldPP = Math.Round(oldPP);
newPP = Math.Round(newPP);

// If the PP do not differ, simply return the PP value.
if (newPP == oldPP)
return $"**{newPP:0.##}pp**";

// Otherwise return the difference string.
return $"{oldPP:0.##} → **{newPP:0.##}pp** *({difference:+#,##0.##;-#,##0.##}pp)*";
return $"{oldPP:0.##}pp → **{newPP:0.##}pp** ({newPP - oldPP:+#,##0.##;-#,##0.##}pp)";
}

/// <summary>
Expand Down

0 comments on commit 293dcee

Please sign in to comment.