Skip to content

Commit

Permalink
Merge pull request #4 from TTTaevas/cleanup
Browse files Browse the repository at this point in the history
v0.3.3
  • Loading branch information
TTTaevas committed Feb 20, 2023
2 parents 910de0f + 3ebbb5e commit 7bc6929
Show file tree
Hide file tree
Showing 10 changed files with 188 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ updates:
- package-ecosystem: "npm" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "monthly"
interval: "daily"
43 changes: 43 additions & 0 deletions .github/workflows/dependabot-reviewer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Stealing from Nícolas Iensen
# https://nicolasiensen.github.io/2022-07-23-automating-dependency-updates-with-dependabot-github-auto-merge-and-github-actions/

name: Dependabot reviewer
on: pull_request_target

permissions:
pull-requests: write
contents: write

jobs:
review-dependabot-pr:
runs-on: ubuntu-latest
if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }}
steps:
- name: Dependabot metadata
id: dependabot-metadata
uses: dependabot/[email protected]
- name: Enable auto-merge for Dependabot PRs
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Approve patch and minor updates
if: ${{steps.dependabot-metadata.outputs.update-type == 'version-update:semver-patch' || steps.dependabot-metadata.outputs.update-type == 'version-update:semver-minor'}}
run: gh pr review $PR_URL --approve -b "I'm **approving** this pull request because **it includes a patch or minor update**"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Approve major updates of development dependencies
if: ${{steps.dependabot-metadata.outputs.update-type == 'version-update:semver-major' && steps.dependabot-metadata.outputs.dependency-type == 'direct:development'}}
run: gh pr review $PR_URL --approve -b "I'm **approving** this pull request because **it includes a major update of a dependency used only in development**"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Comment on major updates of non-development dependencies
if: ${{steps.dependabot-metadata.outputs.update-type == 'version-update:semver-major' && steps.dependabot-metadata.outputs.dependency-type == 'direct:production'}}
run: |
gh pr comment $PR_URL --body "I'm **not approving** this PR because **it includes a major update of a dependency used in production**"
gh pr edit $PR_URL --add-label "requires-manual-qa"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
28 changes: 22 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
name: Publish Package to npmjs
name: Publish Package
on:
release:
types: [published]

jobs:
build:
publish-npm:
name: Publish on NPM
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v3
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
# Defaults to the user or organization that owns the workflow file
scope: '@TTTaevas'

- run: yarn
- run: yarn publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}


publish-gpr:
name: Publish on GPR
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18.x'
registry-url: 'https://npm.pkg.github.com/'
scope: '@tttaevas'

- run: yarn
- run: yarn publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63 changes: 58 additions & 5 deletions lib/beatmap.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { getMods } from "."
import { Mods } from "./mods"
import { getMods, Mods } from "./index"

/**
* For the `approved` of Beatmaps https://osu.ppy.sh/wiki/en/Beatmap/Category
*/
export enum Categories {
graveyard = -2,
WIP = -1,
Expand All @@ -10,6 +12,9 @@ export enum Categories {
qualified = 3,
}

/**
* For the `genre_id` of Beatmaps
*/
export enum Genres {
any = 0,
unspecified = 1,
Expand All @@ -28,6 +33,9 @@ export enum Genres {
jazz = 14,
}

/**
* For the `language_id` of Beatmaps
*/
export enum Languages {
any = 0,
unspecified = 1,
Expand All @@ -49,14 +57,41 @@ export enum Languages {
export interface Beatmap {
beatmapset_id: number
beatmap_id: number
/**
* Also known as the id of the category the beatmap is in, for example it'd be 1 if it was ranked
*/
approved: number
/**
* In seconds. Feel free to use the `getLength` function attached to this object to have the length in a "m:ss" format!
*/
total_length: number
/**
* In seconds. Feel free to use the `getLength` function attached to this object to have the length in a "m:ss" format!
*/
hit_length: number
/**
* The name of the difficulty/beatmap (for example, "Mirash's Insane")
*/
version: string
/**
* md5 hash of the beatmap
*/
file_md5: string
/**
* Circle Size https://osu.ppy.sh/wiki/en/Beatmap/Circle_size
*/
diff_size: number
/**
* Overall Difficulty https://osu.ppy.sh/wiki/en/Beatmap/Overall_difficulty
*/
diff_overall: number
/**
* Approach Rate https://osu.ppy.sh/wiki/en/Beatmap/Approach_rate
*/
diff_approach: number
/**
* Health Drain https://osu.ppy.sh/wiki/en/Gameplay/Health
*/
diff_drain: number
mode: number
count_normal: number
Expand All @@ -65,10 +100,22 @@ export interface Beatmap {
submit_date: Date
approved_date: Date
last_update: Date
/**
* As it's shown on the website (so it's romaji if japanese name)
*/
artist: string
artist_unicode: string | null
/**
* As it's shown when you start playing the beatmap (so it's kana/kanji if japanese name)
*/
artist_unicode: string
/**
* As it's shown on the website (so it's romaji if japanese name)
*/
title: string
title_unicode: string | null
/**
* As it's shown when you start playing the beatmap (so it's kana/kanji if japanese name)
*/
title_unicode: string
creator: string
creator_id: number
bpm: number
Expand All @@ -84,10 +131,16 @@ export interface Beatmap {
audio_unavailable: boolean
playcount: number
passcount: number
packs: string | null // this isn't even documented lol
/**
* Undocumented! Is null if the beatmap(set) is not featured in any beatmap pack https://osu.ppy.sh/beatmaps/packs
*/
packs: string | null
max_combo: number
diff_aim: number
diff_speed: number
/**
* Star Rating https://osu.ppy.sh/wiki/en/Beatmap/Star_rating
*/
difficultyrating: number
getLength: Function
getCategory: Function
Expand Down
46 changes: 26 additions & 20 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,8 @@ import { adjustBeatmapStatsToMods, Beatmap, Categories, Genres, Languages } from
import { Match } from "./match"
import { Mods, ModsShort, unsupported_mods } from "./mods"

function correctType(x: any): any {
if (!isNaN(x)) {
return Number(x)
} else if (/[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/.test(x)) {
return new Date(x + "Z")
} else if (Array.isArray(x)) {
return x.map((e) => correctType(e))
} else if (typeof x === "object" && x !== null) {
const k = Object.keys(x)
const v = Object.values(x)
for (let i = 0; i < k.length; i++) {
x[k[i]] = correctType(v[i])
}
return x
} else {
return x
}
}

export {User, Score, Beatmap, Match, Mods, ModsShort}
export {User, Score, Match, Mods, ModsShort}
export {Beatmap, Categories, Genres, Languages, adjustBeatmapStatsToMods}

export class APIError {
message: string
Expand Down Expand Up @@ -219,3 +201,27 @@ export function getMods(value: Mods | ModsShort, version: "short" | "long"): str
}
return arr
}

/**
* *Almost* **everything** in the JSONs the API returns is a string, this function fixes that
* @param x Anything, but should be a string, an array that contains a string, or an object which has a string
* @returns x, but with it (or what it contains) now having the correct type
*/
function correctType(x: any): any {
if (!isNaN(x)) {
return Number(x)
} else if (/^[+-[0-9][0-9]+-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$/.test(x)) {
return new Date(x + "Z") // add Z to string to specify it's UTC
} else if (Array.isArray(x)) {
return x.map((e) => correctType(e))
} else if (typeof x === "object" && x !== null) {
const k = Object.keys(x)
const v = Object.values(x)
for (let i = 0; i < k.length; i++) {
x[k[i]] = correctType(v[i])
}
return x
} else {
return x
}
}
30 changes: 27 additions & 3 deletions lib/match.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
export interface Match {
/**
* Has the info about the match that is not related to what's been played
*/
match: {
match_id: number,
name: string,
start_time: Date,
end_time: Date
/**
* If the match is not disbanded, null
*/
end_time: Date | null
}
games: {
game_id: number
Expand All @@ -14,22 +20,40 @@ export interface Match {
match_type: number
scoring_type: number
team_type: number
/**
* Bitwise flag. Feel free to use `getMods` to see the mods in a more readable way! Do note that individual scores have a nullable `enabled_mods` property
*/
mods: number
scores: {
slot: number,
/**
* 0 if no team, 1 if blue, 2 if red
*/
team: number,
user_id: number,
score: number,
maxcombo: number,
/**
* Is always 0, "is not used" according to documentation
*/
rank: number,
count50: number,
count100: number,
count300: number,
countmiss: number,
countgeki: number,
countkatu: number,
perfect: number,
pass: number,
/**
* Documentation says "If full combo", but should be "If SS/100% accuracy"
*/
perfect: boolean,
/**
* If the player is alive at the end of the map
*/
pass: boolean,
/**
* Is null if no freemod
*/
enabled_mods: number | null
}[]
getScoringType: Function
Expand Down
3 changes: 3 additions & 0 deletions lib/score.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export interface Score {
countkatu: number
countgeki: number
perfect: boolean
/**
* Bitwise flag. Feel free to use `getMods` to see the mods in a more readable way!
*/
enabled_mods: number
user_id: number
date: Date
Expand Down
3 changes: 1 addition & 2 deletions lib/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import "dotenv/config"
import { adjustBeatmapStatsToMods } from "./beatmap"
import * as osu from "./index"
import { unsupported_mods } from "./mods"

Expand Down Expand Up @@ -105,7 +104,7 @@ const test: () => Promise<void> = async () => {
}

const testBeatmapWithMods = (b: osu.Beatmap, mods: osu.Mods, expected: object) => {
let bm = adjustBeatmapStatsToMods(Object.assign({}, b), mods)
let bm = osu.adjustBeatmapStatsToMods(Object.assign({}, b), mods)
let stats = {
bpm: roundTo(bm.bpm, 2),
cs: roundTo(bm.diff_size, 2),
Expand Down
6 changes: 6 additions & 0 deletions lib/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export interface User {
count_rank_s: number
count_rank_sh: number
count_rank_a: number
/**
* Uses the ISO 3166-1 alpha-2 standard https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
*/
country: string
total_seconds_played: number
pp_country_rank: number
Expand All @@ -25,6 +28,9 @@ export interface User {
beatmap_id: number
beatmapset_id: number
date: Date
/**
* How "epic" this event is (between 1 and 32)
*/
epicfactor: number
}[]
}
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-v1-js",
"version": "0.3.2",
"version": "0.3.3",
"description": "Package to easily access osu!api version 1.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down

0 comments on commit 7bc6929

Please sign in to comment.