Skip to content

Commit 17c1641

Browse files
committed
Add getScores()
1 parent 898aaf7 commit 17c1641

File tree

6 files changed

+50
-3
lines changed

6 files changed

+50
-3
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
branches:
88
- "**"
99
schedule:
10-
- cron: "45 10 12,24 * *"
10+
- cron: "45 10 * * 1"
1111

1212
jobs:
1313
build:

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ async function getSelf() {
152152
getSelf()
153153
```
154154

155+
If you're looking for an example that involves WebSockets, you might wanna take a look at `lib/tests/websocket.ts` in the package's repository!
156+
155157
### Calling the functions, but literally
156158

157159
This package's functions can be accessed both through the api object and through namespaces! It essentially means that for convenience's sake, there are two ways to do anything:
@@ -258,7 +260,7 @@ In the same order as on [the API's official documentation](https://osu.ppy.sh/do
258260
- `GET /spotlights` -> [getSpotlights()](https://osu-v2.taevas.xyz/classes/API.html#getspotlights)
259261

260262
### Scores
261-
- `GET /scores` -> TODO
263+
- `GET /scores` -> [getScores()](https://osu-v2.taevas.xyz/classes/API.html#getscores)
262264

263265
### Under "Undocumented" or missing from docs
264266
- `GET /seasonal-backgrounds` -> [getSeasonalBackgrounds()](https://osu-v2.taevas.xyz/classes/API.html#getseasonalbackgrounds)

lib/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,9 @@ export class API {
742742

743743
// SCORE STUFF
744744

745+
/** {@inheritDoc Score.getSome} @group Score Methods */
746+
readonly getScores = Score.getSome
747+
745748
/** {@inheritDoc Score.getReplay} @group Score Methods */
746749
readonly getReplay = Score.getReplay
747750

lib/namespaces/Score.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { API, Beatmap, Beatmapset, Changelog, Mod, Ruleset, User } from "../index.js"
1+
import { API, Beatmap, Beatmapset, Changelog, Miscellaneous, Mod, Ruleset, User } from "../index.js"
22

33
/** @obtainableFrom {@link API.getBeatmapUserScores} */
44
export interface Score {
@@ -97,6 +97,17 @@ export namespace Score {
9797
beatmap: Beatmap.Extended
9898
}
9999

100+
/**
101+
* Get up to the 1000 (!!) most recent scores!
102+
* @param config Specify the ruleset as a filter, or use a cursor_string to get even more scores
103+
* @remarks You may get less than 1000 scores
104+
*/
105+
export async function getSome(this: API, config?: Pick<Miscellaneous.Config, "cursor_string"> & {
106+
ruleset?: keyof typeof Ruleset
107+
}): Promise<{scores: Score[], cursor_string: Miscellaneous.CursorString}> {
108+
return await this.request("get", ["scores"], {...config})
109+
}
110+
100111
/**
101112
* Get the replay for a score!
102113
* @scope {@link Scope"public"}

lib/tests/guest.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import * as Match from "./guest/match.test.js"
1313
import * as Miscellaneous from "./guest/miscellaneous.test.js"
1414
import * as Multiplayer from "./guest/multiplayer.test.js"
1515
import * as News from "./guest/news.test.js"
16+
import * as Score from "./guest/score.test.js"
1617
import * as Spotlight from "./guest/spotlight.test.js"
1718
import * as User from "./guest/user.test.js"
1819
import * as Wiki from "./guest/wiki.test.js"
@@ -30,6 +31,7 @@ const domains: Test[][] = [
3031
Miscellaneous.tests,
3132
Multiplayer.tests,
3233
News.tests,
34+
Score.tests,
3335
Spotlight.tests,
3436
User.tests,
3537
Wiki.tests,

lib/tests/guest/score.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { expect } from "chai"
2+
import { validate, Test } from "../exports.js"
3+
import { Ruleset } from "../../index.js"
4+
5+
const getScores: Test = async(api) => {
6+
const scores = await api.getScores()
7+
expect(scores.cursor_string).to.be.a("string")
8+
expect(scores.scores.length).to.be.greaterThan(0)
9+
expect(validate(scores.scores, "Score")).to.be.true
10+
11+
console.log("|", "With cursor_string")
12+
const scores_cursor = await api.getScores({cursor_string: scores.cursor_string})
13+
expect(scores_cursor.cursor_string).to.be.a("string")
14+
expect(scores_cursor.scores.length).to.be.greaterThan(0)
15+
expect(validate(scores_cursor.scores, "Score")).to.be.true
16+
17+
console.log("|", "With ruleset")
18+
const scores_ruleset = await api.getScores({ruleset: "fruits"})
19+
expect(scores_ruleset.cursor_string).to.be.a("string")
20+
expect(scores_ruleset.scores.length).to.be.greaterThan(0)
21+
scores_ruleset.scores.forEach((s) => expect(s.ruleset_id).to.equal(Ruleset.fruits))
22+
expect(validate(scores_ruleset.scores, "Score")).to.be.true
23+
24+
return true
25+
}
26+
27+
export const tests = [
28+
getScores,
29+
]

0 commit comments

Comments
 (0)