@hizollo/osu-api 1.2.0 → 1.2.2

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