Skip to content

Commit

Permalink
Changelog stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
TTTaevas committed Apr 23, 2023
1 parent cd074b7 commit f96c639
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
33 changes: 33 additions & 0 deletions lib/changelog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export interface ChangelogBuild {
created_at: Date,
display_version: string,
id: number,
update_stream: UpdateStream | null,
users: number
version: string | null,
changelog_entries?: {
category: string,
created_at: Date | null,
github_pull_request_id: number | null,
github_url: string | null,
id: number | null,
major: Boolean,
repository: string | null,
title: string | null,
type: string,
url: string | null
},
versions?: {
next: ChangelogBuild | null,
previous: ChangelogBuild | null
}
}

export interface UpdateStream {
display_name: string | null,
id: number,
is_featured: Boolean,
name: string,
latest_build: ChangelogBuild | null,
user_count: number
}
30 changes: 30 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import { Leader, Match, MatchInfo, MultiplayerScore, PlaylistItem, Room } from "
import { GameModes, Mod } from "./misc"
import { BeatmapUserScore, Score } from "./score"
import { Rankings, Spotlight } from "./ranking"
import { ChangelogBuild, UpdateStream } from "./changelog"

export {Beatmap, BeatmapCompact}
export {User, UserCompact, KudosuHistory}
export {BeatmapUserScore, Score}
export {Room, Leader, PlaylistItem, MultiplayerScore}
export {GameModes}
export {ChangelogBuild, UpdateStream}

export class APIError {
message: string
Expand Down Expand Up @@ -300,6 +302,34 @@ export class API {
}


// CHANGELOG STUFF

async getChangelogBuild(stream: string, build: string): Promise<ChangelogBuild | APIError> {
let response = await this.request("get", `changelog/${stream}/${build}`)
if (!response) {return new APIError(`No Build could be found (stream: ${stream} / build: ${build})`)}
return correctType(response) as ChangelogBuild
}

async getChangelogListing(format: "html" | "markdown", options?: {build_version_range?: {from?: string, to?: string},
max_id: number, stream: string}): Promise<ChangelogBuild[] | APIError> {
let message_format = [format]
let from = options ? options.build_version_range ? options.build_version_range.from ? options.build_version_range.from : "" : "" : ""
let to = options ? options.build_version_range ? options.build_version_range.from ? options.build_version_range.from : "" : "" : ""
let stream = options ? options.stream ? options.stream : "" : ""
let max_id = options ? options.max_id ? options.max_id : "" : ""

let response = await this.request("get", `changelog`, {message_format, from, to, stream, max_id})
if (!response || !response.builds) {return new APIError(`No Build could be found...`)}
return response.builds.map((b: ChangelogBuild) => correctType(b)) as ChangelogBuild[]
}

async getChangelogStreams(): Promise<UpdateStream[] | APIError> {
let response = await this.request("get", `changelog`, {max_id: 1})
if (!response || !response.streams) {return new APIError(`No stream could be found...`)}
return response.streams.map((s: UpdateStream) => correctType(s)) as UpdateStream[]
}


// MULTIPLAYER STUFF

async getRoom(room: {id: number} | Room): Promise<Room | APIError> {
Expand Down

0 comments on commit f96c639

Please sign in to comment.