Skip to content

Commit

Permalink
Fix mistakes and inconsistencies
Browse files Browse the repository at this point in the history
  • Loading branch information
TTTaevas committed Mar 29, 2024
1 parent 8795d57 commit 4de7cc6
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 74 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function logUserTopPlayBeatmap(username: string) {
const api = await osu.API.createAsync({id: "<client_id>", secret: "<client_secret>"})

const user = await api.getUser(username) // We need to get the id of the user in order to request what we want
const score = (await api.getUserScores(user, "best", osu.Rulesets.osu, {lazer: false}, {limit: 1}))[0] // Specifying the Ruleset is optional
const score = (await api.getUserScores(user, "best", osu.Ruleset.osu, {lazer: false}, {limit: 1}))[0] // Specifying the Ruleset is optional
const beatmapDifficulty = await api.getBeatmapDifficultyAttributesOsu(score.beatmap, score.mods) // Specifying the mods so the SR is adapted to them

const x = `${score.beatmapset.artist} - ${score.beatmapset.title} [${score.beatmap.version}]`
Expand Down
28 changes: 14 additions & 14 deletions lib/beatmap.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { API, Beatmapset, Mod, Rulesets, Score, User } from "./index.js"
import { API, Beatmapset, Mod, Ruleset, Score, User } from "./index.js"
import { getId } from "./misc.js"

export interface Beatmap {
beatmapset_id: Beatmapset["id"]
difficulty_rating: number
id: number
mode: keyof typeof Rulesets
mode: keyof typeof Ruleset
status: string
total_length: number
user_id: User["id"]
Expand All @@ -21,7 +21,7 @@ export namespace Beatmap {
*/
export interface Config {
/** The Ruleset used to make the score, useful if it was made on a convert */
ruleset?: Rulesets
ruleset?: Ruleset
/** The Mods used to make the score, you can simply use `["NM"]` to filter out scores with mods (defaults to **any mods**, no scores filtered) */
mods?: string[]
/** "Beatmap score ranking type", whatever that means... */
Expand Down Expand Up @@ -56,7 +56,7 @@ export namespace Beatmap {
hit_length: number
is_scoreable: boolean
last_updated: Date
mode_int: Rulesets
mode_int: Ruleset
passcount: number
playcount: number
ranked: Beatmapset.RankStatus
Expand Down Expand Up @@ -100,7 +100,7 @@ export namespace Beatmap {
name: string
/** Are difficulty reduction mods unable to be used to clear this pack? (is `false` if you can use such mods) */
no_diff_reduction: boolean
ruleset_id: Rulesets | null
ruleset_id: Ruleset | null
tag: string
/** Download page; going there with a web browser should start the download of a zip file automatically */
url: string
Expand Down Expand Up @@ -189,7 +189,7 @@ export namespace Beatmap {
* @param ruleset Useful to specify if the beatmap is a convert (defaults to **the ruleset the beatmap was intended for**)
* @remarks You may want to use api.getBeatmapDifficultyAttributesOsu (or Taiko or whatever) instead for better type safety
*/
export async function get(this: API, beatmap: Beatmap["id"] | Beatmap, mods?: Mod[] | string[] | number, ruleset?: Rulesets):
export async function get(this: API, beatmap: Beatmap["id"] | Beatmap, mods?: Mod[] | string[] | number, ruleset?: Ruleset):
Promise<DifficultyAttributes.Any> {
const response = await this.request("post", `beatmaps/${getId(beatmap)}/attributes`, {ruleset_id: ruleset, mods})
return response.attributes // It's the only property
Expand All @@ -201,7 +201,7 @@ export namespace Beatmap {
* @param mods Can be a bitset of mods, an array of mod acronyms, or an array of Mods (ignores mod settings) (defaults to **No Mod**)
*/
export async function getOsu(this: API, beatmap: Beatmap["id"] | Beatmap, mods?: Mod[] | string[] | number): Promise<DifficultyAttributes.Osu> {
return await this.getBeatmapDifficultyAttributes(beatmap, mods, Rulesets.osu) as DifficultyAttributes.Osu
return await this.getBeatmapDifficultyAttributes(beatmap, mods, Ruleset.osu) as DifficultyAttributes.Osu
}

/**
Expand All @@ -210,23 +210,23 @@ export namespace Beatmap {
* @param mods Can be a bitset of mods, an array of mod acronyms, or an array of Mods (ignores mod settings) (defaults to **No Mod**)
*/
export async function getTaiko(this: API, beatmap: Beatmap["id"] | Beatmap, mods?: Mod[] | string[] | number): Promise<DifficultyAttributes.Taiko> {
return await this.getBeatmapDifficultyAttributes(beatmap, mods, Rulesets.taiko) as DifficultyAttributes.Taiko
return await this.getBeatmapDifficultyAttributes(beatmap, mods, Ruleset.taiko) as DifficultyAttributes.Taiko
}
/**
* Get various data about the difficulty of a ctb beatmap!
* @param beatmap The Beatmap in question
* @param mods Can be a bitset of mods, an array of mod acronyms, or an array of Mods (ignores mod settings) (defaults to **No Mod**)
*/
export async function getFruits(this: API, beatmap: Beatmap["id"] | Beatmap, mods?: Mod[] | string[] | number): Promise<DifficultyAttributes.Fruits> {
return await this.getBeatmapDifficultyAttributes(beatmap, mods, Rulesets.fruits) as DifficultyAttributes.Fruits
return await this.getBeatmapDifficultyAttributes(beatmap, mods, Ruleset.fruits) as DifficultyAttributes.Fruits
}
/**
* Get various data about the difficulty of a mania beatmap!
* @param beatmap The Beatmap in question
* @param mods Can be a bitset of mods, an array of mod acronyms, or an array of Mods (ignores mod settings) (defaults to **No Mod**)
*/
export async function getMania(this: API, beatmap: Beatmap["id"] | Beatmap, mods?: Mod[] | string[] | number): Promise<DifficultyAttributes.Mania> {
return await this.getBeatmapDifficultyAttributes(beatmap, mods, Rulesets.mania) as DifficultyAttributes.Mania
return await this.getBeatmapDifficultyAttributes(beatmap, mods, Ruleset.mania) as DifficultyAttributes.Mania
}
}

Expand All @@ -247,7 +247,7 @@ export namespace Beatmap {
* @returns An Object with the position of the score according to the specified Mods and Ruleset, and with the score itself
*/
export async function getOne(this: API, beatmap: Beatmap["id"] | Beatmap, user: User["id"] | User, config?: Config): Promise<UserScore> {
const mode = config?.ruleset !== undefined ? Rulesets[config.ruleset] : undefined
const mode = config?.ruleset !== undefined ? Ruleset[config.ruleset] : undefined
return await this.request("get", `beatmaps/${getId(beatmap)}/scores/users/${getId(user)}`,
{legacy_only: config?.legacy_only, mode, mods: config?.mods, type: config?.type})
}
Expand All @@ -259,7 +259,7 @@ export namespace Beatmap {
* @param config Specify the score's ruleset, prevent a lazer score from being returned **(`mods` and `type` should not be supported)**
*/
export async function getMultiple(this: API, beatmap: Beatmap["id"] | Beatmap, user: User["id"] | User, config?: Config): Promise<Score.Legacy[]> {
const mode = config?.ruleset !== undefined ? Rulesets[config.ruleset] : undefined
const mode = config?.ruleset !== undefined ? Ruleset[config.ruleset] : undefined
const response = await this.request("get", `beatmaps/${getId(beatmap)}/scores/users/${getId(user)}/all`,
{legacy_only: config?.legacy_only, mode, mods: config?.mods, type: config?.type})
return response.scores // It's the only property
Expand Down Expand Up @@ -300,7 +300,7 @@ export namespace Beatmap {
* @remarks Please check if `mods` and `type` seem to be supported or not by the API: https://osu.ppy.sh/docs/index.html#get-beatmap-scores
*/
export async function getScores(this: API, beatmap: Beatmap["id"] | Beatmap, config?: Config): Promise<Score.WithUser[]> {
const mode = config?.ruleset !== undefined ? Rulesets[config.ruleset] : undefined
const mode = config?.ruleset !== undefined ? Ruleset[config.ruleset] : undefined
const response = await this.request("get", `beatmaps/${getId(beatmap)}/scores`,
{legacy_only: config?.legacy_only, mode, mods: config?.mods, type: config?.type})
return response.scores // It's the only property
Expand All @@ -314,7 +314,7 @@ export namespace Beatmap {
* @remarks Please check if `mods` and `type` seem to be supported or not by the API: https://osu.ppy.sh/docs/index.html#get-beatmap-scores-non-legacy
*/
export async function getSoloScores(this: API, beatmap: Beatmap["id"] | Beatmap, config?: Config): Promise<Score.Solo[]> {
const mode = config?.ruleset !== undefined ? Rulesets[config.ruleset] : undefined
const mode = config?.ruleset !== undefined ? Ruleset[config.ruleset] : undefined
const response = await this.request("get", `beatmaps/${getId(beatmap)}/solo-scores`,
{legacy_only: config?.legacy_only, mode, mods: config?.mods, type: config?.type})
return response.scores // It's the only property
Expand Down
36 changes: 18 additions & 18 deletions lib/beatmapset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { API, Beatmap, Rulesets, User } from "./index.js"
import { API, Beatmap, Ruleset, User } from "./index.js"
import { getId } from "./misc.js"

export interface Beatmapset {
Expand Down Expand Up @@ -60,7 +60,7 @@ export namespace Beatmapset {
Loved = 4
}

export enum Genres {
export enum Genre {
Any = 0,
Unspecified = 1,
"Video Game" = 2,
Expand All @@ -77,7 +77,7 @@ export namespace Beatmapset {
Jazz = 14
}

export enum Languages {
export enum Language {
Any = 0,
Unspecified = 1,
English = 2,
Expand Down Expand Up @@ -247,7 +247,7 @@ export namespace Beatmapset {
/** @remarks Unrelated to comments in bundles! */
export namespace Comment {
export interface WithModes extends Comment {
modes: (keyof typeof Rulesets)[]
modes: (keyof typeof Ruleset)[]
}

export interface WithDiscussionidPostid extends Comment {
Expand All @@ -260,17 +260,17 @@ export namespace Beatmapset {
}

export interface WithDiscussionidPostidNominatorsids extends WithDiscussionidPostid {
nominators_ids: User["id"][]
nominator_ids: User["id"][]
}

export interface WithDiscussionidPostidOldgenreNewgenre extends WithDiscussionidPostid {
old: keyof typeof Genres
new: keyof typeof Genres
old: keyof typeof Genre
new: keyof typeof Genre
}

export interface WithDiscussionidPostidOldlanguageNewlanguage extends WithDiscussionidPostid {
old: keyof typeof Languages
new: keyof typeof Languages
old: keyof typeof Language
new: keyof typeof Language
}

export interface WithDiscussionidPostidOldnsfwNewnsfw extends WithDiscussionidPostid {
Expand Down Expand Up @@ -301,7 +301,7 @@ export namespace Beatmapset {

export interface WithDiscussionidPostidSourceuseridSourceuserusername extends WithDiscussionidPostid {
source_user_id: User["id"]
source_user_name: User["username"]
source_user_username: User["username"]
}

export interface WithDiscussionidPostidBeatmapidBeatmapversionNewuseridNewuserusername extends WithDiscussionidPostid {
Expand Down Expand Up @@ -385,7 +385,7 @@ export namespace Beatmapset {
converts: Beatmap.Extended.WithFailtimes[]
current_nominations: {
beatmapset_id: Beatmapset["id"]
rulesets: Rulesets[]
rulesets: Ruleset[]
reset: boolean
user_id: User["id"]
}[]
Expand All @@ -394,12 +394,12 @@ export namespace Beatmapset {
description: string
}
genre: {
id: Genres
name: keyof typeof Genres
id: Genre
name: keyof typeof Genre
}
language: {
id: Languages
name: keyof typeof Languages
id: Language
name: keyof typeof Language
}
pack_tags: string[]
ratings: number[]
Expand Down Expand Up @@ -535,7 +535,7 @@ export namespace Beatmapset {
/** Various filters to activate */
general?: ("Recommended difficulty" | "Include converted beatmaps" | "Subscribed mappers" | "Spotlighted beatmaps" | "Featured Artists")[],
/** Only get sets that have maps that you can play in the ruleset of your choice */
mode?: Rulesets,
mode?: Ruleset,
/** Filter in sets depending on their status or on their relation with the authorized user (defaults to **all that have a leaderboard**) */
categories?: "Any" | "Ranked" | "Qualified" | "Loved" | "Favourites" | "Pending" | "WIP" | "Graveyard" | "My Maps",
/** Use this to hide all sets that are marked as explicit */
Expand All @@ -545,13 +545,13 @@ export namespace Beatmapset {
* @remarks "Any"/0 actually looks up sets that specifically have the Genre "Any" such as `5947`, it's excluded because it's counter-intuitive
* and near useless (but you can do something like `1-1` if you actually want that!)
*/
genre?: Exclude<Genres, 0>,
genre?: Exclude<Genre, 0>,
/**
* Specify the spoken language of the music of the beatmapsets you're searching for (don't specify to get any language)
* @remarks "Any"/0 actually looks up sets that specifically have the Language "Any" (and no set has that), it's excluded because it's counter-intuitive
* and near useless (but you can do something like `1-1` if you actually want that!)
*/
language?: Exclude<Languages, 0>,
language?: Exclude<Language, 0>,
/** Should all sets have a video, a storyboard, maybe both at once? */
extra?: ("must_have_video" | "must_have_storyboard")[],
/** Does the authorized user with osu!supporter have already achieved certain ranks on those sets? */
Expand Down
8 changes: 4 additions & 4 deletions lib/event.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { API, User as UserImport, Rulesets } from "./index.js"
import { API, User as UserImport, Ruleset } from "./index.js"

export interface Event {
created_at: Date
Expand Down Expand Up @@ -41,7 +41,7 @@ export namespace Event {
slug: string
description: string
/** If the achievement is for a specific mode only (such as pass a 2* beatmap in taiko) */
mode: keyof typeof Rulesets | null
mode: keyof typeof Ruleset | null
/** @remarks May contain HTML (like have the text between <i></i>) */
instructions: string | null
}
Expand Down Expand Up @@ -90,14 +90,14 @@ export namespace Event {
scoreRank: string
/** The position achieved, like 14 */
rank: number
mode: keyof typeof Rulesets
mode: keyof typeof Ruleset
user: SharedProperties.User
beatmap: SharedProperties.Beatmap
}

export interface RankLost extends Event {
type: "rankLost"
mode: keyof typeof Rulesets
mode: keyof typeof Ruleset
user: SharedProperties.User
beatmap: SharedProperties.Beatmap
}
Expand Down
5 changes: 3 additions & 2 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export { Forum } from "./forum.js"
export { WikiPage } from "./wiki.js"
export { NewsPost } from "./news.js"
export { Home } from "./home.js"
export { Rulesets, Mod, Scope, Spotlight } from "./misc.js"
export { Ruleset, Mod, Scope, Spotlight } from "./misc.js"
export { Chat } from "./chat.js"
export { WebSocket } from "./websocket.js"
export { Comment } from "./comment.js"
Expand Down Expand Up @@ -291,7 +291,8 @@ export class API {
if (this.refresh_on_expires && api.refresh_token) {
setTimeout(() => {
try {
this.refreshToken()
// check again in case anything has changed
if (this.refresh_on_expires && api.refresh_token) {this.refreshToken()}
} catch {}
}, (json.expires_in - 60) * 1000) // 1 minute before the received date
}
Expand Down
2 changes: 1 addition & 1 deletion lib/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type Mod = {
settings?: {[k: string]: any}
}

export enum Rulesets {
export enum Ruleset {
osu = 0,
taiko = 1,
fruits = 2,
Expand Down
8 changes: 4 additions & 4 deletions lib/multiplayer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { API, Beatmap, Chat, Mod, Rulesets, Score, User } from "./index.js"
import { API, Beatmap, Chat, Mod, Ruleset, Score, User } from "./index.js"
import { getId } from "./misc.js"

export namespace Multiplayer {
Expand Down Expand Up @@ -44,7 +44,7 @@ export namespace Multiplayer {
id: number
room_id: number
beatmap_id: Beatmap["id"]
ruleset_id: Rulesets
ruleset_id: Ruleset
allowed_mods: Mod[]
required_mods: Mod[]
expired: boolean
Expand Down Expand Up @@ -149,8 +149,8 @@ export namespace Multiplayer {
id: number
start_time: Date
end_time: Date | null
mode: keyof typeof Rulesets
mode_int: Rulesets
mode: keyof typeof Ruleset
mode_int: Ruleset
scoring_type: string
team_type: string
mods: string[]
Expand Down
16 changes: 8 additions & 8 deletions lib/ranking.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { API, Beatmapset, Rulesets, Spotlight as SpotlightInterface, User } from "./index.js"
import { API, Beatmapset, Ruleset, Spotlight as SpotlightImport, User } from "./index.js"
import { getId } from "./misc.js"

interface Ranking {
Expand Down Expand Up @@ -37,7 +37,7 @@ export namespace Ranking {
export interface Spotlight {
beatmapsets: Beatmapset.Extended[]
ranking: User.Statistics.WithUser[]
spotlight: SpotlightInterface.WithParticipantcount
spotlight: SpotlightImport.WithParticipantcount
}

/**
Expand All @@ -46,7 +46,7 @@ export namespace Ranking {
* @param type Rank players by their performance points or by their ranked score?
* @param config Specify which page, country, filter out non-friends...
*/
export async function getUser(this: API, ruleset: Rulesets, type: "performance" | "score", config?: {
export async function getUser(this: API, ruleset: Ruleset, type: "performance" | "score", config?: {
/** Imagine the array you get as a page, it can only have a maximum of 50 players, while 50 others may be on the next one */
page?: number,
/** What kind of players do you want to see? Keep in mind `friends` has no effect if no authorized user */
Expand All @@ -56,7 +56,7 @@ export namespace Ranking {
/** If `type` is `performance` and `ruleset` is mania, choose between 4k and 7k! */
variant?: "4k" | "7k"
}): Promise<Ranking.User> {
return await this.request("get", `rankings/${Rulesets[ruleset]}/${type}`,
return await this.request("get", `rankings/${Ruleset[ruleset]}/${type}`,
{page: config?.page, filter: config?.filter, country: config?.country, variant: config?.variant})
}

Expand All @@ -65,8 +65,8 @@ export namespace Ranking {
* @param ruleset On which Ruleset should the countries be compared?
* @param page Imagine the array you get as a page, it can only have a maximum of 50 countries, while 50 others may be on the next one (defaults to **1**)
*/
export async function getCountry(this: API, ruleset: Rulesets, page: number = 1): Promise<Ranking.Country> {
return await this.request("get", `rankings/${Rulesets[ruleset]}/country`, {page})
export async function getCountry(this: API, ruleset: Ruleset, page: number = 1): Promise<Ranking.Country> {
return await this.request("get", `rankings/${Ruleset[ruleset]}/country`, {page})
}

/** Get the top 50 players who have the most total kudosu! */
Expand All @@ -81,8 +81,8 @@ export namespace Ranking {
* @param spotlight The spotlight in question
* @param filter What kind of players do you want to see? Keep in mind `friends` has no effect if no authorized user (defaults to **all**)
*/
export async function getSpotlight(this: API, ruleset: Rulesets, spotlight: SpotlightInterface["id"] | SpotlightInterface, filter: "all" | "friends" = "all"):
export async function getSpotlight(this: API, ruleset: Ruleset, spotlight: SpotlightImport["id"] | SpotlightImport, filter: "all" | "friends" = "all"):
Promise<Ranking.Spotlight> {
return await this.request("get", `rankings/${Rulesets[ruleset]}/charts`, {spotlight: getId(spotlight), filter})
return await this.request("get", `rankings/${Ruleset[ruleset]}/charts`, {spotlight: getId(spotlight), filter})
}
}
Loading

0 comments on commit 4de7cc6

Please sign in to comment.