Skip to content

Commit

Permalink
Various additions & test improvements
Browse files Browse the repository at this point in the history
Added getWikiPage, getUserBeatmaps, getUserMostPlayed, getUserRecentActivity
Verifications now support arrays, so it's more safe and straightforward
  • Loading branch information
TTTaevas committed Nov 22, 2023
1 parent 717f673 commit 37f9d68
Show file tree
Hide file tree
Showing 7 changed files with 323 additions and 88 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import * as osu from "osu-api-v2-js"
async function logUserTopPlayBeatmap(username: string) {
// Because of how the API server works, it's more convenient to use `osu.API.createAsync()` instead of `new osu.API()`!
// In a proper application, you'd use this function as soon as the app starts so you can use that object everywhere
// (or if it acts as a user, you'd use this function at the end of the authorization flow)
const api = await osu.API.createAsync({id: "<client_id>", "<client_secret>"})

const user = await api.getUser({username}) // We need to get the id of the user in order to request what we want
Expand Down Expand Up @@ -99,7 +100,7 @@ logUserTopPlayBeatmap("Doomsday fanboy")
- [ ] Edit Topic
- [ ] Edit Post

### Home
### Home
- [x] Search // split between searchUser() and searchWiki()

### Multiplayer
Expand All @@ -123,14 +124,14 @@ logUserTopPlayBeatmap("Doomsday fanboy")
- [x] Get Own Data
- [x] Get User Kudosu
- [x] Get User Scores
- [ ] Get User Beatmaps
- [ ] Get User Recent Activity
- [x] Get User Beatmaps // split between getUserBeatmaps() and getUserMostPlayed()
- [x] Get User Recent Activity
- [x] Get User
- [x] Get Users
- [x] /friends

### Wiki
- [ ] Get Wiki Page
- [x] Get Wiki Page

### Misc Undocumented Stuff
- [ ] /seasonal-backgrounds
Expand Down
24 changes: 22 additions & 2 deletions lib/beatmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export enum RankStatus {
}

/**
* @privateRemarks While not expected from anywhere, it should be exported for ease of use purposes
* Expected from BeatmapPlaycount
*/
export interface Beatmap {
beatmapset_id: number
Expand Down Expand Up @@ -85,7 +85,7 @@ export interface BeatmapExtendedWithFailtimesBeatmapsetextended extends BeatmapE
}

/**
* Expected from BeatmapWithBeatmapset, Score
* Expected from BeatmapWithBeatmapset, Score, BeatmapPlaycount
*/
export interface Beatmapset {
artist: string
Expand Down Expand Up @@ -169,6 +169,13 @@ export interface BeatmapsetExtended extends Beatmapset {
tags: string | 0
}

/**
* Expected from api.getUserBeatmaps()
*/
export interface BeatmapsetExtendedWithBeatmapExtended extends BeatmapsetExtended {
beatmaps: BeatmapExtended[]
}

/**
* Expected from api.getBeatmapset()
*/
Expand Down Expand Up @@ -212,6 +219,19 @@ export interface BeatmapsetExtendedPlus extends BeatmapsetExtended {
has_favourited?: boolean
}

/**
* Expected from api.getUserMostPlayed()
*/
export interface BeatmapPlaycount {
beatmap_id: number
/**
* Playcount
*/
count: number
beatmap: Beatmap
beatmapset: Beatmapset
}

/**
* @privateRemarks While not expected from anywhere, it should be exported for ease of use purposes
*/
Expand Down
128 changes: 128 additions & 0 deletions lib/event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import { Rulesets } from "./misc.js"

export interface Event {
created_at: Date
id: number
}

export interface EventUser extends Event {
user: {
username: string
/**
* What goes after the website's URL, so for example, it could be the `/u/7276846` of `https://osu.ppy.sh/u/7276846` (or `users` instead of `u`)
*/
url: string
}
}

export interface EventBeatmap extends Event {
/**
* {artist} - {title} [{difficulty_name}]
*/
title: string
/**
* What goes after the website's URL, like it could be the `/b/2980857?m=0` of `https://osu.ppy.sh/b/2980857?m=0` (/{beatmap_id}?m={ruleset_id})
*/
url: string
}

export interface EventBeatmapset extends Event {
/**
* {artist} - {title}
*/
title: string
/**
* What goes after the website's URL, like it could be the `/s/689155` of `https://osu.ppy.sh/s/689155` (/{beatmapset_id})
*/
url: string
}


export interface EventAchievement extends EventUser {
type: "achievement"
achievement: {
icon_url: string
id: number
name: string
grouping: string
ordering: number
slug: string
description: string
/**
* If the achievement is for a specific mode only (such as pass a 2* beatmap in taiko)
*/
mode: string | null
/**
* May contain HTML (like have the text between <i></i>)
*/
instructions: string
}
}

export interface EventBeatmapPlaycount extends EventBeatmap {
type: "beatmapPlaycount"
count: number
}

export interface EventBeatmapsetApprove extends EventUser, EventBeatmapset {
type: "beatmapsetApprove"
approval: "ranked" | "approved" | "qualified" | "loved"
}

export interface EventBeatmapsetDelete extends EventBeatmapset {
type: "beatmapsetDelete"
}

export interface EventBeatmapsetRevive extends EventUser, EventBeatmapset {
type: "beatmapsetRevive"
}

export interface EventBeatmapsetUpdate extends EventUser, EventBeatmapset {
type: "beatmapsetUpdate"
}

export interface EventBeatmapsetUpload extends EventUser, EventBeatmapset {
type: "beatmapsetUpload"
}

export interface EventRank extends EventUser, EventBeatmap {
type: "rank"
/**
* The grade, like "S"
*/
scoreRank: string
/**
* The position achieved, like 14
*/
rank: number
mode: Rulesets
}

export interface EventRankLost extends EventUser, EventBeatmap {
type: "rankLost"
mode: Rulesets
}

export interface EventUserSupportAgain extends EventUser {
type: "userSupportAgain"
}

export interface EventUserSupportFirst extends EventUser {
type: "userSupportFirst"
}

export interface EventUserSupportGift extends EventUser {
type: "userSupportGift"
}

export interface EventUsernameChange extends EventUser {
type: "usernameChange"
user: {
username: string
/**
* What goes after the website's URL, so for example, it could be the `/u/7276846` of `https://osu.ppy.sh/u/7276846`
*/
url: string
previousUsername: string
}
}
Loading

0 comments on commit 37f9d68

Please sign in to comment.