From 3ea33f949dfdf50b27c7eedecece1b3dad731fb2 Mon Sep 17 00:00:00 2001 From: minisbett <39670899+minisbett@users.noreply.github.com> Date: Sat, 27 Jul 2024 20:07:50 +0200 Subject: [PATCH] update osu api service to process lazer score ids instead --- huisbot/Modules/Alias.cs | 2 +- huisbot/Modules/Huis/Simulate.cs | 2 +- huisbot/Modules/ModuleBase.cs | 4 ++-- huisbot/Services/OsuApiService.cs | 20 +++++--------------- 4 files changed, 9 insertions(+), 19 deletions(-) diff --git a/huisbot/Modules/Alias.cs b/huisbot/Modules/Alias.cs index 14c14b9..f43a86b 100644 --- a/huisbot/Modules/Alias.cs +++ b/huisbot/Modules/Alias.cs @@ -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; diff --git a/huisbot/Modules/Huis/Simulate.cs b/huisbot/Modules/Huis/Simulate.cs index c065b02..dd3044a 100644 --- a/huisbot/Modules/Huis/Simulate.cs +++ b/huisbot/Modules/Huis/Simulate.cs @@ -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; diff --git a/huisbot/Modules/ModuleBase.cs b/huisbot/Modules/ModuleBase.cs index e571534..4fc158a 100644 --- a/huisbot/Modules/ModuleBase.cs +++ b/huisbot/Modules/ModuleBase.cs @@ -299,7 +299,7 @@ public async Task QueuePlayerAsync(OsuUser player, int reworkId, ulong dis /// /// An identifier for the score. (Score ID or alias) /// The score. - public async Task GetScoreAsync(int rulesetId, string scoreId) + public async Task GetScoreAsync(string scoreId) { // If the identifier is not a number, try to find a score alias. if (!scoreId.All(char.IsDigit)) @@ -315,7 +315,7 @@ public async Task 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? score = await _osu.GetScoreAsync(rulesetId, long.Parse(scoreId)); + NotFoundOr? 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) diff --git a/huisbot/Services/OsuApiService.cs b/huisbot/Services/OsuApiService.cs index 3380b1c..69cd379 100644 --- a/huisbot/Services/OsuApiService.cs +++ b/huisbot/Services/OsuApiService.cs @@ -198,30 +198,20 @@ public async Task EnsureAccessTokenAsync() } /// - /// Returns the score with the specified ID in the specified ruleset. + /// Returns the score with the specified ID. /// - /// The ruleset ID. /// The score ID. /// The score with the specified ID./returns> - public async Task?> GetScoreAsync(int rulesetId, long scoreId) + public async Task?> 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.NotFound; @@ -231,8 +221,8 @@ public async Task 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; } }