Skip to content

Commit

Permalink
Update the Multiplayer interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
TTTaevas committed Nov 20, 2023
1 parent e583405 commit bac3f4f
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 27 deletions.
8 changes: 7 additions & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,13 @@ export class API {
* @param id Can be found at the end of the URL of said match
*/
async getMatch(id: number): Promise<Match> {
const response = await this.request("get", `matches/${id}`)
let response = await this.request("get", `matches/${id}`) as Match
// I know `events[i].game.scores[e].perfect` can at least be 0 instead of being false; fix that
for (let i = 0; i < response.events.length; i++) {
for (let e = 0; e < Number(response.events[i].game?.scores.length); e++) {
response.events[i].game!.scores[e].perfect = Boolean(response.events[i].game!.scores[e].perfect)
}
}
return correctType(response) as Match
}

Expand Down
37 changes: 24 additions & 13 deletions lib/multiplayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,14 @@ export interface PlaylistItem {
required_mods: Mod[]
expired: boolean
owner_id: number
playlist_order: number
played_at: Date
/**
* Should be null if the room isn't the realtime multiplayer kind
*/
playlist_order: number | null
/**
* Should be null if the room isn't the realtime multiplayer kind
*/
played_at: Date | null
beatmap: BeatmapWithBeatmapsetChecksumMaxcombo
}

Expand All @@ -77,7 +83,7 @@ export interface MultiplayerScore {
beatmap_id: number
ended_at: Date
max_combo: number
max_statistics: {
maximum_statistics: {
great: number
ignore_hit: number
large_tick_hit: number
Expand All @@ -88,16 +94,21 @@ export interface MultiplayerScore {
rank: string
ruleset_id: number
started_at: Date
/**
* All of its properties are optional because instead of being 0, the property actually disappears instead!
* (so if the score has no miss, the miss property is simply not there)
* @privateRemarks lmao wtf nanaya
*/
statistics: {
great: number
large_bonus: number
large_tick_hit: number
meh: number
miss: number
ok: number
small_bonus: number
small_tick_hit: number
small_tick_miss: number
great?: number
large_bonus?: number
large_tick_hit?: number
meh?: number
miss?: number
ok?: number
small_bonus?: number
small_tick_hit?: number
small_tick_miss?: number
}
total_score: number
user_id: number
Expand All @@ -118,11 +129,11 @@ export interface MultiplayerScores {
limit: number
sort: string
}
scores: MultiplayerScore[]
/**
* How many scores there are across all pages, not necessarily `scores.length`
*/
total: number
scores: MultiplayerScore[]
/**
* Will be null if not an authorized user or if the authorized user has no score
*/
Expand Down
4 changes: 2 additions & 2 deletions lib/score.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface Score {
accuracy: number
best_id: number | null
created_at: Date
id: number
id: number | null
max_combo: number
mode: string
mode_int: Rulesets
Expand All @@ -22,7 +22,7 @@ export interface Score {
/**
* null when Beatmap is Loved (for example)
*/
pp: null | number
pp: number | null
/**
* Also known as a grade, for example this is `X` (SS) if `accuracy` is `1` (100.00%)
*/
Expand Down
17 changes: 11 additions & 6 deletions lib/tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ async function attempt<T>(msg: string, fun: Promise<any>): Promise<T | false> {
}
}

function isOk(response: any, condition?: boolean) {
function isOk(response: any, condition?: boolean, depth: number = Infinity) {
if (condition === undefined) condition = true
if (!response || !condition) {
console.error("❌ Bad response:", util.inspect(response, {colors: true, compact: true, breakLength: 400, depth: Infinity}))
if (Array.isArray(response) && response[0]) {
console.log("(only printing the first element of the response array for the following error:")
response = response[0]
}
console.error("❌ Bad response:", util.inspect(response, {colors: true, compact: true, breakLength: 400, depth: depth}))
return false
}
return true
Expand Down Expand Up @@ -86,7 +90,8 @@ const testUserStuff = async (): Promise<boolean> => {
if (!isOk(a3, !a3 || (a3.length === 5 && validate(a3[0], "ScoreWithUserBeatmapBeatmapset", score_gen)))) okay = false
let a4 = await <Promise<ReturnType<typeof api.getUserScores> | false>>attempt("getUserScores (firsts): ", api.getUserScores({id: 6503700}, "firsts", 3))
if (!isOk(a4, !a4 || (a4.length === 3 && validate(a4[0], "ScoreWithUserBeatmapBeatmapset", score_gen)))) okay = false
let a5 = await <Promise<ReturnType<typeof api.getUserScores> | false>>attempt("getUserScores (recent): ", api.getUserScores({id: 12337864}, "recent", 1))
let a5 = await <Promise<ReturnType<typeof api.getUserScores> | false>>attempt(
"getUserScores (recent): ", api.getUserScores({id: 12337864}, "recent", 1, undefined, true))
// Due to the nature of the test, it might fail, you may adapt the user id
if (!isOk(a5, !a5 || (a5.length === 1 && validate(a5[0], "ScoreWithUserBeatmapBeatmapset", score_gen)))) okay = false
let a6 = await <Promise<ReturnType<typeof api.getUserKudosu> | false>>attempt("getUserKudosu: ", api.getUserKudosu({id: user_id}, 5))
Expand Down Expand Up @@ -161,16 +166,16 @@ const testMultiplayerStuff = async (): Promise<boolean> => {
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.scores.length > 0 && validate(d3.scores[0], "MultiplayerScores", generator))) ?
!isOk(d3, !d3 || (d3.scores.length > 0 && validate(d3, "MultiplayerScores", generator)), 1) ?
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.scores.length >= 50 && validate(d4.scores[0], "MultiplayerScores", generator)))) okay = false
if (!isOk(d4, !d4 || (d4.scores.length >= 50 && validate(d4, "MultiplayerScores", generator)), 1)) 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)" && validate(d5, "Match", generator)))) okay = false
if (!isOk(d5, !d5 || (d5.match.name === "CWC2020: (Italy) vs (Indonesia)" && validate(d5, "Match", generator)), 3)) okay = false
let d6 = await <Promise<ReturnType<typeof api.getMatches> | false>>attempt("getMatches: ", api.getMatches())
if (!isOk(d6, !d6 || (d6[0].id > 111250329 && validate(d6[0], "MatchInfo", generator)))) okay = false

Expand Down
2 changes: 1 addition & 1 deletion lib/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export interface UserWithCountryCover extends UserWithCountry {
cover: {
custom_url: string | null
url: string
id: string | null
id: number | null
}
}

Expand Down
13 changes: 9 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
integrity sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==

"@types/node@^20.8.10":
version "20.9.1"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.9.1.tgz#9d578c610ce1e984adda087f685ace940954fe19"
integrity sha512-HhmzZh5LSJNS5O8jQKpJ/3ZcrrlG6L70hpGqMIAoM9YVD0YBRNWYsfwcXq8VnSjlNpCpgLzMXdiPo+dxcvSmiA==
version "20.9.2"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.9.2.tgz#002815c8e87fe0c9369121c78b52e800fadc0ac6"
integrity sha512-WHZXKFCEyIUJzAwh3NyyTHYSR35SevJ6mZ1nWwJafKtiQbqRTIKSRcw3Ma3acqgsent3RRDqeVwpHntMk+9irg==
dependencies:
undici-types "~5.26.4"

Expand Down Expand Up @@ -242,7 +242,12 @@ typedoc@^0.25.3:
minimatch "^9.0.3"
shiki "^0.14.1"

typescript@^5.2.2, typescript@~5.2.2:
typescript@^5.2.2:
version "5.3.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.3.2.tgz#00d1c7c1c46928c5845c1ee8d0cc2791031d4c43"
integrity sha512-6l+RyNy7oAHDfxC4FzSJcz9vnjTKxrLpDG5M2Vu4SHRVNg6xzqZp6LYSR9zjqQTu8DU/f5xwxUdADOkbrIX2gQ==

typescript@~5.2.2:
version "5.2.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.2.2.tgz#5ebb5e5a5b75f085f22bc3f8460fba308310fa78"
integrity sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==
Expand Down

0 comments on commit bac3f4f

Please sign in to comment.