@hizollo/osu-api 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,845 @@
1
+ "use strict";
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
+ mod
24
+ ));
25
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
26
+
27
+ // index.ts
28
+ var osu_api_exports = {};
29
+ __export(osu_api_exports, {
30
+ BaseManager: () => BaseManager,
31
+ BaseScore: () => BaseScore,
32
+ Beatmap: () => Beatmap,
33
+ BeatmapApprovedState: () => BeatmapApprovedState,
34
+ BeatmapGenre: () => BeatmapGenre,
35
+ BeatmapLanguage: () => BeatmapLanguage,
36
+ BeatmapManager: () => BeatmapManager,
37
+ BeatmapScore: () => BeatmapScore,
38
+ Beatmapset: () => Beatmapset,
39
+ Client: () => Client,
40
+ GameMode: () => GameMode,
41
+ Match: () => Match,
42
+ MatchGame: () => MatchGame,
43
+ MatchManager: () => MatchManager,
44
+ MatchScore: () => MatchScore,
45
+ MatchScoringType: () => MatchScoringType,
46
+ MatchTeamType: () => MatchTeamType,
47
+ Mods: () => Mods,
48
+ ModsBitField: () => ModsBitField,
49
+ Replay: () => Replay,
50
+ ReplayManager: () => ReplayManager,
51
+ ScoreManager: () => ScoreManager,
52
+ ScoreRank: () => ScoreRank,
53
+ Team: () => Team,
54
+ URLBuilder: () => URLBuilder,
55
+ User: () => User,
56
+ UserEvent: () => UserEvent,
57
+ UserManager: () => UserManager,
58
+ UserRequestType: () => UserRequestType
59
+ });
60
+ module.exports = __toCommonJS(osu_api_exports);
61
+
62
+ // src/Client.ts
63
+ var request2 = __toESM(require("superagent"));
64
+
65
+ // src/managers/UserManager.ts
66
+ var request = __toESM(require("superagent"));
67
+
68
+ // src/types/enums.ts
69
+ var GameMode = /* @__PURE__ */ ((GameMode3) => {
70
+ GameMode3[GameMode3["Standard"] = 0] = "Standard";
71
+ GameMode3[GameMode3["Taiko"] = 1] = "Taiko";
72
+ GameMode3[GameMode3["Catch"] = 2] = "Catch";
73
+ GameMode3[GameMode3["Mania"] = 3] = "Mania";
74
+ return GameMode3;
75
+ })(GameMode || {});
76
+ var UserRequestType = /* @__PURE__ */ ((UserRequestType2) => {
77
+ UserRequestType2["String"] = "string";
78
+ UserRequestType2["Id"] = "id";
79
+ return UserRequestType2;
80
+ })(UserRequestType || {});
81
+ var Mods = {
82
+ None: 0n,
83
+ NoFail: 1n << 0n,
84
+ Easy: 1n << 1n,
85
+ TouchDevice: 1n << 2n,
86
+ Hidden: 1n << 3n,
87
+ HardRock: 1n << 4n,
88
+ SuddenDeath: 1n << 5n,
89
+ DoubleTime: 1n << 6n,
90
+ Relax: 1n << 7n,
91
+ HalfTime: 1n << 8n,
92
+ Nightcore: 1n << 9n,
93
+ Flashlight: 1n << 10n,
94
+ Autoplay: 1n << 11n,
95
+ SpunOut: 1n << 12n,
96
+ AutoPilot: 1n << 13n,
97
+ Perfect: 1n << 14n,
98
+ Key4: 1n << 15n,
99
+ Key5: 1n << 16n,
100
+ Key6: 1n << 17n,
101
+ Key7: 1n << 18n,
102
+ Key8: 1n << 19n,
103
+ FadeIn: 1n << 20n,
104
+ Random: 1n << 21n,
105
+ Cinema: 1n << 22n,
106
+ Target: 1n << 23n,
107
+ Key9: 1n << 24n,
108
+ KeyCoop: 1n << 25n,
109
+ Key1: 1n << 26n,
110
+ Key3: 1n << 27n,
111
+ Key2: 1n << 28n,
112
+ ScoreV2: 1n << 29n,
113
+ Mirror: 1n << 30n
114
+ };
115
+ var BeatmapApprovedState = /* @__PURE__ */ ((BeatmapApprovedState3) => {
116
+ BeatmapApprovedState3[BeatmapApprovedState3["Graveyard"] = -2] = "Graveyard";
117
+ BeatmapApprovedState3[BeatmapApprovedState3["WIP"] = -1] = "WIP";
118
+ BeatmapApprovedState3[BeatmapApprovedState3["Pending"] = 0] = "Pending";
119
+ BeatmapApprovedState3[BeatmapApprovedState3["Ranked"] = 1] = "Ranked";
120
+ BeatmapApprovedState3[BeatmapApprovedState3["Approved"] = 2] = "Approved";
121
+ BeatmapApprovedState3[BeatmapApprovedState3["Qualified"] = 3] = "Qualified";
122
+ BeatmapApprovedState3[BeatmapApprovedState3["Loved"] = 4] = "Loved";
123
+ return BeatmapApprovedState3;
124
+ })(BeatmapApprovedState || {});
125
+ var BeatmapGenre = /* @__PURE__ */ ((BeatmapGenre3) => {
126
+ BeatmapGenre3[BeatmapGenre3["Any"] = 0] = "Any";
127
+ BeatmapGenre3[BeatmapGenre3["Unspecified"] = 1] = "Unspecified";
128
+ BeatmapGenre3[BeatmapGenre3["VideoGame"] = 2] = "VideoGame";
129
+ BeatmapGenre3[BeatmapGenre3["Anime"] = 3] = "Anime";
130
+ BeatmapGenre3[BeatmapGenre3["Rock"] = 4] = "Rock";
131
+ BeatmapGenre3[BeatmapGenre3["Pop"] = 5] = "Pop";
132
+ BeatmapGenre3[BeatmapGenre3["Other"] = 6] = "Other";
133
+ BeatmapGenre3[BeatmapGenre3["Novelty"] = 7] = "Novelty";
134
+ BeatmapGenre3[BeatmapGenre3["HipHop"] = 9] = "HipHop";
135
+ BeatmapGenre3[BeatmapGenre3["Electronic"] = 10] = "Electronic";
136
+ BeatmapGenre3[BeatmapGenre3["Metal"] = 11] = "Metal";
137
+ BeatmapGenre3[BeatmapGenre3["Classic"] = 12] = "Classic";
138
+ BeatmapGenre3[BeatmapGenre3["Folk"] = 13] = "Folk";
139
+ BeatmapGenre3[BeatmapGenre3["Jazz"] = 14] = "Jazz";
140
+ return BeatmapGenre3;
141
+ })(BeatmapGenre || {});
142
+ var BeatmapLanguage = /* @__PURE__ */ ((BeatmapLanguage3) => {
143
+ BeatmapLanguage3[BeatmapLanguage3["Any"] = 0] = "Any";
144
+ BeatmapLanguage3[BeatmapLanguage3["Unspecified"] = 1] = "Unspecified";
145
+ BeatmapLanguage3[BeatmapLanguage3["English"] = 2] = "English";
146
+ BeatmapLanguage3[BeatmapLanguage3["Japanese"] = 3] = "Japanese";
147
+ BeatmapLanguage3[BeatmapLanguage3["Chinese"] = 4] = "Chinese";
148
+ BeatmapLanguage3[BeatmapLanguage3["Instrumental"] = 5] = "Instrumental";
149
+ BeatmapLanguage3[BeatmapLanguage3["Korean"] = 6] = "Korean";
150
+ BeatmapLanguage3[BeatmapLanguage3["French"] = 7] = "French";
151
+ BeatmapLanguage3[BeatmapLanguage3["German"] = 8] = "German";
152
+ BeatmapLanguage3[BeatmapLanguage3["Swedish"] = 9] = "Swedish";
153
+ BeatmapLanguage3[BeatmapLanguage3["Spanish"] = 10] = "Spanish";
154
+ BeatmapLanguage3[BeatmapLanguage3["Italian"] = 11] = "Italian";
155
+ BeatmapLanguage3[BeatmapLanguage3["Russian"] = 12] = "Russian";
156
+ BeatmapLanguage3[BeatmapLanguage3["Polish"] = 13] = "Polish";
157
+ BeatmapLanguage3[BeatmapLanguage3["Other"] = 14] = "Other";
158
+ return BeatmapLanguage3;
159
+ })(BeatmapLanguage || {});
160
+ var ScoreRank = /* @__PURE__ */ ((ScoreRank2) => {
161
+ ScoreRank2[ScoreRank2["XH"] = 0] = "XH";
162
+ ScoreRank2[ScoreRank2["X"] = 1] = "X";
163
+ ScoreRank2[ScoreRank2["SH"] = 2] = "SH";
164
+ ScoreRank2[ScoreRank2["S"] = 3] = "S";
165
+ ScoreRank2[ScoreRank2["A"] = 4] = "A";
166
+ ScoreRank2[ScoreRank2["B"] = 5] = "B";
167
+ ScoreRank2[ScoreRank2["C"] = 6] = "C";
168
+ ScoreRank2[ScoreRank2["D"] = 7] = "D";
169
+ ScoreRank2[ScoreRank2["F"] = 8] = "F";
170
+ return ScoreRank2;
171
+ })(ScoreRank || {});
172
+ var MatchScoringType = /* @__PURE__ */ ((MatchScoringType2) => {
173
+ MatchScoringType2[MatchScoringType2["Score"] = 0] = "Score";
174
+ MatchScoringType2[MatchScoringType2["Accuracy"] = 1] = "Accuracy";
175
+ MatchScoringType2[MatchScoringType2["Combo"] = 2] = "Combo";
176
+ MatchScoringType2[MatchScoringType2["ScoreV2"] = 3] = "ScoreV2";
177
+ return MatchScoringType2;
178
+ })(MatchScoringType || {});
179
+ var MatchTeamType = /* @__PURE__ */ ((MatchTeamType2) => {
180
+ MatchTeamType2[MatchTeamType2["HeadToHead"] = 0] = "HeadToHead";
181
+ MatchTeamType2[MatchTeamType2["TagCoop"] = 1] = "TagCoop";
182
+ MatchTeamType2[MatchTeamType2["TeamVs"] = 2] = "TeamVs";
183
+ MatchTeamType2[MatchTeamType2["TagTeamVs"] = 3] = "TagTeamVs";
184
+ return MatchTeamType2;
185
+ })(MatchTeamType || {});
186
+ var Team = /* @__PURE__ */ ((Team2) => {
187
+ Team2[Team2["None"] = 0] = "None";
188
+ Team2[Team2["Blue"] = 1] = "Blue";
189
+ Team2[Team2["Red"] = 2] = "Red";
190
+ return Team2;
191
+ })(Team || {});
192
+
193
+ // src/utils/URLBuilder.ts
194
+ var URLBuilder = class {
195
+ static gameModeToURLPattern(mode) {
196
+ switch (mode) {
197
+ case 0 /* Standard */:
198
+ return "osu";
199
+ case 1 /* Taiko */:
200
+ return "taiko";
201
+ case 2 /* Catch */:
202
+ return "fruits";
203
+ case 3 /* Mania */:
204
+ return "mania";
205
+ default:
206
+ throw new Error("INVALID_GAMEMODE");
207
+ }
208
+ }
209
+ static avatar(id) {
210
+ return `https://a.ppy.sh/${id}`;
211
+ }
212
+ static profile(idOrName) {
213
+ return `https://osu.ppy.sh/users/${idOrName}`;
214
+ }
215
+ static banner(userId, hash, ext) {
216
+ return `https://assets.ppy.sh/user-profile-covers/${userId}/${hash}.${ext}`;
217
+ }
218
+ static defaultBanner(id, ext) {
219
+ return `https://osu.ppy.sh/images/headers/profile-covers/c${id}.${ext}`;
220
+ }
221
+ static beatmapsetURL(beatmapsetId) {
222
+ return `https://osu.ppy.sh/beatmapsets/${beatmapsetId}`;
223
+ }
224
+ static beatmapURL(beatmapsetId, beatmapId, mode) {
225
+ const m = URLBuilder.gameModeToURLPattern(mode);
226
+ return `https://osu.ppy.sh/beatmapsets/${beatmapsetId}#${m}/${beatmapId}`;
227
+ }
228
+ static beatmapCoverImage(beatmapsetId) {
229
+ return `https://assets.ppy.sh/beatmaps/${beatmapsetId}/covers/cover.jpg`;
230
+ }
231
+ static beatmapCoverThumbnail(beatmapsetId) {
232
+ return `https://b.ppy.sh/thumb/${beatmapsetId}l.jpg`;
233
+ }
234
+ static scoreURL(mode, scoreId) {
235
+ const m = URLBuilder.gameModeToURLPattern(mode);
236
+ return `https://osu.ppy.sh/scores/${m}/${scoreId}`;
237
+ }
238
+ };
239
+
240
+ // src/structures/ModsBitField.ts
241
+ var _ModsBitField = class {
242
+ constructor(bits = 0n) {
243
+ this.bitfield = _ModsBitField.resolve(bits);
244
+ }
245
+ any(bit) {
246
+ return (this.bitfield & _ModsBitField.resolve(bit)) !== 0n;
247
+ }
248
+ equals(bit) {
249
+ return this.bitfield === _ModsBitField.resolve(bit);
250
+ }
251
+ has(bit) {
252
+ bit = _ModsBitField.resolve(bit);
253
+ return (this.bitfield & bit) === bit;
254
+ }
255
+ add(...bits) {
256
+ let total = 0n;
257
+ for (const bit of bits) {
258
+ total |= _ModsBitField.resolve(bit);
259
+ }
260
+ this.bitfield |= total;
261
+ return this;
262
+ }
263
+ remove(...bits) {
264
+ let total = 0n;
265
+ for (const bit of bits) {
266
+ total |= _ModsBitField.resolve(bit);
267
+ }
268
+ this.bitfield &= ~total;
269
+ return this;
270
+ }
271
+ toArray() {
272
+ return Object.keys(_ModsBitField.Flags).filter((bit) => this.has(bit));
273
+ }
274
+ serialize() {
275
+ const serialized = {};
276
+ for (const [flag, bit] of Object.entries(_ModsBitField.Flags)) {
277
+ serialized[flag] = this.has(bit);
278
+ }
279
+ return serialized;
280
+ }
281
+ isNone() {
282
+ return this.bitfield === 0n;
283
+ }
284
+ valueOf() {
285
+ return this.bitfield;
286
+ }
287
+ static resolve(bit) {
288
+ if (Array.isArray(bit)) {
289
+ return bit.map(_ModsBitField.resolve).reduce((acc, now) => acc | now, 0n);
290
+ }
291
+ if (bit instanceof _ModsBitField) {
292
+ return bit.bitfield;
293
+ }
294
+ if (typeof bit === "number")
295
+ return BigInt(bit);
296
+ if (typeof bit === "string") {
297
+ if (!isNaN(+bit))
298
+ return BigInt(bit);
299
+ const a = _ModsBitField.Flags[bit];
300
+ if (typeof a === "undefined")
301
+ throw new Error("INVALID_BITFIELD");
302
+ return a;
303
+ }
304
+ return bit;
305
+ }
306
+ };
307
+ var ModsBitField = _ModsBitField;
308
+ ModsBitField.Flags = Mods;
309
+ ModsBitField.KeyMod = Mods.Key1 | Mods.Key2 | Mods.Key3 | Mods.Key4 | Mods.Key5 | Mods.Key6 | Mods.Key7 | Mods.Key8 | Mods.Key9 | Mods.KeyCoop;
310
+ ModsBitField.FreeModAllowed = Mods.NoFail | Mods.Easy | Mods.Hidden | Mods.HardRock | Mods.SuddenDeath | Mods.Flashlight | Mods.FadeIn | Mods.Relax | Mods.AutoPilot | Mods.SpunOut | _ModsBitField.KeyMod;
311
+ ModsBitField.ScoreIncreaseMods = Mods.Hidden | Mods.HardRock | Mods.DoubleTime | Mods.Flashlight | Mods.FadeIn;
312
+
313
+ // src/structures/BaseScore.ts
314
+ var BaseScore = class {
315
+ constructor(client, data, other) {
316
+ this.client = client;
317
+ this.score = +data.score;
318
+ this.maxCombo = +data.maxcombo;
319
+ this.statistics = {
320
+ count50: +data.count50,
321
+ count100: +data.count100,
322
+ count300: +data.count300,
323
+ countMiss: +data.countmiss,
324
+ countKatu: +data.countkatu,
325
+ countGeki: +data.countgeki
326
+ };
327
+ this.perfect = !!+data.perfect;
328
+ this.enabledMods = new ModsBitField(data.enabled_mods);
329
+ this.userId = data.user_id;
330
+ this.rank = ScoreRank[data.rank];
331
+ this.mode = other.mode ?? 0 /* Standard */;
332
+ if ("beatmap_id" in data) {
333
+ this.beatmapId = data.beatmap_id;
334
+ } else {
335
+ this.beatmapId = other.mapId;
336
+ }
337
+ }
338
+ async getPlayer(options = {}) {
339
+ const candidates = await this.client.users.getUser({
340
+ user: this.userId,
341
+ type: "id" /* Id */,
342
+ ...options
343
+ });
344
+ return candidates[0];
345
+ }
346
+ async getBeatmap() {
347
+ const candidates = await this.client.beatmaps.getBeatmaps({
348
+ beatmapId: this.beatmapId,
349
+ mode: this.mode
350
+ });
351
+ return candidates[0];
352
+ }
353
+ getReplay() {
354
+ return this.client.replays.getReplay({
355
+ beatmapId: this.beatmapId,
356
+ user: this.userId,
357
+ type: "id" /* Id */
358
+ });
359
+ }
360
+ };
361
+
362
+ // src/structures/BeatmapScore.ts
363
+ var BeatmapScore = class extends BaseScore {
364
+ constructor(client, data, other) {
365
+ super(client, data, other);
366
+ this.scoreId = null;
367
+ this.username = null;
368
+ this.pp = null;
369
+ this.replayAvailable = null;
370
+ this.date = new Date(data.date);
371
+ if ("score_id" in data) {
372
+ this.scoreId = data.score_id;
373
+ }
374
+ if ("username" in data) {
375
+ this.username = data.username;
376
+ }
377
+ if ("pp" in data) {
378
+ this.pp = +data.pp;
379
+ }
380
+ if ("replay_available" in data) {
381
+ this.replayAvailable = !!+data.replay_available;
382
+ }
383
+ }
384
+ scoreURL() {
385
+ if (!this.scoreId)
386
+ return null;
387
+ return URLBuilder.scoreURL(this.mode, this.scoreId);
388
+ }
389
+ };
390
+
391
+ // src/structures/UserEvent.ts
392
+ var UserEvent = class {
393
+ constructor(user, data) {
394
+ this.user = user;
395
+ this.displayHtml = data.display_html;
396
+ this.beatmapId = data.beatmap_id;
397
+ this.beatmapsetId = data.beatmapset_id;
398
+ this.date = new Date(data.date);
399
+ this.epicfactor = +data.epicfactor;
400
+ }
401
+ async getBeatmap() {
402
+ const candidates = await this.user.client.beatmaps.getBeatmaps({
403
+ beatmapId: this.beatmapId,
404
+ beatmapsetId: this.beatmapsetId
405
+ });
406
+ return candidates[0];
407
+ }
408
+ async getBeatmapset() {
409
+ const beatmap = await this.getBeatmap();
410
+ return beatmap?.getBeatmapset();
411
+ }
412
+ };
413
+
414
+ // src/structures/User.ts
415
+ var User = class {
416
+ constructor(client, data) {
417
+ this.client = client;
418
+ this.id = data.user_id;
419
+ this.username = data.username;
420
+ this.joinDate = new Date(data.join_date);
421
+ this.count300 = +data.count300;
422
+ this.count100 = +data.count100;
423
+ this.count50 = +data.count50;
424
+ this.playcount = +data.playcount;
425
+ this.playtime = +data.total_seconds_played;
426
+ this.rankedScore = +data.ranked_score;
427
+ this.totalScore = +data.total_score;
428
+ this.rank = +data.pp_rank;
429
+ this.level = +data.level;
430
+ this.pp = +data.pp_raw;
431
+ this.accuracy = +data.accuracy;
432
+ this.scoreRankCount = {
433
+ ss: +data.count_rank_ss,
434
+ ssh: +data.count_rank_ssh,
435
+ s: +data.count_rank_s,
436
+ sh: +data.count_rank_sh,
437
+ a: +data.count_rank_a
438
+ };
439
+ this.country = data.country;
440
+ this.countryRank = +data.pp_country_rank;
441
+ this.events = data.events.map((v) => new UserEvent(this, v));
442
+ this.banner = null;
443
+ }
444
+ avatarURL() {
445
+ return URLBuilder.avatar(this.id);
446
+ }
447
+ profileURL() {
448
+ return URLBuilder.profile(this.id);
449
+ }
450
+ async fetchBanner(force = false) {
451
+ if (!force && this.banner)
452
+ return this.banner;
453
+ const url = await this.client.users.fetchBanner({ id: this.id });
454
+ return this.banner = url;
455
+ }
456
+ };
457
+
458
+ // src/managers/BaseManager.ts
459
+ var BaseManager = class {
460
+ constructor(client) {
461
+ this.client = client;
462
+ }
463
+ };
464
+
465
+ // src/managers/UserManager.ts
466
+ var UserManager = class extends BaseManager {
467
+ async getUser(options) {
468
+ const queries = {
469
+ u: options.user,
470
+ m: options.gameMode,
471
+ type: options.type,
472
+ event_days: options.eventDays
473
+ };
474
+ const res = await this.client.request({
475
+ path: "get_user",
476
+ queries
477
+ });
478
+ return res.map((v) => new User(this.client, v));
479
+ }
480
+ async fetchBanner({ id }) {
481
+ const context = await request.get(`https://osu.ppy.sh/users/${id}`);
482
+ const banner_regex = new RegExp(`https:\\\\\\/\\\\\\/assets\\.ppy\\.sh\\\\\\/user-profile-covers\\\\\\/${id}\\\\\\/(?<hash>[0-9a-z]*?)\\.(?<ext>.*?)&`, "gm");
483
+ const banner = banner_regex.exec(context.text);
484
+ if (banner) {
485
+ const url2 = URLBuilder.banner(id, banner?.groups?.hash, banner?.groups?.ext);
486
+ return url2;
487
+ }
488
+ const default_banner_regex = new RegExp("https:\\\\\\/\\\\\\/osu\\.ppy\\.sh\\\\\\/images\\\\\\/headers\\\\\\/profile-covers\\\\\\/c(?<id>\\d)\\.(?<ext>.*?)&", "gm");
489
+ const defaultBanner = default_banner_regex.exec(context.text);
490
+ const url = URLBuilder.defaultBanner(defaultBanner?.groups?.id, defaultBanner?.groups?.ext);
491
+ return url;
492
+ }
493
+ async getUserBest(options) {
494
+ const queries = {
495
+ u: options.user,
496
+ m: options.mode,
497
+ type: options.type,
498
+ limit: options.limit
499
+ };
500
+ const res = await this.client.request({
501
+ path: "get_user_best",
502
+ queries
503
+ });
504
+ return res.map((v) => new BeatmapScore(this.client, v, { mode: options.mode }));
505
+ }
506
+ async getUserRecent(options) {
507
+ const queries = {
508
+ u: options.user,
509
+ m: options.mode,
510
+ type: options.type,
511
+ limit: options.limit
512
+ };
513
+ const res = await this.client.request({
514
+ path: "get_user_recent",
515
+ queries
516
+ });
517
+ return res.map((v) => new BeatmapScore(this.client, v, { mode: options.mode }));
518
+ }
519
+ };
520
+
521
+ // src/utils/toSqlDate.ts
522
+ function toSqlDate(date) {
523
+ return date.toISOString().slice(0, 19).replace("T", " ");
524
+ }
525
+
526
+ // src/structures/Beatmapset.ts
527
+ var Beatmapset = class {
528
+ constructor(client, data, maps) {
529
+ this.client = client;
530
+ this.beatmaps = maps;
531
+ this.id = data.beatmapsetId;
532
+ this.approvedState = data.approvedState;
533
+ this.length = data.totalLength;
534
+ this.submitDate = data.submitDate;
535
+ this.approvedDate = data.approvedDate;
536
+ this.lastUpdate = data.lastUpdate;
537
+ this.artist = data.artist;
538
+ this.title = data.title;
539
+ this.creator = data.creator;
540
+ this.creatorId = data.creatorId;
541
+ this.source = data.source;
542
+ this.tags = data.tags.slice();
543
+ this.genre = data.genre;
544
+ this.language = data.language;
545
+ this.favoriteCount = data.favoriteCount;
546
+ this.rating = data.rating;
547
+ this.downloadUnavailable = data.downloadUnavailable;
548
+ this.audioUnavailable = data.audioUnavailable;
549
+ }
550
+ beatmapsetURL() {
551
+ return URLBuilder.beatmapsetURL(this.id);
552
+ }
553
+ coverImageURL() {
554
+ return URLBuilder.beatmapCoverImage(this.id);
555
+ }
556
+ coverThumbnailURL() {
557
+ return URLBuilder.beatmapCoverThumbnail(this.id);
558
+ }
559
+ async getCreator() {
560
+ const candidates = await this.client.users.getUser({
561
+ user: this.creatorId,
562
+ type: "id" /* Id */
563
+ });
564
+ return candidates[0];
565
+ }
566
+ };
567
+
568
+ // src/structures/Beatmap.ts
569
+ var Beatmap = class {
570
+ constructor(client, data) {
571
+ this.client = client;
572
+ this.id = data.beatmap_id;
573
+ this.beatmapsetId = data.beatmapset_id;
574
+ this.approvedState = +data.approved;
575
+ this.totalLength = +data.total_length;
576
+ this.hitLength = +data.hit_length;
577
+ this.diffcultyName = data.version;
578
+ this.hash = data.file_md5;
579
+ this.difficulty = {
580
+ ApproachRate: +data.diff_approach,
581
+ CircleSize: +data.diff_size,
582
+ OverallDifficulty: +data.diff_overall,
583
+ HPDrainRate: +data.diff_drain,
584
+ aim: +(data.diff_aim ?? 0),
585
+ speed: +(data.diff_speed ?? 0),
586
+ rating: +(data.difficultyrating ?? 0)
587
+ };
588
+ this.mode = +data.mode;
589
+ this.objectCount = {
590
+ circle: +data.count_normal,
591
+ slider: +data.count_slider,
592
+ spinner: +data.count_spinner
593
+ };
594
+ this.submitDate = new Date(data.submit_date);
595
+ if (!data.approved_date) {
596
+ this.approvedDate = null;
597
+ } else {
598
+ this.approvedDate = new Date(data.approved_date);
599
+ }
600
+ this.lastUpdate = new Date(data.last_update);
601
+ this.artist = data.artist;
602
+ this.title = data.title;
603
+ this.creator = data.creator;
604
+ this.creatorId = data.creator_id;
605
+ this.bpm = +data.bpm;
606
+ this.source = data.source;
607
+ this.tags = data.tags.split(" ");
608
+ this.genre = +data.genre_id;
609
+ this.language = +data.language_id;
610
+ this.favoriteCount = +data.favourite_count;
611
+ this.rating = +data.rating;
612
+ this.downloadUnavailable = !!+data.download_unavailable;
613
+ this.audioUnavailable = !!+data.audio_unavailable;
614
+ this.playcount = +data.playcount;
615
+ this.passcount = +data.passcount;
616
+ if (data.max_combo) {
617
+ this.maxCombo = +data.max_combo;
618
+ } else {
619
+ this.maxCombo = null;
620
+ }
621
+ }
622
+ beatmapsetURL() {
623
+ return URLBuilder.beatmapsetURL(this.beatmapsetId);
624
+ }
625
+ beatmapURL() {
626
+ return URLBuilder.beatmapURL(this.beatmapsetId, this.id, this.mode);
627
+ }
628
+ coverImageURL() {
629
+ return URLBuilder.beatmapCoverImage(this.beatmapsetId);
630
+ }
631
+ coverThumbnailURL() {
632
+ return URLBuilder.beatmapCoverThumbnail(this.beatmapsetId);
633
+ }
634
+ async getCreator() {
635
+ const candidates = await this.client.users.getUser({
636
+ user: this.creatorId,
637
+ type: "id" /* Id */
638
+ });
639
+ return candidates[0];
640
+ }
641
+ async getBeatmapset() {
642
+ const set = await this.client.beatmaps.getBeatmaps({
643
+ beatmapsetId: this.beatmapsetId
644
+ });
645
+ return new Beatmapset(this.client, this, set);
646
+ }
647
+ };
648
+
649
+ // src/managers/BeatmapManager.ts
650
+ var BeatmapManager = class extends BaseManager {
651
+ async getBeatmaps(options = {}) {
652
+ const queries = {
653
+ since: options.since && toSqlDate(options.since),
654
+ s: options.beatmapsetId,
655
+ b: options.beatmapId,
656
+ u: options.user,
657
+ type: options.type,
658
+ m: options.mode,
659
+ a: options.showConverted,
660
+ h: options.hash,
661
+ limit: options.limit,
662
+ mods: ModsBitField.resolve(options.mods ?? 0)
663
+ };
664
+ const res = await this.client.request({
665
+ path: "get_beatmaps",
666
+ queries
667
+ });
668
+ return res.map((v) => new Beatmap(this.client, v));
669
+ }
670
+ };
671
+
672
+ // src/managers/ScoreManager.ts
673
+ var ScoreManager = class extends BaseManager {
674
+ async getScores(options) {
675
+ const mods = options.mods == void 0 ? void 0 : ModsBitField.resolve(options.mods);
676
+ const queries = {
677
+ b: options.beatmapId,
678
+ u: options.user,
679
+ m: options.mode,
680
+ mods,
681
+ type: options.type,
682
+ limit: options.limit
683
+ };
684
+ const res = await this.client.request({
685
+ path: "get_scores",
686
+ queries
687
+ });
688
+ return res.map((v) => new BeatmapScore(this.client, v, { mapId: options.beatmapId, mode: options.mode }));
689
+ }
690
+ };
691
+
692
+ // src/structures/Replay.ts
693
+ var import_node_buffer = require("buffer");
694
+ var Replay = class {
695
+ constructor(client, data) {
696
+ this.client = client;
697
+ this.content = data.content;
698
+ this.stream = import_node_buffer.Buffer.from(this.content, "base64");
699
+ }
700
+ };
701
+
702
+ // src/managers/ReplayManager.ts
703
+ var ReplayManager = class extends BaseManager {
704
+ async getReplay(options) {
705
+ if ((!options.beatmapId || !options.user) && !options.scoreId) {
706
+ throw new Error("You should provide either beatmapId and user or scordId to get replay");
707
+ }
708
+ const mods = options.mods == void 0 ? void 0 : ModsBitField.resolve(options.mods);
709
+ const queries = {
710
+ b: options.beatmapId,
711
+ u: options.user,
712
+ m: options.mode,
713
+ s: options.scoreId,
714
+ type: options.type,
715
+ mods
716
+ };
717
+ const res = await this.client.request({
718
+ path: "get_replay",
719
+ queries
720
+ });
721
+ return new Replay(this.client, res);
722
+ }
723
+ };
724
+
725
+ // src/structures/MatchScore.ts
726
+ var MatchScore = class extends BaseScore {
727
+ constructor(client, data, other) {
728
+ super(client, data, other);
729
+ this.slot = +data.slot;
730
+ this.team = +data.team;
731
+ this.pass = !!+data.pass;
732
+ }
733
+ };
734
+
735
+ // src/structures/MatchGame.ts
736
+ var MatchGame = class {
737
+ constructor(match, data) {
738
+ this.client = match.client;
739
+ this.match = match;
740
+ this.id = data.game_id;
741
+ this.startAt = new Date(data.start_time);
742
+ this.endAt = new Date(data.end_time);
743
+ this.beatmapId = data.beatmap_id;
744
+ this.mode = +data.play_mode;
745
+ this.matchType = +data.match_type;
746
+ this.scoringType = +data.scoring_type;
747
+ this.teamType = +data.team_type;
748
+ this.mods = new ModsBitField(data.mods);
749
+ this.scores = data.scores.map((score) => new MatchScore(this.client, score, {
750
+ mode: +data.play_mode,
751
+ mapId: data.beatmap_id
752
+ }));
753
+ }
754
+ async getBeatmap() {
755
+ const candidates = await this.client.beatmaps.getBeatmaps({
756
+ beatmapId: this.beatmapId
757
+ });
758
+ return candidates[0];
759
+ }
760
+ };
761
+
762
+ // src/structures/Match.ts
763
+ var Match = class {
764
+ constructor(client, data) {
765
+ this.client = client;
766
+ const { match, games } = data;
767
+ this.id = match.match_id;
768
+ this.name = match.name;
769
+ this.startAt = new Date(match.start_time);
770
+ if (match.end_time) {
771
+ this.endAt = new Date(match.end_time);
772
+ } else {
773
+ this.endAt = null;
774
+ }
775
+ this.games = games.map((data2) => new MatchGame(this, data2));
776
+ }
777
+ };
778
+
779
+ // src/managers/MatchManager.ts
780
+ var MatchManager = class extends BaseManager {
781
+ async getMatch(options) {
782
+ const queries = {
783
+ mp: options.matchId
784
+ };
785
+ const res = await this.client.request({
786
+ path: "get_match",
787
+ queries
788
+ });
789
+ if (res.match === 0) {
790
+ return null;
791
+ }
792
+ return new Match(this.client, res);
793
+ }
794
+ };
795
+
796
+ // src/Client.ts
797
+ var Client = class {
798
+ constructor(options) {
799
+ this.apiKey = options.apiKey;
800
+ this.users = new UserManager(this);
801
+ this.beatmaps = new BeatmapManager(this);
802
+ this.scores = new ScoreManager(this);
803
+ this.replays = new ReplayManager(this);
804
+ this.matches = new MatchManager(this);
805
+ }
806
+ async request(options) {
807
+ if (!options?.path)
808
+ throw new Error("MISSING_PATH");
809
+ const response = await request2.get(`https://osu.ppy.sh/api/${options.path}`).query({ k: this.apiKey }).query(options.queries);
810
+ return response.body;
811
+ }
812
+ };
813
+ // Annotate the CommonJS export names for ESM import in node:
814
+ 0 && (module.exports = {
815
+ BaseManager,
816
+ BaseScore,
817
+ Beatmap,
818
+ BeatmapApprovedState,
819
+ BeatmapGenre,
820
+ BeatmapLanguage,
821
+ BeatmapManager,
822
+ BeatmapScore,
823
+ Beatmapset,
824
+ Client,
825
+ GameMode,
826
+ Match,
827
+ MatchGame,
828
+ MatchManager,
829
+ MatchScore,
830
+ MatchScoringType,
831
+ MatchTeamType,
832
+ Mods,
833
+ ModsBitField,
834
+ Replay,
835
+ ReplayManager,
836
+ ScoreManager,
837
+ ScoreRank,
838
+ Team,
839
+ URLBuilder,
840
+ User,
841
+ UserEvent,
842
+ UserManager,
843
+ UserRequestType
844
+ });
845
+ //# sourceMappingURL=index.js.map