Skip to content

Commit

Permalink
Tests and some more docs for Multiplayer stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
TTTaevas committed Nov 11, 2023
1 parent 998f8a8 commit 0a6baf9
Show file tree
Hide file tree
Showing 26 changed files with 173 additions and 96 deletions.
14 changes: 14 additions & 0 deletions docs/assets/highlight.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
--dark-hl-4: #B5CEA8;
--light-hl-5: #A31515;
--dark-hl-5: #CE9178;
--light-hl-6: #0000FF;
--dark-hl-6: #569CD6;
--light-hl-7: #0070C1;
--dark-hl-7: #4FC1FF;
--light-code-background: #FFFFFF;
--dark-code-background: #1E1E1E;
}
Expand All @@ -22,6 +26,8 @@
--hl-3: var(--light-hl-3);
--hl-4: var(--light-hl-4);
--hl-5: var(--light-hl-5);
--hl-6: var(--light-hl-6);
--hl-7: var(--light-hl-7);
--code-background: var(--light-code-background);
} }

Expand All @@ -32,6 +38,8 @@
--hl-3: var(--dark-hl-3);
--hl-4: var(--dark-hl-4);
--hl-5: var(--dark-hl-5);
--hl-6: var(--dark-hl-6);
--hl-7: var(--dark-hl-7);
--code-background: var(--dark-code-background);
} }

Expand All @@ -42,6 +50,8 @@
--hl-3: var(--light-hl-3);
--hl-4: var(--light-hl-4);
--hl-5: var(--light-hl-5);
--hl-6: var(--light-hl-6);
--hl-7: var(--light-hl-7);
--code-background: var(--light-code-background);
}

Expand All @@ -52,6 +62,8 @@
--hl-3: var(--dark-hl-3);
--hl-4: var(--dark-hl-4);
--hl-5: var(--dark-hl-5);
--hl-6: var(--dark-hl-6);
--hl-7: var(--dark-hl-7);
--code-background: var(--dark-code-background);
}

Expand All @@ -61,4 +73,6 @@
.hl-3 { color: var(--hl-3); }
.hl-4 { color: var(--hl-4); }
.hl-5 { color: var(--hl-5); }
.hl-6 { color: var(--hl-6); }
.hl-7 { color: var(--hl-7); }
pre, code { background: var(--code-background); }
2 changes: 1 addition & 1 deletion docs/assets/search.js

Large diffs are not rendered by default.

101 changes: 65 additions & 36 deletions docs/classes/API.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/classes/APIError.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/enums/Rulesets.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/functions/generateAuthorizationURL.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/index.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/Beatmap.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/interfaces/BeatmapExtended.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/BeatmapUserScore.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/Beatmapset.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/BeatmapsetExtended.html

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions docs/interfaces/ChangelogBuild.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/KudosuHistory.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/Leader.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/MultiplayerScore.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/PlaylistItem.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/Room.html

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions docs/interfaces/Score.html

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions docs/interfaces/UpdateStream.html

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions docs/interfaces/User.html

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions docs/interfaces/UserExtended.html

Large diffs are not rendered by default.

20 changes: 12 additions & 8 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ export class API {

/**
* Get extensive beatmapset data about whichever beatmapset you want!
* @param beatmap An object with the id of the beatmapset you're trying to get
* @param beatmapset An object with the id of the beatmapset you're trying to get
*/
async getBeatmapset(beatmapset: {id: number} | Beatmapset): Promise<BeatmapsetExtended> {
const response = await this.request("get", `beatmapsets/${beatmapset.id}`)
Expand Down Expand Up @@ -485,13 +485,18 @@ export class API {

// MULTIPLAYER STUFF

/**
* Get data about a lazer multiplayer room (realtime or playlists)!
* @param room An object with the id of the room, is at the end of its URL (after `/multiplayer/rooms/`)
*/
async getRoom(room: {id: number} | Room): Promise<Room> {
const response = await this.request("get", `rooms/${room.id}`)
return correctType(response) as Room
}

/**
* Get room data for each room fitting the given criterias
* Get rooms that are active, that have ended, that the user participated in, that the user made, or just simply any room!
* @param mode Self-explanatory enough, defaults to `active`
* @scope public
*/
async getRooms(mode: "active" | "all" | "ended" | "participated" | "owned" = "active"): Promise<Room[]> {
Expand All @@ -500,7 +505,8 @@ export class API {
}

/**
* Get the room stats of a user from the room, for each user of that room
* Get the room stats of all the users of that room!
* @param room An object with the id of the room in question
* @scope public
*/
async getRoomLeaderboard(room: {id: number} | Room): Promise<Leader[]> {
Expand All @@ -509,8 +515,7 @@ export class API {
}

/**
* Get the scores on a specific item of a room
* @scope public
* Get the scores on a specific item of a room, for a maximum of 50!
* @remarks (2023-11-10) Items are broken for multiplayer (real-time) rooms, not for playlists (like spotlights), that's an osu! bug
* https://github.com/ppy/osu-web/issues/10725
*/
Expand All @@ -520,7 +525,7 @@ export class API {
}

/**
* @remarks For multiplayer lobbies from the stable (non-lazer) client, with URLs having `community/matches` or `mp`
* Get data of a multiplayer lobby from the stable (non-lazer) client that have URLs with `community/matches` or `mp`
* @param id Can be found at the end of the URL of said match
*/
async getMatch(id: number): Promise<Match> {
Expand All @@ -529,8 +534,7 @@ export class API {
}

/**
* Gets the info of the 50 most recently created matches, descending order (most recent is at index 0)
* @remarks For multiplayer lobbies from the stable (non-lazer) client, with URLs having `community/matches` or `mp`
* Gets the info of the 50 most recently created stable (non-lazer) matches, descending order (most recent is at index 0)
*/
async getMatches(): Promise<MatchInfo[]> {
const response = await this.request("get", "matches")
Expand Down
19 changes: 19 additions & 0 deletions lib/tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,25 @@ const testChangelogStuff = async (): Promise<boolean> => {
const testMultiplayerStuff = async (): Promise<boolean> => {
let okay = true

let d1 = await <Promise<ReturnType<typeof api.getRoom> | false>>attempt("\ngetRoom (realtime): ", api.getRoom({id: 231069}))
if (!isOk(d1, !d1 || (d1.recent_participants.length === 4))) okay = false
let d2 = await <Promise<ReturnType<typeof api.getRoom> | false>>attempt("getRoom (playlist): ", api.getRoom({id: 51693}))
if (!isOk(d2, !d2 || (d2.participant_count === 159))) okay = false
if (d1) { // can't bother getting and writing down the id of a playlist item
let d3 = await <Promise<ReturnType<typeof api.getPlaylistItemScores> | false>>attempt(
"getPlaylistItemScores (realtime): ", api.getPlaylistItemScores({id: d1.playlist[0].id, room_id: d1.id}))
!isOk(d3, !d3 || (d3.length > 0)) ? console.log("Bug not fixed yet...") : console.log("Bug fixed!!! :partying_face:")
}
if (d2) { // still can't bother getting and writing down the id of a playlist item
let d4 = await <Promise<ReturnType<typeof api.getPlaylistItemScores> | false>>attempt(
"getPlaylistItemScores (playlist): ", api.getPlaylistItemScores({id: d2.playlist[0].id, room_id: d2.id}))
if (!isOk(d4, !d4 || (d4.length >= 50))) okay = false
}
let d5 = await <Promise<ReturnType<typeof api.getMatch> | false>>attempt("getMatch: ", api.getMatch(62006076))
if (!isOk(d5, !d5 || (d5.match.name === "CWC2020: (Italy) vs (Indonesia)"))) okay = false
let d6 = await <Promise<ReturnType<typeof api.getMatches> | false>>attempt("getMatches: ", api.getMatches())
if (!isOk(d6, !d6 || (d6[0].id > 111250329))) okay = false

return okay
}

Expand Down
6 changes: 3 additions & 3 deletions lib/tests/test_authorized.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ async function test(id: string | undefined, secret: string | undefined, redirect

let api = await osu.API.createAsync({id: Number(id), secret}, {code, redirect_uri}, "all")
if (api) {
let d1 = await api.getRanking(osu.Rulesets.osu, "performance", 1, "friends")
let d1 = await api.getRoom({id: 231069})
if (d1) {
d1.ranking = [d1.ranking[0]]
console.log(d1)
let d2 = await api.getPlaylistItemScores({id: d1.playlist[0].id, room_id: 231069})
console.log(d2)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "osu-api-v2-js",
"version": "0.3.1",
"version": "0.3.2",
"description": "Package to easily access osu!api version 2.0",
"type": "module",
"main": "dist/index.js",
Expand Down

0 comments on commit 0a6baf9

Please sign in to comment.