Implement getUserMostPlayed from osu!api

This commit is contained in:
Stedoss 2024-11-16 15:46:14 +00:00
parent 7886e509dd
commit e06b5f3c7c
2 changed files with 24 additions and 0 deletions

View File

@ -294,6 +294,24 @@ class OsuApi(
} }
} }
fun getUserMostPlayed(userId: Int, limit: Int? = null, offset: Int? = null): List<OsuApiModels.BeatmapPlaycount>? {
val queryParams = mapOf(
"limit" to limit,
"offset" to offset,
)
val response = this.doRequest("https://osu.ppy.sh/api/v2/users/$userId/beatmapsets/most_played/?", queryParams)
if (response == null) {
this.logger.info("Error getting user most played ($userId)")
return null
}
return when (response.statusCode()) {
200 -> serializer.decodeFromString<List<OsuApiModels.BeatmapPlaycount>>(response.body())
else -> null
}
}
var rateLimitRemaining: Long = 0L var rateLimitRemaining: Long = 0L
var rateLimitTotal: Long = 0L var rateLimitTotal: Long = 0L

View File

@ -232,4 +232,10 @@ class OsuApiModels {
val content: String val content: String
) )
@Serializable
data class BeatmapPlaycount(
val beatmap_id: Int,
val count: Int,
)
} }