lunibee 0.1.0 → 0.1.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.
Files changed (67) hide show
  1. package/README.md +229 -0
  2. package/dist/builders/attachment.d.ts +20 -0
  3. package/dist/builders/commands.d.ts +118 -0
  4. package/dist/builders/components.d.ts +151 -0
  5. package/dist/builders/embed.d.ts +59 -0
  6. package/dist/builders/index.d.ts +5 -0
  7. package/dist/builders/index.js +828 -0
  8. package/dist/builders/index.js.map +13 -0
  9. package/dist/collection/cache.d.ts +37 -0
  10. package/dist/collection/index.d.ts +47 -0
  11. package/dist/collection/index.js +214 -0
  12. package/dist/collection/index.js.map +11 -0
  13. package/dist/core/client-state.d.ts +10 -0
  14. package/dist/core/collector.d.ts +27 -0
  15. package/dist/core/events.d.ts +5 -0
  16. package/dist/core/index.d.ts +111 -0
  17. package/dist/core/index.js +3188 -0
  18. package/dist/core/index.js.map +29 -0
  19. package/dist/core/permissions.d.ts +293 -0
  20. package/dist/formatters/index.d.ts +10 -0
  21. package/dist/formatters/index.js +43 -0
  22. package/dist/formatters/index.js.map +10 -0
  23. package/dist/handlers/index.d.ts +16 -0
  24. package/dist/handlers/index.js +37 -0
  25. package/dist/handlers/index.js.map +10 -0
  26. package/{src/index.ts → dist/index.d.ts} +2 -29
  27. package/dist/index.js +4182 -0
  28. package/dist/index.js.map +41 -0
  29. package/dist/managers/application.d.ts +28 -0
  30. package/dist/managers/base.d.ts +28 -0
  31. package/dist/managers/index.d.ts +96 -0
  32. package/dist/managers/index.js +947 -0
  33. package/dist/managers/index.js.map +22 -0
  34. package/dist/managers/member.d.ts +35 -0
  35. package/dist/managers/message.d.ts +25 -0
  36. package/dist/managers/role.d.ts +34 -0
  37. package/dist/managers/thread.d.ts +14 -0
  38. package/dist/rest/index.d.ts +49 -0
  39. package/dist/rest/index.js +344 -0
  40. package/dist/rest/index.js.map +12 -0
  41. package/dist/rest/routes.d.ts +44 -0
  42. package/dist/rest/types.d.ts +26 -0
  43. package/dist/rest/webhook.d.ts +40 -0
  44. package/dist/sharding/bus.d.ts +22 -0
  45. package/dist/sharding/index.d.ts +34 -0
  46. package/dist/sharding/index.js +732 -0
  47. package/dist/sharding/index.js.map +13 -0
  48. package/dist/structures/base.d.ts +75 -0
  49. package/dist/structures/index.d.ts +39 -0
  50. package/dist/structures/index.js +571 -0
  51. package/dist/structures/index.js.map +14 -0
  52. package/dist/structures/interactions.d.ts +136 -0
  53. package/dist/structures/permissions.d.ts +73 -0
  54. package/dist/structures/resources.d.ts +64 -0
  55. package/dist/types/index.d.ts +535 -0
  56. package/dist/types/index.js +132 -0
  57. package/dist/types/index.js.map +10 -0
  58. package/dist/utils/index.d.ts +6 -0
  59. package/dist/utils/index.js +18 -0
  60. package/dist/utils/index.js.map +10 -0
  61. package/dist/voice/index.d.ts +97 -0
  62. package/dist/voice/index.js +161 -0
  63. package/dist/voice/index.js.map +10 -0
  64. package/dist/ws/index.d.ts +76 -0
  65. package/dist/ws/index.js +582 -0
  66. package/dist/ws/index.js.map +11 -0
  67. package/package.json +113 -28
@@ -0,0 +1,947 @@
1
+ // @bun
2
+ // packages/collection/src/index.ts
3
+ class Collection extends Map {
4
+ first() {
5
+ for (const value of this.values())
6
+ return value;
7
+ return;
8
+ }
9
+ firstKey() {
10
+ for (const key of this.keys())
11
+ return key;
12
+ return;
13
+ }
14
+ last() {
15
+ let value;
16
+ for (const item of this.values())
17
+ value = item;
18
+ return value;
19
+ }
20
+ lastKey() {
21
+ let key;
22
+ for (const item of this.keys())
23
+ key = item;
24
+ return key;
25
+ }
26
+ find(predicate) {
27
+ for (const [key, value] of this) {
28
+ if (predicate(value, key, this))
29
+ return value;
30
+ }
31
+ return;
32
+ }
33
+ filter(predicate) {
34
+ const result = new Collection;
35
+ for (const [key, value] of this) {
36
+ if (predicate(value, key, this))
37
+ result.set(key, value);
38
+ }
39
+ return result;
40
+ }
41
+ map(transform) {
42
+ const result = [];
43
+ for (const [key, value] of this) {
44
+ result.push(transform(value, key, this));
45
+ }
46
+ return result;
47
+ }
48
+ some(predicate) {
49
+ for (const [key, value] of this) {
50
+ if (predicate(value, key, this))
51
+ return true;
52
+ }
53
+ return false;
54
+ }
55
+ every(predicate) {
56
+ for (const [key, value] of this) {
57
+ if (!predicate(value, key, this))
58
+ return false;
59
+ }
60
+ return true;
61
+ }
62
+ each(callback) {
63
+ for (const [key, value] of this) {
64
+ callback(value, key, this);
65
+ }
66
+ return this;
67
+ }
68
+ array() {
69
+ return [...this.values()];
70
+ }
71
+ keyArray() {
72
+ return [...this.keys()];
73
+ }
74
+ entriesArray() {
75
+ return [...this.entries()];
76
+ }
77
+ clone() {
78
+ const copy = new Collection;
79
+ for (const [key, value] of this)
80
+ copy.set(key, value);
81
+ return copy;
82
+ }
83
+ hasAll(...keys) {
84
+ for (let i = 0;i < keys.length; i++) {
85
+ if (!this.has(keys[i]))
86
+ return false;
87
+ }
88
+ return true;
89
+ }
90
+ hasAny(...keys) {
91
+ for (let i = 0;i < keys.length; i++) {
92
+ if (this.has(keys[i]))
93
+ return true;
94
+ }
95
+ return false;
96
+ }
97
+ findKey(predicate) {
98
+ for (const [key, value] of this) {
99
+ if (predicate(value, key, this))
100
+ return key;
101
+ }
102
+ return;
103
+ }
104
+ someEntry(predicate) {
105
+ return this.some(predicate);
106
+ }
107
+ sweep(predicate) {
108
+ let removed = 0;
109
+ for (const [key, value] of this) {
110
+ if (predicate(value, key, this) && this.delete(key))
111
+ removed++;
112
+ }
113
+ return removed;
114
+ }
115
+ firstEntry() {
116
+ for (const [key, value] of this)
117
+ return [key, value];
118
+ return;
119
+ }
120
+ lastEntry() {
121
+ let entry;
122
+ for (const item of this)
123
+ entry = [item[0], item[1]];
124
+ return entry;
125
+ }
126
+ }
127
+
128
+ // packages/managers/src/base.ts
129
+ class Manager {
130
+ cache = new Collection;
131
+ get(id) {
132
+ return this.cache.get(id);
133
+ }
134
+ has(id) {
135
+ return this.cache.has(id);
136
+ }
137
+ set(id, value) {
138
+ this.cache.set(id, value);
139
+ return this;
140
+ }
141
+ delete(id) {
142
+ return this.cache.delete(id);
143
+ }
144
+ clear() {
145
+ this.cache.clear();
146
+ }
147
+ get size() {
148
+ return this.cache.size;
149
+ }
150
+ first() {
151
+ return this.cache.first();
152
+ }
153
+ values() {
154
+ return this.cache.array();
155
+ }
156
+ find(predicate) {
157
+ return this.cache.find(predicate);
158
+ }
159
+ [Symbol.iterator]() {
160
+ return this.cache[Symbol.iterator]();
161
+ }
162
+ }
163
+
164
+ class ResourceManager extends Manager {
165
+ #fetcher;
166
+ #key;
167
+ constructor(fetcher, key) {
168
+ super();
169
+ if (typeof fetcher !== "function" || typeof key !== "function")
170
+ throw new TypeError("ResourceManager requires fetcher and key functions.");
171
+ this.#fetcher = fetcher;
172
+ this.#key = key;
173
+ }
174
+ async resolve(id) {
175
+ return this.get(id) ?? this.fetch(id);
176
+ }
177
+ async fetch(id) {
178
+ const resource = await this.#fetcher(id);
179
+ this.set(id, resource);
180
+ return resource;
181
+ }
182
+ async fetchMany(ids) {
183
+ return Promise.all([...ids].map((id) => this.resolve(id)));
184
+ }
185
+ upsert(resource) {
186
+ const key = this.#key(resource);
187
+ this.set(key, resource);
188
+ return resource;
189
+ }
190
+ update(resource) {
191
+ return this.upsert(resource);
192
+ }
193
+ }
194
+ // packages/rest/src/routes.ts
195
+ var Routes = {
196
+ user: () => "/users/@me",
197
+ userById: (userId) => `/users/${snowflake(userId, "User ID")}`,
198
+ guild: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}`,
199
+ guildChannels: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/channels`,
200
+ guildMember: (guildId, userId) => `/guilds/${snowflake(guildId, "Guild ID")}/members/${snowflake(userId, "User ID")}`,
201
+ guildRoles: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/roles`,
202
+ guildRole: (guildId, roleId) => `/guilds/${snowflake(guildId, "Guild ID")}/roles/${snowflake(roleId, "Role ID")}`,
203
+ guildMemberRole: (guildId, userId, roleId) => `/guilds/${snowflake(guildId, "Guild ID")}/members/${snowflake(userId, "User ID")}/roles/${snowflake(roleId, "Role ID")}`,
204
+ guildBans: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/bans`,
205
+ guildBan: (guildId, userId) => `/guilds/${snowflake(guildId, "Guild ID")}/bans/${snowflake(userId, "User ID")}`,
206
+ channel: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}`,
207
+ channelMessages: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/messages`,
208
+ message: (channelId, messageId) => `/channels/${snowflake(channelId, "Channel ID")}/messages/${snowflake(messageId, "Message ID")}`,
209
+ crosspostMessage: (channelId, messageId) => `${Routes.message(channelId, messageId)}/crosspost`,
210
+ messageReactions: (channelId, messageId, emoji) => `${Routes.message(channelId, messageId)}/reactions/${encodeURIComponent(emoji)}`,
211
+ messageReactionsAll: (channelId, messageId) => `${Routes.message(channelId, messageId)}/reactions`,
212
+ channelPins: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/pins`,
213
+ channelPin: (channelId, messageId) => `/channels/${snowflake(channelId, "Channel ID")}/pins/${snowflake(messageId, "Message ID")}`,
214
+ messageThread: (channelId, messageId) => `${Routes.message(channelId, messageId)}/threads`,
215
+ channelBulkDelete: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/messages/bulk-delete`,
216
+ channelWebhooks: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/webhooks`,
217
+ channelInvites: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/invites`,
218
+ webhook: (webhookId, token) => `/webhooks/${snowflake(webhookId, "Webhook ID")}${token ? `/${encodeURIComponent(token)}` : ""}`,
219
+ webhookMessage: (webhookId, token, messageId) => `/webhooks/${snowflake(webhookId, "Webhook ID")}/${encodeURIComponent(token)}/messages/${snowflake(messageId, "Message ID")}`,
220
+ applicationCommands: (applicationId) => `/applications/${snowflake(applicationId, "Application ID")}/commands`,
221
+ applicationCommand: (applicationId, commandId) => `/applications/${snowflake(applicationId, "Application ID")}/commands/${snowflake(commandId, "Command ID")}`,
222
+ guildApplicationCommands: (applicationId, guildId) => `/applications/${snowflake(applicationId, "Application ID")}/guilds/${snowflake(guildId, "Guild ID")}/commands`,
223
+ guildApplicationCommand: (applicationId, guildId, commandId) => `/applications/${snowflake(applicationId, "Application ID")}/guilds/${snowflake(guildId, "Guild ID")}/commands/${snowflake(commandId, "Command ID")}`,
224
+ interactionCallback: (interactionId, token) => `/interactions/${snowflake(interactionId, "Interaction ID")}/${encodeURIComponent(token)}/callback`,
225
+ interactionOriginalResponse: (applicationId, token) => `/webhooks/${snowflake(applicationId, "Application ID")}/${encodeURIComponent(token)}/messages/@original`,
226
+ guildActiveThreads: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/threads/active`,
227
+ channelPublicArchivedThreads: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/threads/archived/public`,
228
+ channelPrivateArchivedThreads: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/threads/archived/private`,
229
+ threadMembers: (threadId) => `/channels/${snowflake(threadId, "Thread ID")}/thread-members`,
230
+ guildScheduledEvents: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/scheduled-events`,
231
+ guildScheduledEvent: (guildId, eventId) => `/guilds/${snowflake(guildId, "Guild ID")}/scheduled-events/${snowflake(eventId, "Event ID")}`,
232
+ guildAutoModerationRules: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/auto-moderation/rules`,
233
+ guildAutoModerationRule: (guildId, ruleId) => `/guilds/${snowflake(guildId, "Guild ID")}/auto-moderation/rules/${snowflake(ruleId, "Rule ID")}`,
234
+ voiceRegions: () => "/voice/regions",
235
+ gateway: () => "/gateway",
236
+ gatewayBot: () => "/gateway/bot"
237
+ };
238
+ function snowflake(value, field) {
239
+ if (!/^\d{1,20}$/.test(value))
240
+ throw new TypeError(`${field} must be a valid Discord snowflake.`);
241
+ return value;
242
+ }
243
+ // packages/structures/src/base.ts
244
+ class BaseStructure {
245
+ id;
246
+ constructor(id) {
247
+ if (!/^\d{1,20}$/.test(id))
248
+ throw new TypeError("A Discord structure requires a valid snowflake ID.");
249
+ this.id = id;
250
+ }
251
+ toString() {
252
+ return this.id;
253
+ }
254
+ }
255
+
256
+ class User extends BaseStructure {
257
+ username;
258
+ globalName;
259
+ avatar;
260
+ bot;
261
+ system;
262
+ flags;
263
+ constructor(data) {
264
+ super(data.id);
265
+ if (!data.username)
266
+ throw new TypeError("A Discord user requires a username.");
267
+ this.username = data.username;
268
+ this.globalName = data.global_name ?? null;
269
+ this.avatar = data.avatar ?? null;
270
+ this.bot = data.bot ?? false;
271
+ this.system = data.system ?? false;
272
+ this.flags = data.public_flags ?? 0;
273
+ }
274
+ get displayName() {
275
+ return this.globalName ?? this.username;
276
+ }
277
+ avatarURL(options = {}) {
278
+ if (!this.avatar)
279
+ return null;
280
+ const extension = options.extension ?? (this.avatar.startsWith("a_") ? "gif" : "png");
281
+ return `https://cdn.discordapp.com/avatars/${this.id}/${this.avatar}.${extension}${options.size ? `?size=${options.size}` : ""}`;
282
+ }
283
+ defaultAvatarURL() {
284
+ return `https://cdn.discordapp.com/embed/avatars/${Number(BigInt(this.id) % 5n)}.png`;
285
+ }
286
+ displayAvatarURL(options = {}) {
287
+ return this.avatarURL(options) ?? this.defaultAvatarURL();
288
+ }
289
+ }
290
+
291
+ class Channel extends BaseStructure {
292
+ type;
293
+ name;
294
+ guildId;
295
+ #context;
296
+ constructor(data, context) {
297
+ super(data.id);
298
+ if (!Number.isInteger(data.type) || data.type < 0)
299
+ throw new RangeError("A Discord channel requires a valid channel type.");
300
+ this.type = data.type;
301
+ this.name = data.name;
302
+ this.guildId = data.guild_id;
303
+ this.#context = context;
304
+ }
305
+ sendMessage(options) {
306
+ if (!this.#context)
307
+ throw new Error("This channel is not attached to a client.");
308
+ return this.#context.sendMessage(this.id, options);
309
+ }
310
+ }
311
+
312
+ class Guild extends BaseStructure {
313
+ name;
314
+ preferredLocale;
315
+ ownerId;
316
+ constructor(data) {
317
+ super(data.id);
318
+ if (!data.name)
319
+ throw new TypeError("A Discord guild requires a name.");
320
+ this.name = data.name;
321
+ this.preferredLocale = data.preferred_locale;
322
+ this.ownerId = data.owner_id;
323
+ }
324
+ }
325
+ // packages/structures/src/permissions.ts
326
+ var Permissions = {
327
+ CreateInstantInvite: 1n << 0n,
328
+ KickMembers: 1n << 1n,
329
+ BanMembers: 1n << 2n,
330
+ Administrator: 1n << 3n,
331
+ ManageChannels: 1n << 4n,
332
+ ManageGuild: 1n << 5n,
333
+ AddReactions: 1n << 6n,
334
+ ViewAuditLog: 1n << 7n,
335
+ PrioritySpeaker: 1n << 8n,
336
+ Stream: 1n << 9n,
337
+ ViewChannel: 1n << 10n,
338
+ SendMessages: 1n << 11n,
339
+ SendTTSMessages: 1n << 12n,
340
+ ManageMessages: 1n << 13n,
341
+ EmbedLinks: 1n << 14n,
342
+ AttachFiles: 1n << 15n,
343
+ ReadMessageHistory: 1n << 16n,
344
+ MentionEveryone: 1n << 17n,
345
+ UseExternalEmojis: 1n << 18n,
346
+ ViewGuildInsights: 1n << 19n,
347
+ Connect: 1n << 20n,
348
+ Speak: 1n << 21n,
349
+ MuteMembers: 1n << 22n,
350
+ DeafenMembers: 1n << 23n,
351
+ MoveMembers: 1n << 24n,
352
+ UseVAD: 1n << 25n,
353
+ ChangeNickname: 1n << 26n,
354
+ ManageNicknames: 1n << 27n,
355
+ ManageRoles: 1n << 28n,
356
+ ManageWebhooks: 1n << 29n,
357
+ ManageGuildExpressions: 1n << 30n,
358
+ UseApplicationCommands: 1n << 31n,
359
+ RequestToSpeak: 1n << 32n,
360
+ ManageEvents: 1n << 33n,
361
+ ManageThreads: 1n << 34n,
362
+ CreatePublicThreads: 1n << 35n,
363
+ CreatePrivateThreads: 1n << 36n,
364
+ UseExternalStickers: 1n << 37n,
365
+ SendMessagesInThreads: 1n << 38n,
366
+ UseEmbeddedActivities: 1n << 39n,
367
+ ModerateMembers: 1n << 40n,
368
+ ViewCreatorMonetizationAnalytics: 1n << 41n,
369
+ UseSoundboard: 1n << 42n,
370
+ CreateGuildExpressions: 1n << 43n,
371
+ CreateEvents: 1n << 44n,
372
+ UseExternalSounds: 1n << 45n,
373
+ SendVoiceMessages: 1n << 46n,
374
+ SendPolls: 1n << 49n,
375
+ UseExternalApps: 1n << 50n
376
+ };
377
+
378
+ class PermissionSet {
379
+ bitfield;
380
+ constructor(value = 0n) {
381
+ try {
382
+ if (Array.isArray(value)) {
383
+ let bit = 0n;
384
+ for (const item of value)
385
+ bit |= this.#resolve(item);
386
+ this.bitfield = bit;
387
+ } else if (value instanceof PermissionSet) {
388
+ this.bitfield = value.bitfield;
389
+ } else {
390
+ const bitfield = this.#resolve(value);
391
+ if (bitfield < 0n)
392
+ throw new RangeError("Permission bitfield cannot be negative.");
393
+ this.bitfield = bitfield;
394
+ }
395
+ } catch (error) {
396
+ if (error instanceof RangeError)
397
+ throw error;
398
+ throw new TypeError("Permission bitfield must be a valid non-negative integer.", { cause: error });
399
+ }
400
+ }
401
+ has(...permissions) {
402
+ return permissions.every((permission) => (this.bitfield & this.#resolve(permission)) === this.#resolve(permission));
403
+ }
404
+ any(...permissions) {
405
+ return permissions.some((permission) => (this.bitfield & this.#resolve(permission)) !== 0n);
406
+ }
407
+ add(...permissions) {
408
+ let bitfield = this.bitfield;
409
+ for (const permission of permissions)
410
+ bitfield |= this.#resolve(permission);
411
+ return new PermissionSet(bitfield);
412
+ }
413
+ remove(...permissions) {
414
+ let bitfield = this.bitfield;
415
+ for (const permission of permissions)
416
+ bitfield &= ~this.#resolve(permission);
417
+ return new PermissionSet(bitfield);
418
+ }
419
+ equals(other) {
420
+ return this.bitfield === (other instanceof PermissionSet ? other.bitfield : new PermissionSet(other).bitfield);
421
+ }
422
+ toString() {
423
+ return this.bitfield.toString();
424
+ }
425
+ toArray() {
426
+ return Object.keys(Permissions).filter((permission) => this.has(permission));
427
+ }
428
+ #resolve(permission) {
429
+ if (permission instanceof PermissionSet)
430
+ return permission.bitfield;
431
+ if (typeof permission === "bigint")
432
+ return permission;
433
+ if (typeof permission === "number")
434
+ return BigInt(permission);
435
+ if (Array.isArray(permission)) {
436
+ let bit = 0n;
437
+ for (const p of permission)
438
+ bit |= this.#resolve(p);
439
+ return bit;
440
+ }
441
+ if (typeof permission === "string") {
442
+ if (permission in Permissions)
443
+ return Permissions[permission];
444
+ const matchedKey = Object.keys(Permissions).find((k) => k.toLowerCase() === permission.toLowerCase());
445
+ if (matchedKey)
446
+ return Permissions[matchedKey];
447
+ return BigInt(permission);
448
+ }
449
+ return 0n;
450
+ }
451
+ }
452
+
453
+ class PermissionsBitField extends PermissionSet {
454
+ constructor(value = 0n) {
455
+ super(value);
456
+ }
457
+ }
458
+
459
+ // packages/structures/src/resources.ts
460
+ class GuildMember {
461
+ user;
462
+ guildId;
463
+ nickname;
464
+ roleIds;
465
+ pending;
466
+ joinedAt;
467
+ permissions;
468
+ constructor(data) {
469
+ this.user = new User(data.user);
470
+ if (!/^\d{1,20}$/.test(data.guild_id))
471
+ throw new TypeError("Member guild_id must be a valid snowflake.");
472
+ this.guildId = data.guild_id;
473
+ this.nickname = data.nick ?? null;
474
+ this.roleIds = [...data.roles ?? []];
475
+ this.pending = data.pending ?? false;
476
+ this.joinedAt = data.joined_at ? new Date(data.joined_at) : undefined;
477
+ if (this.joinedAt?.toString() === "Invalid Date")
478
+ throw new RangeError("Member joined_at must be a valid date.");
479
+ this.permissions = new PermissionsBitField(data.permissions ?? 0n);
480
+ }
481
+ get displayName() {
482
+ return this.nickname ?? this.user.displayName;
483
+ }
484
+ }
485
+
486
+ class Role extends BaseStructure {
487
+ name;
488
+ color;
489
+ hoist;
490
+ permissions;
491
+ managed;
492
+ mentionable;
493
+ constructor(data) {
494
+ super(data.id);
495
+ if (!data.name)
496
+ throw new TypeError("Role name cannot be empty.");
497
+ this.name = data.name;
498
+ this.color = data.color ?? 0;
499
+ this.hoist = data.hoist ?? false;
500
+ this.permissions = new PermissionsBitField(data.permissions ?? 0n);
501
+ this.managed = data.managed ?? false;
502
+ this.mentionable = data.mentionable ?? false;
503
+ }
504
+ toString() {
505
+ return `<@&${this.id}>`;
506
+ }
507
+ }
508
+
509
+ // packages/structures/src/index.ts
510
+ class Message extends BaseStructure {
511
+ content;
512
+ author;
513
+ channelId;
514
+ channel;
515
+ guildId;
516
+ flags;
517
+ createdAt;
518
+ attachments;
519
+ embeds;
520
+ mentions;
521
+ mentionRoles;
522
+ pinned;
523
+ mentionEveryone;
524
+ type;
525
+ reference;
526
+ referencedMessage;
527
+ #context;
528
+ constructor(data, context) {
529
+ super(data.id);
530
+ if (!/^\d{1,20}$/.test(data.channel_id))
531
+ throw new TypeError("Message channel_id must be a valid snowflake.");
532
+ this.content = data.content ?? "";
533
+ this.author = new User(data.author);
534
+ this.channelId = data.channel_id;
535
+ this.guildId = data.guild_id;
536
+ this.flags = data.flags ?? 0;
537
+ this.createdAt = new Date(data.timestamp ?? Number((BigInt(this.id) >> 22n) + 1420070400000n));
538
+ this.attachments = data.attachments ?? [];
539
+ this.embeds = data.embeds ?? [];
540
+ this.mentions = (data.mentions ?? []).map((user) => new User(user));
541
+ this.mentionRoles = data.mention_roles ?? [];
542
+ this.pinned = data.pinned ?? false;
543
+ this.mentionEveryone = data.mention_everyone ?? false;
544
+ this.type = data.type ?? 0;
545
+ this.reference = data.message_reference;
546
+ this.referencedMessage = data.referenced_message ? new Message(data.referenced_message, context) : data.referenced_message === null ? null : undefined;
547
+ this.#context = context;
548
+ this.channel = new Channel({ id: data.channel_id, type: 0, guild_id: data.guild_id }, context);
549
+ }
550
+ get embedsSuppressed() {
551
+ return (this.flags & 4) !== 0;
552
+ }
553
+ edit(options) {
554
+ if (!this.#context)
555
+ throw new Error("This message is not attached to a client.");
556
+ return this.#context.editMessage(this.channelId, this.id, options);
557
+ }
558
+ delete() {
559
+ if (!this.#context)
560
+ throw new Error("This message is not attached to a client.");
561
+ return this.#context.deleteMessage(this.channelId, this.id);
562
+ }
563
+ crosspost() {
564
+ if (!this.#context)
565
+ throw new Error("This message is not attached to a client.");
566
+ return this.#context.crosspostMessage(this.channelId, this.id);
567
+ }
568
+ reply(options) {
569
+ if (!this.#context)
570
+ throw new Error("This message is not attached to a client.");
571
+ const payload = typeof options === "string" ? { content: options } : { ...options };
572
+ payload.message_reference = {
573
+ message_id: this.id,
574
+ channel_id: this.channelId,
575
+ guild_id: this.guildId
576
+ };
577
+ return this.#context.sendMessage(this.channelId, payload);
578
+ }
579
+ }
580
+
581
+ // packages/managers/src/message.ts
582
+ class MessageManager {
583
+ cache = new Collection;
584
+ #rest;
585
+ #context;
586
+ #channelId;
587
+ constructor(rest, context, channelId) {
588
+ if (!channelId)
589
+ throw new TypeError("Channel ID is required.");
590
+ this.#rest = rest;
591
+ this.#context = context;
592
+ this.#channelId = channelId;
593
+ }
594
+ async resolve(messageId) {
595
+ return this.cache.get(messageId) ?? this.fetch(messageId);
596
+ }
597
+ async send(options) {
598
+ const data = await this.#rest.post(Routes.channelMessages(this.#channelId), options);
599
+ return this.upsert(data);
600
+ }
601
+ async fetch(messageId) {
602
+ const data = await this.#rest.get(Routes.message(this.#channelId, messageId));
603
+ const message = Array.isArray(data) ? data[0] : data;
604
+ if (!message)
605
+ throw new Error("Discord returned no message payload.");
606
+ return this.upsert(message);
607
+ }
608
+ fetchMany(messageIds) {
609
+ return Promise.all(Array.from(messageIds, (messageId) => this.fetch(messageId)));
610
+ }
611
+ upsert(data) {
612
+ const existing = this.cache.get(data.id);
613
+ const message = new Message(data, this.#context);
614
+ if (existing) {
615
+ Object.assign(existing, message);
616
+ return existing;
617
+ }
618
+ this.cache.set(message.id, message);
619
+ return message;
620
+ }
621
+ delete(messageId) {
622
+ return this.cache.delete(messageId);
623
+ }
624
+ }
625
+
626
+ // packages/managers/src/thread.ts
627
+ class ThreadManager {
628
+ #rest;
629
+ #context;
630
+ #channelId;
631
+ constructor(rest, context, channelId) {
632
+ if (!channelId)
633
+ throw new TypeError("Channel ID is required.");
634
+ this.#rest = rest;
635
+ this.#context = context;
636
+ this.#channelId = channelId;
637
+ }
638
+ async createFromMessage(messageId, options) {
639
+ const data = await this.#rest.post(Routes.messageThread(this.#channelId, messageId), {
640
+ name: options.name,
641
+ auto_archive_duration: options.autoArchiveDuration,
642
+ rate_limit_per_user: options.rateLimitPerUser
643
+ });
644
+ return new Channel(data, this.#context);
645
+ }
646
+ }
647
+ // packages/managers/src/role.ts
648
+ class RoleManager extends ResourceManager {
649
+ #rest;
650
+ guildId;
651
+ constructor(guildId, rest) {
652
+ super((id) => rest.get(Routes.guildRole(guildId, id)).then((data) => new Role(data)), (role) => role.id);
653
+ this.guildId = guildId;
654
+ this.#rest = rest;
655
+ }
656
+ async fetchAll() {
657
+ const data = await this.#rest.get(Routes.guildRoles(this.guildId));
658
+ return data.map((item) => {
659
+ const role = new Role(item);
660
+ this.set(role.id, role);
661
+ return role;
662
+ });
663
+ }
664
+ async create(options) {
665
+ const { reason, ...payload } = options;
666
+ const data = await this.#rest.post(Routes.guildRoles(this.guildId), {
667
+ ...payload,
668
+ permissions: payload.permissions !== undefined ? String(payload.permissions) : undefined
669
+ });
670
+ const role = new Role(data);
671
+ this.set(role.id, role);
672
+ return role;
673
+ }
674
+ async edit(roleId, options) {
675
+ const { reason, ...payload } = options;
676
+ const data = await this.#rest.patch(Routes.guildRole(this.guildId, roleId), {
677
+ ...payload,
678
+ permissions: payload.permissions !== undefined ? String(payload.permissions) : undefined
679
+ });
680
+ const role = new Role(data);
681
+ this.set(role.id, role);
682
+ return role;
683
+ }
684
+ async deleteRole(roleId) {
685
+ await this.#rest.delete(Routes.guildRole(this.guildId, roleId));
686
+ this.delete(roleId);
687
+ }
688
+ }
689
+ // packages/managers/src/member.ts
690
+ class GuildMemberManager extends ResourceManager {
691
+ #rest;
692
+ guildId;
693
+ constructor(guildId, rest) {
694
+ super((id) => rest.get(Routes.guildMember(guildId, id)).then((data) => new GuildMember({ ...data, guild_id: guildId })), (member) => member.user.id);
695
+ this.guildId = guildId;
696
+ this.#rest = rest;
697
+ }
698
+ async kick(userId) {
699
+ await this.#rest.delete(Routes.guildMember(this.guildId, userId));
700
+ this.delete(userId);
701
+ }
702
+ async ban(userId, options = {}) {
703
+ await this.#rest.put(Routes.guildBan(this.guildId, userId), {
704
+ delete_message_seconds: options.deleteMessageSeconds
705
+ });
706
+ this.delete(userId);
707
+ }
708
+ async unban(userId) {
709
+ await this.#rest.delete(Routes.guildBan(this.guildId, userId));
710
+ }
711
+ async edit(userId, options) {
712
+ const data = await this.#rest.patch(Routes.guildMember(this.guildId, userId), options);
713
+ const member = new GuildMember({ ...data, guild_id: this.guildId });
714
+ this.set(member.user.id, member);
715
+ return member;
716
+ }
717
+ async addRole(userId, roleId) {
718
+ await this.#rest.put(Routes.guildMemberRole(this.guildId, userId, roleId));
719
+ }
720
+ async removeRole(userId, roleId) {
721
+ await this.#rest.delete(Routes.guildMemberRole(this.guildId, userId, roleId));
722
+ }
723
+ async timeout(userId, milliseconds) {
724
+ const timeoutDate = milliseconds === null ? null : new Date(Date.now() + milliseconds).toISOString();
725
+ return this.edit(userId, { communication_disabled_until: timeoutDate });
726
+ }
727
+ }
728
+ // packages/managers/src/application.ts
729
+ class ApplicationCommandManager {
730
+ #rest;
731
+ #applicationId;
732
+ constructor(rest, applicationId) {
733
+ this.#rest = rest;
734
+ this.#applicationId = applicationId;
735
+ }
736
+ fetch() {
737
+ return this.#rest.get(Routes.applicationCommands(this.#applicationId));
738
+ }
739
+ create(data) {
740
+ return this.#rest.post(Routes.applicationCommands(this.#applicationId), data);
741
+ }
742
+ set(commands) {
743
+ return this.#rest.put(Routes.applicationCommands(this.#applicationId), commands);
744
+ }
745
+ edit(commandId, data) {
746
+ return this.#rest.patch(Routes.applicationCommand(this.#applicationId, commandId), data);
747
+ }
748
+ async delete(commandId) {
749
+ await this.#rest.delete(Routes.applicationCommand(this.#applicationId, commandId));
750
+ }
751
+ fetchGuild(guildId) {
752
+ return this.#rest.get(Routes.guildApplicationCommands(this.#applicationId, guildId));
753
+ }
754
+ createGuild(guildId, data) {
755
+ return this.#rest.post(Routes.guildApplicationCommands(this.#applicationId, guildId), data);
756
+ }
757
+ setGuild(guildId, commands) {
758
+ return this.#rest.put(Routes.guildApplicationCommands(this.#applicationId, guildId), commands);
759
+ }
760
+ editGuild(guildId, commandId, data) {
761
+ return this.#rest.patch(Routes.guildApplicationCommand(this.#applicationId, guildId, commandId), data);
762
+ }
763
+ async deleteGuild(guildId, commandId) {
764
+ await this.#rest.delete(Routes.guildApplicationCommand(this.#applicationId, guildId, commandId));
765
+ }
766
+ }
767
+
768
+ // packages/managers/src/index.ts
769
+ class UserManager extends ResourceManager {
770
+ constructor(rest) {
771
+ super(async (id) => new User(await rest.get(Routes.userById(id))), (user) => user.id);
772
+ }
773
+ }
774
+
775
+ class GuildManager extends ResourceManager {
776
+ constructor(rest) {
777
+ super(async (id) => new Guild(await rest.get(Routes.guild(id))), (guild) => guild.id);
778
+ }
779
+ }
780
+ var MessageCreateOptions = undefined;
781
+ var MessageEditOptions = undefined;
782
+ var MessageFetchOptions = undefined;
783
+ var MessageThreadOptions = undefined;
784
+ var ReactionFetchOptions = undefined;
785
+
786
+ class ChannelManager extends Manager {
787
+ #rest;
788
+ #context;
789
+ #messageManagers = new Map;
790
+ constructor(rest) {
791
+ super();
792
+ this.#rest = rest;
793
+ this.#context = {
794
+ sendMessage: (channelId, options) => this.send(channelId, options),
795
+ editMessage: (channelId, messageId, options) => this.editMessage(channelId, messageId, options),
796
+ deleteMessage: (channelId, messageId) => this.deleteMessage(channelId, messageId),
797
+ crosspostMessage: (channelId, messageId) => this.crosspostMessage(channelId, messageId)
798
+ };
799
+ }
800
+ messages(channelId) {
801
+ let manager = this.#messageManagers.get(channelId);
802
+ if (!manager) {
803
+ manager = new MessageManager(this.#rest, this.#context, channelId);
804
+ this.#messageManagers.set(channelId, manager);
805
+ }
806
+ return manager;
807
+ }
808
+ threads(channelId) {
809
+ return new ThreadManager(this.#rest, this.#context, channelId);
810
+ }
811
+ async fetch(channelId) {
812
+ const data = await this.#rest.get(Routes.channel(channelId));
813
+ return this.upsert(data);
814
+ }
815
+ async resolve(channelId) {
816
+ return this.get(channelId) ?? this.fetch(channelId);
817
+ }
818
+ upsert(data) {
819
+ const existing = this.get(data.id);
820
+ const channel = new Channel(data, this.#context);
821
+ if (existing) {
822
+ Object.assign(existing, channel);
823
+ return existing;
824
+ }
825
+ this.set(channel.id, channel);
826
+ return channel;
827
+ }
828
+ update(channel) {
829
+ return this.set(channel.id, channel);
830
+ }
831
+ send(channelId, options) {
832
+ return this.messages(channelId).send(options);
833
+ }
834
+ sendMessage(channelId, options) {
835
+ return this.send(channelId, options);
836
+ }
837
+ async fetchMessage(channelId, messageId, options = {}) {
838
+ return this.messages(channelId).fetch(messageId);
839
+ }
840
+ fetchMessages(channelId, query) {
841
+ if (isMessageQuery(query)) {
842
+ const params = new URLSearchParams;
843
+ if (query.before)
844
+ params.set("before", query.before);
845
+ if (query.after)
846
+ params.set("after", query.after);
847
+ if (query.around)
848
+ params.set("around", query.around);
849
+ if (query.limit !== undefined)
850
+ params.set("limit", String(query.limit));
851
+ const suffix = params.toString();
852
+ return this.#rest.get(`${Routes.channelMessages(channelId)}${suffix ? `?${suffix}` : ""}`).then((data) => data.map((item) => this.messages(channelId).upsert(item)));
853
+ }
854
+ return this.messages(channelId).fetchMany(query);
855
+ }
856
+ upsertMessage(data) {
857
+ return this.messages(data.channel_id).upsert(data);
858
+ }
859
+ async editMessage(channelId, messageId, options) {
860
+ const data = await this.#rest.patch(Routes.message(channelId, messageId), options);
861
+ return this.messages(channelId).upsert(data);
862
+ }
863
+ async deleteMessage(channelId, messageId) {
864
+ await this.#rest.delete(Routes.message(channelId, messageId));
865
+ this.messages(channelId).delete(messageId);
866
+ }
867
+ deleteCachedMessage(channelId, messageId) {
868
+ return this.messages(channelId).delete(messageId);
869
+ }
870
+ async crosspostMessage(channelId, messageId) {
871
+ const data = await this.#rest.post(Routes.crosspostMessage(channelId, messageId));
872
+ return this.messages(channelId).upsert(data);
873
+ }
874
+ async bulkDeleteMessages(channelId, messageIds) {
875
+ const ids = [...messageIds];
876
+ await this.#rest.post(Routes.channelBulkDelete(channelId), {
877
+ messages: ids
878
+ });
879
+ for (const id of ids)
880
+ this.messages(channelId).delete(id);
881
+ }
882
+ async addReaction(channelId, messageId, emoji) {
883
+ await this.#rest.put(Routes.messageReactions(channelId, messageId, emoji));
884
+ }
885
+ async fetchReactions(channelId, messageId, emoji, options = {}) {
886
+ const params = new URLSearchParams;
887
+ if (options.limit !== undefined)
888
+ params.set("limit", String(options.limit));
889
+ if (options.after)
890
+ params.set("after", options.after);
891
+ const suffix = params.toString();
892
+ const data = await this.#rest.get(`${Routes.messageReactions(channelId, messageId, emoji)}${suffix ? `?${suffix}` : ""}`);
893
+ return data.map((user) => new User(user));
894
+ }
895
+ async removeOwnReaction(channelId, messageId, emoji) {
896
+ await this.#rest.delete(Routes.messageReactions(channelId, messageId, emoji) + "/@me");
897
+ }
898
+ async removeReaction(channelId, messageId, emoji, userId) {
899
+ await this.#rest.delete(`${Routes.messageReactions(channelId, messageId, emoji)}/${userId}`);
900
+ }
901
+ async removeAllReactions(channelId, messageId) {
902
+ await this.#rest.delete(Routes.messageReactionsAll(channelId, messageId));
903
+ }
904
+ async fetchPinnedMessages(channelId) {
905
+ const data = await this.#rest.get(Routes.channelPins(channelId));
906
+ return data.map((item) => this.messages(channelId).upsert(item));
907
+ }
908
+ async pinMessage(channelId, messageId) {
909
+ await this.#rest.put(Routes.channelPin(channelId, messageId));
910
+ }
911
+ async unpinMessage(channelId, messageId) {
912
+ await this.#rest.delete(Routes.channelPin(channelId, messageId));
913
+ }
914
+ createThreadFromMessage(channelId, messageId, options) {
915
+ return this.threads(channelId).createFromMessage(messageId, options);
916
+ }
917
+ delete(channelId) {
918
+ this.#messageManagers.delete(channelId);
919
+ return super.delete(channelId);
920
+ }
921
+ clear() {
922
+ this.#messageManagers.clear();
923
+ super.clear();
924
+ }
925
+ }
926
+ function isMessageQuery(value) {
927
+ return typeof value === "object" && value !== null && !(Symbol.iterator in value);
928
+ }
929
+ export {
930
+ ApplicationCommandManager,
931
+ ChannelManager,
932
+ GuildManager,
933
+ GuildMemberManager,
934
+ Manager,
935
+ MessageCreateOptions,
936
+ MessageEditOptions,
937
+ MessageFetchOptions,
938
+ MessageManager,
939
+ MessageThreadOptions,
940
+ ReactionFetchOptions,
941
+ ResourceManager,
942
+ RoleManager,
943
+ ThreadManager,
944
+ UserManager
945
+ };
946
+
947
+ //# debugId=B1F523C9C7EE890964756E2164756E21