Add ability to get a beatmap from osu!api from ID

This commit is contained in:
Stedoss 2024-11-18 01:30:56 +00:00
parent e0cabfefcf
commit 7d44e4014b

View File

@ -137,6 +137,19 @@ class OsuApi(
} }
} }
fun getBeatmapFromId(beatmapId: Int): OsuApiModels.Beatmap? {
val response = doRequest("https://osu.ppy.sh/api/v2/beatmaps/$beatmapId", emptyMap())
if (response == null) {
this.logger.info("Error loading beatmap $beatmapId")
return null
}
return when (response.statusCode()) {
200 -> serializer.decodeFromString<OsuApiModels.Beatmap>(response.body())
else -> null
}
}
/** /**
* Retrieves the replay data for a given score ID from the osu!api. * Retrieves the replay data for a given score ID from the osu!api.
* Efficiently cycles through the API keys to avoid rate limiting. * Efficiently cycles through the API keys to avoid rate limiting.
@ -215,7 +228,7 @@ class OsuApi(
} }
fun getUserBeatmapScores(userId: Long, beatmapId: Int): OsuApiModels.BeatmapScores? { fun getUserBeatmapScores(userId: Long, beatmapId: Int): OsuApiModels.BeatmapScores? {
val response = doRequest("https://osu.ppy.sh/api/v2/beatmaps/$beatmapId/scores/users/$userId/all", mapOf()) val response = doRequest("https://osu.ppy.sh/api/v2/beatmaps/$beatmapId/scores/users/$userId/all", emptyMap())
if(response == null) { if(response == null) {
this.logger.info("Error getting scores on beatmap $beatmapId for user $userId") this.logger.info("Error getting scores on beatmap $beatmapId for user $userId")
@ -249,7 +262,7 @@ class OsuApi(
} }
fun checkIfUserBanned(userId: Long): Boolean? { fun checkIfUserBanned(userId: Long): Boolean? {
val response = this.doRequest("https://osu.ppy.sh/api/v2/users/$userId/osu?key=id", mapOf()) val response = this.doRequest("https://osu.ppy.sh/api/v2/users/$userId/osu?key=id", emptyMap())
if(response == null) { if(response == null) {
this.logger.info("Error loading user with userId = $userId") this.logger.info("Error loading user with userId = $userId")
return null return null