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