lunibee 0.1.5 → 0.1.7

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 (60) hide show
  1. package/README.md +13 -24
  2. package/dist/builders/commands.d.ts +37 -0
  3. package/dist/builders/components.d.ts +127 -12
  4. package/dist/builders/embed.d.ts +3 -1
  5. package/dist/builders/index.d.ts +2 -2
  6. package/dist/builders/index.js +319 -16
  7. package/dist/builders/index.js.map +8 -7
  8. package/dist/collection/index.d.ts +36 -0
  9. package/dist/collection/index.js +110 -6
  10. package/dist/collection/index.js.map +4 -4
  11. package/dist/core/events.d.ts +69 -3
  12. package/dist/core/index.d.ts +158 -90
  13. package/dist/core/index.js +1543 -1169
  14. package/dist/core/index.js.map +24 -23
  15. package/dist/core/permissions.d.ts +112 -53
  16. package/dist/formatters/index.d.ts +43 -3
  17. package/dist/formatters/index.js +64 -1
  18. package/dist/formatters/index.js.map +3 -3
  19. package/dist/handlers/index.js.map +2 -2
  20. package/dist/index.d.ts +5 -4
  21. package/dist/index.js +3882 -1588
  22. package/dist/index.js.map +43 -35
  23. package/dist/managers/emoji.d.ts +38 -0
  24. package/dist/managers/guild.d.ts +141 -0
  25. package/dist/managers/index.d.ts +86 -75
  26. package/dist/managers/index.js +1084 -67
  27. package/dist/managers/index.js.map +21 -16
  28. package/dist/managers/message.d.ts +7 -12
  29. package/dist/managers/user.d.ts +20 -0
  30. package/dist/rest/index.d.ts +173 -1
  31. package/dist/rest/index.js +343 -47
  32. package/dist/rest/index.js.map +8 -6
  33. package/dist/rest/redis.d.ts +37 -0
  34. package/dist/rest/routes.d.ts +26 -1
  35. package/dist/rest/store.d.ts +38 -0
  36. package/dist/rest/webhook.d.ts +2 -2
  37. package/dist/sharding/cluster.d.ts +61 -0
  38. package/dist/sharding/index.d.ts +8 -0
  39. package/dist/sharding/index.js +289 -18
  40. package/dist/sharding/index.js.map +8 -7
  41. package/dist/structures/audit-log.d.ts +26 -0
  42. package/dist/structures/base.d.ts +131 -48
  43. package/dist/structures/embed.d.ts +65 -0
  44. package/dist/structures/index.d.ts +74 -26
  45. package/dist/structures/index.js +1528 -59
  46. package/dist/structures/index.js.map +14 -8
  47. package/dist/structures/interactions.d.ts +72 -17
  48. package/dist/structures/resources.d.ts +199 -7
  49. package/dist/types/index.d.ts +605 -84
  50. package/dist/types/index.js +71 -1
  51. package/dist/types/index.js.map +3 -3
  52. package/dist/utils/index.js.map +2 -2
  53. package/dist/voice/index.d.ts +88 -0
  54. package/dist/voice/index.js +204 -5
  55. package/dist/voice/index.js.map +3 -3
  56. package/dist/ws/index.d.ts +40 -1
  57. package/dist/ws/index.js +105 -18
  58. package/dist/ws/index.js.map +4 -4
  59. package/package.json +16 -16
  60. package/dist/structures/permissions.d.ts +0 -73
@@ -123,6 +123,97 @@ class Collection extends Map {
123
123
  entry = [item[0], item[1]];
124
124
  return entry;
125
125
  }
126
+ union(other) {
127
+ const result = this.clone();
128
+ for (const [key, value] of other)
129
+ result.set(key, value);
130
+ return result;
131
+ }
132
+ intersection(other) {
133
+ const result = new Collection;
134
+ for (const [key, value] of this) {
135
+ if (other.has(key))
136
+ result.set(key, value);
137
+ }
138
+ return result;
139
+ }
140
+ difference(other) {
141
+ const result = new Collection;
142
+ for (const [key, value] of this) {
143
+ if (!other.has(key))
144
+ result.set(key, value);
145
+ }
146
+ return result;
147
+ }
148
+ partition(predicate) {
149
+ const pass = new Collection;
150
+ const fail = new Collection;
151
+ for (const [key, value] of this) {
152
+ if (predicate(value, key, this))
153
+ pass.set(key, value);
154
+ else
155
+ fail.set(key, value);
156
+ }
157
+ return [pass, fail];
158
+ }
159
+ tap(fn) {
160
+ fn(this);
161
+ return this;
162
+ }
163
+ flatMap(transform) {
164
+ const result = [];
165
+ for (const [key, value] of this) {
166
+ for (const item of transform(value, key, this))
167
+ result.push(item);
168
+ }
169
+ return result;
170
+ }
171
+ reduce(fn, initialValue) {
172
+ let acc = initialValue;
173
+ for (const [key, value] of this)
174
+ acc = fn(acc, value, key, this);
175
+ return acc;
176
+ }
177
+ sorted(comparator) {
178
+ const decorated = [...this.entries()].map((entry, index) => ({
179
+ entry,
180
+ index
181
+ }));
182
+ if (comparator)
183
+ decorated.sort((x, y) => {
184
+ const comparison = comparator(x.entry[1], y.entry[1], x.entry[0], y.entry[0]);
185
+ return comparison !== 0 ? comparison : x.index - y.index;
186
+ });
187
+ const result = new Collection;
188
+ for (const { entry } of decorated)
189
+ result.set(entry[0], entry[1]);
190
+ return result;
191
+ }
192
+ random() {
193
+ const arr = [...this.values()];
194
+ if (!arr.length)
195
+ return;
196
+ return arr[Math.floor(Math.random() * arr.length)];
197
+ }
198
+ randomKey() {
199
+ const arr = [...this.keys()];
200
+ if (!arr.length)
201
+ return;
202
+ return arr[Math.floor(Math.random() * arr.length)];
203
+ }
204
+ at(index) {
205
+ const arr = [...this.values()];
206
+ const i = index < 0 ? arr.length + index : index;
207
+ return arr[i];
208
+ }
209
+ keyAt(index) {
210
+ const arr = [...this.keys()];
211
+ const i = index < 0 ? arr.length + index : index;
212
+ return arr[i];
213
+ }
214
+ toJSON() {
215
+ return [...this.entries()];
216
+ }
126
217
  }
127
218
 
128
219
  // packages/managers/src/base.ts
@@ -191,11 +282,27 @@ class ResourceManager extends Manager {
191
282
  return this.upsert(resource);
192
283
  }
193
284
  }
285
+ // packages/rest/package.json
286
+ var package_default = {
287
+ name: "@lunibee/rest",
288
+ version: "0.1.7",
289
+ type: "module",
290
+ module: "./src/index.ts",
291
+ types: "./src/index.ts",
292
+ exports: {
293
+ ".": "./src/index.ts"
294
+ }
295
+ };
296
+
194
297
  // packages/rest/src/routes.ts
195
298
  var Routes = {
196
299
  user: () => "/users/@me",
197
300
  userById: (userId) => `/users/${snowflake(userId, "User ID")}`,
198
301
  guild: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}`,
302
+ guildPreview: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/preview`,
303
+ guildActiveThreads: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/threads/active`,
304
+ guildWebhooks: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/webhooks`,
305
+ guildInvites: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/invites`,
199
306
  guildChannels: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/channels`,
200
307
  guildMember: (guildId, userId) => `/guilds/${snowflake(guildId, "Guild ID")}/members/${snowflake(userId, "User ID")}`,
201
308
  guildRoles: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/roles`,
@@ -223,7 +330,6 @@ var Routes = {
223
330
  guildApplicationCommand: (applicationId, guildId, commandId) => `/applications/${snowflake(applicationId, "Application ID")}/guilds/${snowflake(guildId, "Guild ID")}/commands/${snowflake(commandId, "Command ID")}`,
224
331
  interactionCallback: (interactionId, token) => `/interactions/${snowflake(interactionId, "Interaction ID")}/${encodeURIComponent(token)}/callback`,
225
332
  interactionOriginalResponse: (applicationId, token) => `/webhooks/${snowflake(applicationId, "Application ID")}/${encodeURIComponent(token)}/messages/@original`,
226
- guildActiveThreads: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/threads/active`,
227
333
  channelPublicArchivedThreads: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/threads/archived/public`,
228
334
  channelPrivateArchivedThreads: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/threads/archived/private`,
229
335
  threadMembers: (threadId) => `/channels/${snowflake(threadId, "Thread ID")}/thread-members`,
@@ -233,13 +339,38 @@ var Routes = {
233
339
  guildAutoModerationRule: (guildId, ruleId) => `/guilds/${snowflake(guildId, "Guild ID")}/auto-moderation/rules/${snowflake(ruleId, "Rule ID")}`,
234
340
  voiceRegions: () => "/voice/regions",
235
341
  gateway: () => "/gateway",
236
- gatewayBot: () => "/gateway/bot"
342
+ gatewayBot: () => "/gateway/bot",
343
+ guildAuditLog: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/audit-logs`,
344
+ guildMembers: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/members`,
345
+ guildWelcomeScreen: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/welcome-screen`,
346
+ guildOnboarding: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/onboarding`,
347
+ guildPrune: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/prune`,
348
+ stageInstances: () => "/stage-instances",
349
+ stageInstanceByChannel: (channelId) => `/stage-instances/${snowflake(channelId, "Channel ID")}`,
350
+ invite: (code) => `/invites/${encodeURIComponent(code)}`,
351
+ guildVanity: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/vanity-url`,
352
+ guildEmoji: (guildId, emojiId) => emojiId ? `/guilds/${snowflake(guildId, "Guild ID")}/emojis/${snowflake(emojiId, "Emoji ID")}` : `/guilds/${snowflake(guildId, "Guild ID")}/emojis`,
353
+ applicationEmoji: (applicationId, emojiId) => emojiId ? `/applications/${snowflake(applicationId, "Application ID")}/emojis/${snowflake(emojiId, "Emoji ID")}` : `/applications/${snowflake(applicationId, "Application ID")}/emojis`
237
354
  };
238
355
  function snowflake(value, field) {
239
356
  if (!/^\d{1,20}$/.test(value))
240
357
  throw new TypeError(`${field} must be a valid Discord snowflake.`);
241
358
  return value;
242
359
  }
360
+ // packages/rest/src/index.ts
361
+ var LIBRARY_VERSION = package_default.version;
362
+ var LIBRARY_URL = "https://github.com/Ekretos/lunibee";
363
+ var USER_AGENT = `DiscordBot (${LIBRARY_URL}, ${package_default.version})`;
364
+ var REQUEST_DATA_KEYS = new Set([
365
+ "body",
366
+ "files",
367
+ "query",
368
+ "headers",
369
+ "reason",
370
+ "auth",
371
+ "signal"
372
+ ]);
373
+
243
374
  // packages/structures/src/base.ts
244
375
  class BaseStructure {
245
376
  id;
@@ -251,6 +382,16 @@ class BaseStructure {
251
382
  toString() {
252
383
  return this.id;
253
384
  }
385
+ get createdAt() {
386
+ return new Date(Number((BigInt(this.id) >> 22n) + 1420070400000n));
387
+ }
388
+ }
389
+ var CDN_BASE = "https://cdn.discordapp.com";
390
+ function cdnURL(path, hash, options = {}) {
391
+ const isAnimated = hash.startsWith("a_") && !options.forceStatic;
392
+ const ext = options.extension ?? (isAnimated ? "gif" : "png");
393
+ const size = options.size ? `?size=${options.size}` : "";
394
+ return `${CDN_BASE}${path}/${hash}.${ext}${size}`;
254
395
  }
255
396
 
256
397
  class User extends BaseStructure {
@@ -260,6 +401,7 @@ class User extends BaseStructure {
260
401
  bot;
261
402
  system;
262
403
  flags;
404
+ discriminator;
263
405
  constructor(data) {
264
406
  super(data.id);
265
407
  if (!data.username)
@@ -270,6 +412,7 @@ class User extends BaseStructure {
270
412
  this.bot = data.bot ?? false;
271
413
  this.system = data.system ?? false;
272
414
  this.flags = data.public_flags ?? 0;
415
+ this.discriminator = data.discriminator && data.discriminator !== "0" ? data.discriminator : null;
273
416
  }
274
417
  get displayName() {
275
418
  return this.globalName ?? this.username;
@@ -277,21 +420,29 @@ class User extends BaseStructure {
277
420
  avatarURL(options = {}) {
278
421
  if (!this.avatar)
279
422
  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}` : ""}`;
423
+ return cdnURL(`/avatars/${this.id}`, this.avatar, options);
282
424
  }
283
425
  defaultAvatarURL() {
284
- return `https://cdn.discordapp.com/embed/avatars/${Number(BigInt(this.id) % 5n)}.png`;
426
+ const index = this.discriminator ? Number(this.discriminator) % 5 : Number((BigInt(this.id) >> 22n) % 6n);
427
+ return `${CDN_BASE}/embed/avatars/${index}.png`;
285
428
  }
286
429
  displayAvatarURL(options = {}) {
287
430
  return this.avatarURL(options) ?? this.defaultAvatarURL();
288
431
  }
432
+ toString() {
433
+ return `<@${this.id}>`;
434
+ }
289
435
  }
290
436
 
291
437
  class Channel extends BaseStructure {
292
438
  type;
293
439
  name;
294
440
  guildId;
441
+ topic;
442
+ parentId;
443
+ nsfw;
444
+ rateLimitPerUser;
445
+ position;
295
446
  #context;
296
447
  constructor(data, context) {
297
448
  super(data.id);
@@ -300,6 +451,11 @@ class Channel extends BaseStructure {
300
451
  this.type = data.type;
301
452
  this.name = data.name;
302
453
  this.guildId = data.guild_id;
454
+ this.topic = data.topic;
455
+ this.parentId = data.parent_id;
456
+ this.nsfw = data.nsfw;
457
+ this.rateLimitPerUser = data.rate_limit_per_user;
458
+ this.position = data.position;
303
459
  this.#context = context;
304
460
  }
305
461
  sendMessage(options) {
@@ -307,22 +463,196 @@ class Channel extends BaseStructure {
307
463
  throw new Error("This channel is not attached to a client.");
308
464
  return this.#context.sendMessage(this.id, options);
309
465
  }
466
+ send(options) {
467
+ return this.sendMessage(options);
468
+ }
469
+ edit(options) {
470
+ if (!this.#context?.editChannel)
471
+ throw new Error("This channel is not attached to a client.");
472
+ return this.#context.editChannel(this.id, options);
473
+ }
474
+ editName(name) {
475
+ if (!name.trim())
476
+ throw new TypeError("Channel name cannot be empty.");
477
+ return this.edit({ name });
478
+ }
479
+ editTopic(topic) {
480
+ return this.edit({ topic });
481
+ }
482
+ editParent(parentId) {
483
+ return this.edit({ parent_id: parentId });
484
+ }
485
+ delete() {
486
+ if (!this.#context?.deleteChannel)
487
+ throw new Error("This channel is not attached to a client.");
488
+ return this.#context.deleteChannel(this.id);
489
+ }
490
+ update(options) {
491
+ return this.edit(options);
492
+ }
493
+ toString() {
494
+ return `<#${this.id}>`;
495
+ }
310
496
  }
311
497
 
312
498
  class Guild extends BaseStructure {
313
499
  name;
500
+ icon;
501
+ splash;
502
+ banner;
503
+ description;
314
504
  preferredLocale;
315
505
  ownerId;
506
+ features;
507
+ verificationLevel;
508
+ premiumTier;
509
+ premiumSubscriptionCount;
510
+ memberCount;
511
+ approximateMemberCount;
512
+ approximatePresenceCount;
513
+ vanityUrlCode;
514
+ nsfwLevel;
515
+ discoverySplash;
516
+ rulesChannelId;
517
+ systemChannelId;
518
+ systemChannelFlags;
519
+ maxMembers;
520
+ mfaLevel;
521
+ explicitContentFilter;
522
+ defaultMessageNotifications;
316
523
  constructor(data) {
317
524
  super(data.id);
318
525
  if (!data.name)
319
526
  throw new TypeError("A Discord guild requires a name.");
320
527
  this.name = data.name;
321
- this.preferredLocale = data.preferred_locale;
528
+ this.icon = data.icon ?? null;
529
+ this.splash = data.splash ?? null;
530
+ this.banner = data.banner ?? null;
531
+ this.description = data.description ?? null;
532
+ this.preferredLocale = data.preferred_locale ?? "en-US";
322
533
  this.ownerId = data.owner_id;
534
+ this.features = data.features ?? [];
535
+ this.verificationLevel = data.verification_level ?? 0;
536
+ this.premiumTier = data.premium_tier ?? 0;
537
+ this.premiumSubscriptionCount = data.premium_subscription_count ?? 0;
538
+ this.memberCount = data.member_count ?? data.approximate_member_count;
539
+ this.approximateMemberCount = data.approximate_member_count;
540
+ this.approximatePresenceCount = data.approximate_presence_count;
541
+ this.vanityUrlCode = data.vanity_url_code ?? null;
542
+ this.nsfwLevel = data.nsfw_level ?? 0;
543
+ this.discoverySplash = data.discovery_splash ?? null;
544
+ const d = data;
545
+ this.rulesChannelId = d.rules_channel_id ?? null;
546
+ this.systemChannelId = d.system_channel_id ?? null;
547
+ this.systemChannelFlags = d.system_channel_flags ?? 0;
548
+ this.maxMembers = d.max_members ?? 0;
549
+ this.mfaLevel = d.mfa_level ?? 0;
550
+ this.explicitContentFilter = d.explicit_content_filter ?? 0;
551
+ this.defaultMessageNotifications = d.default_message_notifications ?? 0;
552
+ }
553
+ iconURL(options = {}) {
554
+ if (!this.icon)
555
+ return null;
556
+ return cdnURL(`/icons/${this.id}`, this.icon, options);
557
+ }
558
+ splashURL(options = {}) {
559
+ if (!this.splash)
560
+ return null;
561
+ return cdnURL(`/splashes/${this.id}`, this.splash, options);
562
+ }
563
+ bannerURL(options = {}) {
564
+ if (!this.banner)
565
+ return null;
566
+ return cdnURL(`/banners/${this.id}`, this.banner, options);
567
+ }
568
+ discoverySplashURL(options = {}) {
569
+ if (!this.discoverySplash)
570
+ return null;
571
+ return cdnURL(`/discovery-splashes/${this.id}`, this.discoverySplash, options);
572
+ }
573
+ widgetImageURL(style = "shield") {
574
+ return `https://discord.com/api/guilds/${this.id}/widget.png?style=${style}`;
575
+ }
576
+ hasFeature(feature) {
577
+ return this.features.includes(feature);
578
+ }
579
+ get isCommunity() {
580
+ return this.hasFeature("COMMUNITY");
581
+ }
582
+ get isPartnered() {
583
+ return this.hasFeature("PARTNERED");
584
+ }
585
+ get isVerified() {
586
+ return this.hasFeature("VERIFIED");
587
+ }
588
+ get isBoosted() {
589
+ return this.premiumSubscriptionCount > 0;
590
+ }
591
+ get boostLevel() {
592
+ return this.premiumTier;
593
+ }
594
+ get hasVanityUrl() {
595
+ return this.vanityUrlCode !== null;
596
+ }
597
+ get vanityURL() {
598
+ return this.vanityUrlCode ? `https://discord.gg/${this.vanityUrlCode}` : null;
599
+ }
600
+ toString() {
601
+ return this.name;
323
602
  }
324
603
  }
325
- // packages/structures/src/permissions.ts
604
+ // packages/core/src/permissions.ts
605
+ var Permission = {
606
+ createInstantInvite: 1n << 0n,
607
+ kickMembers: 1n << 1n,
608
+ banMembers: 1n << 2n,
609
+ administrator: 1n << 3n,
610
+ manageChannels: 1n << 4n,
611
+ manageGuild: 1n << 5n,
612
+ addReactions: 1n << 6n,
613
+ viewAuditLog: 1n << 7n,
614
+ prioritySpeaker: 1n << 8n,
615
+ stream: 1n << 9n,
616
+ viewChannel: 1n << 10n,
617
+ sendMessages: 1n << 11n,
618
+ sendTTSMessages: 1n << 12n,
619
+ manageMessages: 1n << 13n,
620
+ embedLinks: 1n << 14n,
621
+ attachFiles: 1n << 15n,
622
+ readMessageHistory: 1n << 16n,
623
+ mentionEveryone: 1n << 17n,
624
+ useExternalEmojis: 1n << 18n,
625
+ viewGuildInsights: 1n << 19n,
626
+ connect: 1n << 20n,
627
+ speak: 1n << 21n,
628
+ muteMembers: 1n << 22n,
629
+ deafenMembers: 1n << 23n,
630
+ moveMembers: 1n << 24n,
631
+ useVAD: 1n << 25n,
632
+ changeNickname: 1n << 26n,
633
+ manageNicknames: 1n << 27n,
634
+ manageRoles: 1n << 28n,
635
+ manageWebhooks: 1n << 29n,
636
+ manageGuildExpressions: 1n << 30n,
637
+ useApplicationCommands: 1n << 31n,
638
+ requestToSpeak: 1n << 32n,
639
+ manageEvents: 1n << 33n,
640
+ manageThreads: 1n << 34n,
641
+ createPublicThreads: 1n << 35n,
642
+ createPrivateThreads: 1n << 36n,
643
+ useExternalStickers: 1n << 37n,
644
+ sendMessagesInThreads: 1n << 38n,
645
+ useEmbeddedActivities: 1n << 39n,
646
+ moderateMembers: 1n << 40n,
647
+ viewCreatorMonetizationAnalytics: 1n << 41n,
648
+ useSoundboard: 1n << 42n,
649
+ createGuildExpressions: 1n << 43n,
650
+ createEvents: 1n << 44n,
651
+ useExternalSounds: 1n << 45n,
652
+ sendVoiceMessages: 1n << 46n,
653
+ sendPolls: 1n << 49n,
654
+ useExternalApps: 1n << 50n
655
+ };
326
656
  var Permissions = {
327
657
  CreateInstantInvite: 1n << 0n,
328
658
  KickMembers: 1n << 1n,
@@ -374,6 +704,57 @@ var Permissions = {
374
704
  SendPolls: 1n << 49n,
375
705
  UseExternalApps: 1n << 50n
376
706
  };
707
+ var PermissionFlagsBits = {
708
+ CreateInstantInvite: 1n << 0n,
709
+ KickMembers: 1n << 1n,
710
+ BanMembers: 1n << 2n,
711
+ Administrator: 1n << 3n,
712
+ ManageChannels: 1n << 4n,
713
+ ManageGuild: 1n << 5n,
714
+ AddReactions: 1n << 6n,
715
+ ViewAuditLog: 1n << 7n,
716
+ PrioritySpeaker: 1n << 8n,
717
+ Stream: 1n << 9n,
718
+ ViewChannel: 1n << 10n,
719
+ SendMessages: 1n << 11n,
720
+ SendTTSMessages: 1n << 12n,
721
+ ManageMessages: 1n << 13n,
722
+ EmbedLinks: 1n << 14n,
723
+ AttachFiles: 1n << 15n,
724
+ ReadMessageHistory: 1n << 16n,
725
+ MentionEveryone: 1n << 17n,
726
+ UseExternalEmojis: 1n << 18n,
727
+ ViewGuildInsights: 1n << 19n,
728
+ Connect: 1n << 20n,
729
+ Speak: 1n << 21n,
730
+ MuteMembers: 1n << 22n,
731
+ DeafenMembers: 1n << 23n,
732
+ MoveMembers: 1n << 24n,
733
+ UseVAD: 1n << 25n,
734
+ ChangeNickname: 1n << 26n,
735
+ ManageNicknames: 1n << 27n,
736
+ ManageRoles: 1n << 28n,
737
+ ManageWebhooks: 1n << 29n,
738
+ ManageGuildExpressions: 1n << 30n,
739
+ UseApplicationCommands: 1n << 31n,
740
+ RequestToSpeak: 1n << 32n,
741
+ ManageEvents: 1n << 33n,
742
+ ManageThreads: 1n << 34n,
743
+ CreatePublicThreads: 1n << 35n,
744
+ CreatePrivateThreads: 1n << 36n,
745
+ UseExternalStickers: 1n << 37n,
746
+ SendMessagesInThreads: 1n << 38n,
747
+ UseEmbeddedActivities: 1n << 39n,
748
+ ModerateMembers: 1n << 40n,
749
+ ViewCreatorMonetizationAnalytics: 1n << 41n,
750
+ UseSoundboard: 1n << 42n,
751
+ CreateGuildExpressions: 1n << 43n,
752
+ CreateEvents: 1n << 44n,
753
+ UseExternalSounds: 1n << 45n,
754
+ SendVoiceMessages: 1n << 46n,
755
+ SendPolls: 1n << 49n,
756
+ UseExternalApps: 1n << 50n
757
+ };
377
758
 
378
759
  class PermissionSet {
379
760
  bitfield;
@@ -381,8 +762,9 @@ class PermissionSet {
381
762
  try {
382
763
  if (Array.isArray(value)) {
383
764
  let bit = 0n;
384
- for (const item of value)
765
+ for (const item of value) {
385
766
  bit |= this.#resolve(item);
767
+ }
386
768
  this.bitfield = bit;
387
769
  } else if (value instanceof PermissionSet) {
388
770
  this.bitfield = value.bitfield;
@@ -398,22 +780,195 @@ class PermissionSet {
398
780
  throw new TypeError("Permission bitfield must be a valid non-negative integer.", { cause: error });
399
781
  }
400
782
  }
783
+ get createInstantInvite() {
784
+ return (this.bitfield & Permission.createInstantInvite) === Permission.createInstantInvite;
785
+ }
786
+ get kickMembers() {
787
+ return (this.bitfield & Permission.kickMembers) === Permission.kickMembers;
788
+ }
789
+ get banMembers() {
790
+ return (this.bitfield & Permission.banMembers) === Permission.banMembers;
791
+ }
792
+ get administrator() {
793
+ return (this.bitfield & Permission.administrator) === Permission.administrator;
794
+ }
795
+ get manageChannels() {
796
+ return (this.bitfield & Permission.manageChannels) === Permission.manageChannels;
797
+ }
798
+ get manageGuild() {
799
+ return (this.bitfield & Permission.manageGuild) === Permission.manageGuild;
800
+ }
801
+ get addReactions() {
802
+ return (this.bitfield & Permission.addReactions) === Permission.addReactions;
803
+ }
804
+ get viewAuditLog() {
805
+ return (this.bitfield & Permission.viewAuditLog) === Permission.viewAuditLog;
806
+ }
807
+ get prioritySpeaker() {
808
+ return (this.bitfield & Permission.prioritySpeaker) === Permission.prioritySpeaker;
809
+ }
810
+ get stream() {
811
+ return (this.bitfield & Permission.stream) === Permission.stream;
812
+ }
813
+ get viewChannel() {
814
+ return (this.bitfield & Permission.viewChannel) === Permission.viewChannel;
815
+ }
816
+ get sendMessages() {
817
+ return (this.bitfield & Permission.sendMessages) === Permission.sendMessages;
818
+ }
819
+ get sendTTSMessages() {
820
+ return (this.bitfield & Permission.sendTTSMessages) === Permission.sendTTSMessages;
821
+ }
822
+ get manageMessages() {
823
+ return (this.bitfield & Permission.manageMessages) === Permission.manageMessages;
824
+ }
825
+ get embedLinks() {
826
+ return (this.bitfield & Permission.embedLinks) === Permission.embedLinks;
827
+ }
828
+ get attachFiles() {
829
+ return (this.bitfield & Permission.attachFiles) === Permission.attachFiles;
830
+ }
831
+ get readMessageHistory() {
832
+ return (this.bitfield & Permission.readMessageHistory) === Permission.readMessageHistory;
833
+ }
834
+ get mentionEveryone() {
835
+ return (this.bitfield & Permission.mentionEveryone) === Permission.mentionEveryone;
836
+ }
837
+ get useExternalEmojis() {
838
+ return (this.bitfield & Permission.useExternalEmojis) === Permission.useExternalEmojis;
839
+ }
840
+ get viewGuildInsights() {
841
+ return (this.bitfield & Permission.viewGuildInsights) === Permission.viewGuildInsights;
842
+ }
843
+ get connect() {
844
+ return (this.bitfield & Permission.connect) === Permission.connect;
845
+ }
846
+ get speak() {
847
+ return (this.bitfield & Permission.speak) === Permission.speak;
848
+ }
849
+ get muteMembers() {
850
+ return (this.bitfield & Permission.muteMembers) === Permission.muteMembers;
851
+ }
852
+ get deafenMembers() {
853
+ return (this.bitfield & Permission.deafenMembers) === Permission.deafenMembers;
854
+ }
855
+ get moveMembers() {
856
+ return (this.bitfield & Permission.moveMembers) === Permission.moveMembers;
857
+ }
858
+ get useVAD() {
859
+ return (this.bitfield & Permission.useVAD) === Permission.useVAD;
860
+ }
861
+ get changeNickname() {
862
+ return (this.bitfield & Permission.changeNickname) === Permission.changeNickname;
863
+ }
864
+ get manageNicknames() {
865
+ return (this.bitfield & Permission.manageNicknames) === Permission.manageNicknames;
866
+ }
867
+ get manageRoles() {
868
+ return (this.bitfield & Permission.manageRoles) === Permission.manageRoles;
869
+ }
870
+ get manageWebhooks() {
871
+ return (this.bitfield & Permission.manageWebhooks) === Permission.manageWebhooks;
872
+ }
873
+ get manageGuildExpressions() {
874
+ return (this.bitfield & Permission.manageGuildExpressions) === Permission.manageGuildExpressions;
875
+ }
876
+ get useApplicationCommands() {
877
+ return (this.bitfield & Permission.useApplicationCommands) === Permission.useApplicationCommands;
878
+ }
879
+ get requestToSpeak() {
880
+ return (this.bitfield & Permission.requestToSpeak) === Permission.requestToSpeak;
881
+ }
882
+ get manageEvents() {
883
+ return (this.bitfield & Permission.manageEvents) === Permission.manageEvents;
884
+ }
885
+ get manageThreads() {
886
+ return (this.bitfield & Permission.manageThreads) === Permission.manageThreads;
887
+ }
888
+ get createPublicThreads() {
889
+ return (this.bitfield & Permission.createPublicThreads) === Permission.createPublicThreads;
890
+ }
891
+ get createPrivateThreads() {
892
+ return (this.bitfield & Permission.createPrivateThreads) === Permission.createPrivateThreads;
893
+ }
894
+ get useExternalStickers() {
895
+ return (this.bitfield & Permission.useExternalStickers) === Permission.useExternalStickers;
896
+ }
897
+ get sendMessagesInThreads() {
898
+ return (this.bitfield & Permission.sendMessagesInThreads) === Permission.sendMessagesInThreads;
899
+ }
900
+ get useEmbeddedActivities() {
901
+ return (this.bitfield & Permission.useEmbeddedActivities) === Permission.useEmbeddedActivities;
902
+ }
903
+ get moderateMembers() {
904
+ return (this.bitfield & Permission.moderateMembers) === Permission.moderateMembers;
905
+ }
906
+ get viewCreatorMonetizationAnalytics() {
907
+ return (this.bitfield & Permission.viewCreatorMonetizationAnalytics) === Permission.viewCreatorMonetizationAnalytics;
908
+ }
909
+ get useSoundboard() {
910
+ return (this.bitfield & Permission.useSoundboard) === Permission.useSoundboard;
911
+ }
912
+ get createGuildExpressions() {
913
+ return (this.bitfield & Permission.createGuildExpressions) === Permission.createGuildExpressions;
914
+ }
915
+ get createEvents() {
916
+ return (this.bitfield & Permission.createEvents) === Permission.createEvents;
917
+ }
918
+ get useExternalSounds() {
919
+ return (this.bitfield & Permission.useExternalSounds) === Permission.useExternalSounds;
920
+ }
921
+ get sendVoiceMessages() {
922
+ return (this.bitfield & Permission.sendVoiceMessages) === Permission.sendVoiceMessages;
923
+ }
924
+ get sendPolls() {
925
+ return (this.bitfield & Permission.sendPolls) === Permission.sendPolls;
926
+ }
927
+ get useExternalApps() {
928
+ return (this.bitfield & Permission.useExternalApps) === Permission.useExternalApps;
929
+ }
401
930
  has(...permissions) {
402
- return permissions.every((permission) => (this.bitfield & this.#resolve(permission)) === this.#resolve(permission));
931
+ if (permissions.length === 1) {
932
+ const p = permissions[0];
933
+ const bit = typeof p === "bigint" ? p : this.#resolve(p);
934
+ return (this.bitfield & bit) === bit;
935
+ }
936
+ for (let i = 0;i < permissions.length; i++) {
937
+ const p = permissions[i];
938
+ const bit = typeof p === "bigint" ? p : this.#resolve(p);
939
+ if ((this.bitfield & bit) !== bit)
940
+ return false;
941
+ }
942
+ return true;
403
943
  }
404
944
  any(...permissions) {
405
- return permissions.some((permission) => (this.bitfield & this.#resolve(permission)) !== 0n);
945
+ if (permissions.length === 1) {
946
+ const p = permissions[0];
947
+ const bit = typeof p === "bigint" ? p : this.#resolve(p);
948
+ return (this.bitfield & bit) !== 0n;
949
+ }
950
+ for (let i = 0;i < permissions.length; i++) {
951
+ const p = permissions[i];
952
+ const bit = typeof p === "bigint" ? p : this.#resolve(p);
953
+ if ((this.bitfield & bit) !== 0n)
954
+ return true;
955
+ }
956
+ return false;
406
957
  }
407
958
  add(...permissions) {
408
959
  let bitfield = this.bitfield;
409
- for (const permission of permissions)
410
- bitfield |= this.#resolve(permission);
960
+ for (let i = 0;i < permissions.length; i++) {
961
+ const p = permissions[i];
962
+ bitfield |= typeof p === "bigint" ? p : this.#resolve(p);
963
+ }
411
964
  return new PermissionSet(bitfield);
412
965
  }
413
966
  remove(...permissions) {
414
967
  let bitfield = this.bitfield;
415
- for (const permission of permissions)
416
- bitfield &= ~this.#resolve(permission);
968
+ for (let i = 0;i < permissions.length; i++) {
969
+ const p = permissions[i];
970
+ bitfield &= ~(typeof p === "bigint" ? p : this.#resolve(p));
971
+ }
417
972
  return new PermissionSet(bitfield);
418
973
  }
419
974
  equals(other) {
@@ -423,27 +978,31 @@ class PermissionSet {
423
978
  return this.bitfield.toString();
424
979
  }
425
980
  toArray() {
426
- return Object.keys(Permissions).filter((permission) => this.has(permission));
981
+ return Object.keys(Permission).filter((permission) => this.has(permission));
427
982
  }
428
983
  #resolve(permission) {
429
- if (permission instanceof PermissionSet)
430
- return permission.bitfield;
431
984
  if (typeof permission === "bigint")
432
985
  return permission;
433
986
  if (typeof permission === "number")
434
987
  return BigInt(permission);
988
+ if (permission instanceof PermissionSet)
989
+ return permission.bitfield;
435
990
  if (Array.isArray(permission)) {
436
991
  let bit = 0n;
437
- for (const p of permission)
438
- bit |= this.#resolve(p);
992
+ for (let i = 0;i < permission.length; i++)
993
+ bit |= this.#resolve(permission[i]);
439
994
  return bit;
440
995
  }
441
996
  if (typeof permission === "string") {
997
+ if (permission in Permission)
998
+ return Permission[permission];
442
999
  if (permission in Permissions)
443
1000
  return Permissions[permission];
444
- const matchedKey = Object.keys(Permissions).find((k) => k.toLowerCase() === permission.toLowerCase());
445
- if (matchedKey)
446
- return Permissions[matchedKey];
1001
+ if (permission in PermissionFlagsBits)
1002
+ return PermissionFlagsBits[permission];
1003
+ const lower = permission.charAt(0).toLowerCase() + permission.slice(1);
1004
+ if (lower in Permission)
1005
+ return Permission[lower];
447
1006
  return BigInt(permission);
448
1007
  }
449
1008
  return 0n;
@@ -451,12 +1010,72 @@ class PermissionSet {
451
1010
  }
452
1011
 
453
1012
  class PermissionsBitField extends PermissionSet {
1013
+ static Flags = PermissionFlagsBits;
1014
+ static All = Permission;
454
1015
  constructor(value = 0n) {
455
1016
  super(value);
456
1017
  }
457
1018
  }
458
-
1019
+ // packages/types/src/index.ts
1020
+ var GatewayIntentBits = {
1021
+ Guilds: 1 << 0,
1022
+ GuildMembers: 1 << 1,
1023
+ GuildModeration: 1 << 2,
1024
+ GuildExpressions: 1 << 3,
1025
+ GuildIntegrations: 1 << 4,
1026
+ GuildWebhooks: 1 << 5,
1027
+ GuildInvites: 1 << 6,
1028
+ GuildVoiceStates: 1 << 7,
1029
+ GuildPresences: 1 << 8,
1030
+ GuildMessages: 1 << 9,
1031
+ GuildMessageReactions: 1 << 10,
1032
+ GuildMessageTyping: 1 << 11,
1033
+ DirectMessages: 1 << 12,
1034
+ DirectMessageReactions: 1 << 13,
1035
+ DirectMessageTyping: 1 << 14,
1036
+ MessageContent: 1 << 15,
1037
+ GuildScheduledEvents: 1 << 16,
1038
+ AutoModerationConfiguration: 1 << 20,
1039
+ AutoModerationExecution: 1 << 21,
1040
+ GuildMessagePolls: 1 << 24,
1041
+ DirectMessagePolls: 1 << 25
1042
+ };
1043
+ var IntentBits = {
1044
+ guild: 1 << 0,
1045
+ guilds: 1 << 0,
1046
+ guildMembers: 1 << 1,
1047
+ guildModeration: 1 << 2,
1048
+ guildBans: 1 << 2,
1049
+ guildExpressions: 1 << 3,
1050
+ guildEmojis: 1 << 3,
1051
+ guildEmojisAndStickers: 1 << 3,
1052
+ guildIntegrations: 1 << 4,
1053
+ guildWebhooks: 1 << 5,
1054
+ guildInvites: 1 << 6,
1055
+ guildVoiceStates: 1 << 7,
1056
+ guildPresences: 1 << 8,
1057
+ guildMessages: 1 << 9,
1058
+ guildMessage: 1 << 9,
1059
+ guildMessageReactions: 1 << 10,
1060
+ guildMessageTyping: 1 << 11,
1061
+ directMessages: 1 << 12,
1062
+ directMessageReactions: 1 << 13,
1063
+ directMessageTyping: 1 << 14,
1064
+ messageContent: 1 << 15,
1065
+ guildScheduledEvents: 1 << 16,
1066
+ autoModerationConfiguration: 1 << 20,
1067
+ autoModerationExecution: 1 << 21,
1068
+ guildMessagePolls: 1 << 24,
1069
+ directMessagePolls: 1 << 25
1070
+ };
459
1071
  // packages/structures/src/resources.ts
1072
+ function toDateOrNull(value) {
1073
+ if (!value)
1074
+ return null;
1075
+ const date = new Date(value);
1076
+ return Number.isNaN(date.getTime()) ? null : date;
1077
+ }
1078
+
460
1079
  class GuildMember {
461
1080
  user;
462
1081
  guildId;
@@ -465,6 +1084,10 @@ class GuildMember {
465
1084
  pending;
466
1085
  joinedAt;
467
1086
  permissions;
1087
+ avatarHash;
1088
+ premiumSince;
1089
+ timedOutUntil;
1090
+ flags;
468
1091
  constructor(data) {
469
1092
  this.user = new User(data.user);
470
1093
  if (!/^\d{1,20}$/.test(data.guild_id))
@@ -477,10 +1100,28 @@ class GuildMember {
477
1100
  if (this.joinedAt?.toString() === "Invalid Date")
478
1101
  throw new RangeError("Member joined_at must be a valid date.");
479
1102
  this.permissions = new PermissionsBitField(data.permissions ?? 0n);
1103
+ this.avatarHash = data.avatar ?? null;
1104
+ this.premiumSince = toDateOrNull(data.premium_since);
1105
+ this.timedOutUntil = toDateOrNull(data.communication_disabled_until);
1106
+ this.flags = data.flags ?? 0;
480
1107
  }
481
1108
  get displayName() {
482
1109
  return this.nickname ?? this.user.displayName;
483
1110
  }
1111
+ get isTimedOut() {
1112
+ return this.timedOutUntil !== null && this.timedOutUntil > new Date;
1113
+ }
1114
+ avatarURL(options = {}) {
1115
+ if (this.avatarHash)
1116
+ return cdnURL(`/guilds/${this.guildId}/users/${this.user.id}/avatars`, this.avatarHash, options);
1117
+ return this.user.avatarURL(options);
1118
+ }
1119
+ displayAvatarURL(options = {}) {
1120
+ return this.avatarURL(options) ?? this.user.displayAvatarURL(options);
1121
+ }
1122
+ toString() {
1123
+ return this.user.toString();
1124
+ }
484
1125
  }
485
1126
 
486
1127
  class Role extends BaseStructure {
@@ -490,6 +1131,10 @@ class Role extends BaseStructure {
490
1131
  permissions;
491
1132
  managed;
492
1133
  mentionable;
1134
+ position;
1135
+ unicodeEmoji;
1136
+ iconHash;
1137
+ tags;
493
1138
  constructor(data) {
494
1139
  super(data.id);
495
1140
  if (!data.name)
@@ -500,13 +1145,101 @@ class Role extends BaseStructure {
500
1145
  this.permissions = new PermissionsBitField(data.permissions ?? 0n);
501
1146
  this.managed = data.managed ?? false;
502
1147
  this.mentionable = data.mentionable ?? false;
1148
+ this.position = data.position ?? 0;
1149
+ this.unicodeEmoji = data.unicode_emoji ?? null;
1150
+ this.iconHash = data.icon ?? null;
1151
+ this.tags = data.tags ?? null;
1152
+ }
1153
+ get colorHex() {
1154
+ return `#${this.color.toString(16).padStart(6, "0").toUpperCase()}`;
1155
+ }
1156
+ iconURL(options = {}) {
1157
+ if (!this.iconHash)
1158
+ return null;
1159
+ return cdnURL(`/role-icons/${this.id}`, this.iconHash, options);
1160
+ }
1161
+ isEveryone(guildId) {
1162
+ return this.id === guildId;
503
1163
  }
504
1164
  toString() {
505
1165
  return `<@&${this.id}>`;
506
1166
  }
507
1167
  }
1168
+ class Emoji extends BaseStructure {
1169
+ name;
1170
+ roleIds;
1171
+ user;
1172
+ requireColons;
1173
+ managed;
1174
+ animated;
1175
+ available;
1176
+ constructor(data) {
1177
+ super(data.id ?? "unicode");
1178
+ this.name = data.name;
1179
+ this.roleIds = data.roles ?? [];
1180
+ this.user = data.user ? new User(data.user) : null;
1181
+ this.requireColons = data.require_colons ?? false;
1182
+ this.managed = data.managed ?? false;
1183
+ this.animated = data.animated ?? false;
1184
+ this.available = data.available ?? true;
1185
+ }
1186
+ url(options = {}) {
1187
+ if (!this.id || this.id === "unicode")
1188
+ return null;
1189
+ const ext = options.extension ?? (this.animated ? "gif" : "png");
1190
+ const size = options.size ? `?size=${options.size}` : "";
1191
+ return `${CDN_BASE}/emojis/${this.id}.${ext}${size}`;
1192
+ }
1193
+ toString() {
1194
+ return this.id !== "unicode" ? `<${this.animated ? "a" : ""}:${this.name}:${this.id}>` : this.name ?? "";
1195
+ }
1196
+ }
508
1197
 
1198
+ class AutoModerationRule extends BaseStructure {
1199
+ guildId;
1200
+ name;
1201
+ creatorId;
1202
+ eventType;
1203
+ triggerType;
1204
+ triggerMetadata;
1205
+ actions;
1206
+ enabled;
1207
+ exemptRoles;
1208
+ exemptChannels;
1209
+ constructor(data) {
1210
+ super(data.id);
1211
+ if (!/^\d{1,20}$/.test(data.guild_id))
1212
+ throw new TypeError("AutoModerationRule guild_id must be a valid snowflake.");
1213
+ this.guildId = data.guild_id;
1214
+ this.name = data.name;
1215
+ this.creatorId = data.creator_id;
1216
+ this.eventType = data.event_type;
1217
+ this.triggerType = data.trigger_type;
1218
+ this.triggerMetadata = data.trigger_metadata;
1219
+ this.actions = data.actions;
1220
+ this.enabled = data.enabled;
1221
+ this.exemptRoles = data.exempt_roles;
1222
+ this.exemptChannels = data.exempt_channels;
1223
+ }
1224
+ toJSON() {
1225
+ return {
1226
+ id: this.id,
1227
+ guildId: this.guildId,
1228
+ name: this.name,
1229
+ creatorId: this.creatorId,
1230
+ eventType: this.eventType,
1231
+ triggerType: this.triggerType,
1232
+ triggerMetadata: this.triggerMetadata,
1233
+ actions: this.actions,
1234
+ enabled: this.enabled,
1235
+ exemptRoles: this.exemptRoles,
1236
+ exemptChannels: this.exemptChannels
1237
+ };
1238
+ }
1239
+ }
509
1240
  // packages/structures/src/index.ts
1241
+ var NON_SYSTEM_MESSAGE_TYPES = new Set([0, 19, 20, 23]);
1242
+
510
1243
  class Message extends BaseStructure {
511
1244
  content;
512
1245
  author;
@@ -514,7 +1247,7 @@ class Message extends BaseStructure {
514
1247
  channel;
515
1248
  guildId;
516
1249
  flags;
517
- createdAt;
1250
+ timestamp;
518
1251
  attachments;
519
1252
  embeds;
520
1253
  mentions;
@@ -523,6 +1256,7 @@ class Message extends BaseStructure {
523
1256
  mentionEveryone;
524
1257
  type;
525
1258
  reference;
1259
+ components;
526
1260
  referencedMessage;
527
1261
  #context;
528
1262
  constructor(data, context) {
@@ -534,9 +1268,10 @@ class Message extends BaseStructure {
534
1268
  this.channelId = data.channel_id;
535
1269
  this.guildId = data.guild_id;
536
1270
  this.flags = data.flags ?? 0;
537
- this.createdAt = new Date(data.timestamp ?? Number((BigInt(this.id) >> 22n) + 1420070400000n));
1271
+ this.timestamp = new Date(data.timestamp ?? Number((BigInt(this.id) >> 22n) + 1420070400000n));
538
1272
  this.attachments = data.attachments ?? [];
539
1273
  this.embeds = data.embeds ?? [];
1274
+ this.components = data.components ?? [];
540
1275
  this.mentions = (data.mentions ?? []).map((user) => new User(user));
541
1276
  this.mentionRoles = data.mention_roles ?? [];
542
1277
  this.pinned = data.pinned ?? false;
@@ -550,21 +1285,25 @@ class Message extends BaseStructure {
550
1285
  get embedsSuppressed() {
551
1286
  return (this.flags & 4) !== 0;
552
1287
  }
1288
+ get createdTimestamp() {
1289
+ return this.timestamp.getTime();
1290
+ }
1291
+ get createdAt() {
1292
+ return this.timestamp;
1293
+ }
553
1294
  edit(options) {
554
1295
  if (!this.#context)
555
1296
  throw new Error("This message is not attached to a client.");
556
1297
  return this.#context.editMessage(this.channelId, this.id, options);
557
1298
  }
1299
+ update(options) {
1300
+ return this.edit(options);
1301
+ }
558
1302
  delete() {
559
1303
  if (!this.#context)
560
1304
  throw new Error("This message is not attached to a client.");
561
1305
  return this.#context.deleteMessage(this.channelId, this.id);
562
1306
  }
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
1307
  reply(options) {
569
1308
  if (!this.#context)
570
1309
  throw new Error("This message is not attached to a client.");
@@ -576,6 +1315,81 @@ class Message extends BaseStructure {
576
1315
  };
577
1316
  return this.#context.sendMessage(this.channelId, payload);
578
1317
  }
1318
+ crosspost() {
1319
+ if (!this.#context)
1320
+ throw new Error("This message is not attached to a client.");
1321
+ return this.#context.crosspostMessage(this.channelId, this.id);
1322
+ }
1323
+ react(emoji) {
1324
+ if (!this.#context?.addReaction)
1325
+ throw new Error("This message is not attached to a client.");
1326
+ return this.#context.addReaction(this.channelId, this.id, emoji);
1327
+ }
1328
+ removeReaction(emoji, userId) {
1329
+ if (!this.#context)
1330
+ throw new Error("This message is not attached to a client.");
1331
+ return userId ? this.#context.removeReaction?.(this.channelId, this.id, emoji, userId) ?? Promise.reject(new Error("Reaction operations are unavailable.")) : this.#context.removeOwnReaction?.(this.channelId, this.id, emoji) ?? Promise.reject(new Error("Reaction operations are unavailable."));
1332
+ }
1333
+ removeAllReactions() {
1334
+ if (!this.#context?.removeAllReactions)
1335
+ throw new Error("This message is not attached to a client.");
1336
+ return this.#context.removeAllReactions(this.channelId, this.id);
1337
+ }
1338
+ pin() {
1339
+ if (!this.#context?.pinMessage)
1340
+ throw new Error("This message is not attached to a client.");
1341
+ return this.#context.pinMessage(this.channelId, this.id);
1342
+ }
1343
+ unpin() {
1344
+ if (!this.#context?.unpinMessage)
1345
+ throw new Error("This message is not attached to a client.");
1346
+ return this.#context.unpinMessage(this.channelId, this.id);
1347
+ }
1348
+ get isEphemeral() {
1349
+ return (this.flags & 64) !== 0;
1350
+ }
1351
+ get isPinned() {
1352
+ return this.pinned;
1353
+ }
1354
+ get isSystemMessage() {
1355
+ return !NON_SYSTEM_MESSAGE_TYPES.has(this.type);
1356
+ }
1357
+ get isCrosspost() {
1358
+ return (this.flags & 2) !== 0;
1359
+ }
1360
+ get hasAttachments() {
1361
+ return this.attachments.length > 0;
1362
+ }
1363
+ get hasEmbeds() {
1364
+ return this.embeds.length > 0;
1365
+ }
1366
+ get hasComponents() {
1367
+ return this.components.length > 0;
1368
+ }
1369
+ suppressEmbeds() {
1370
+ return this.edit({ flags: this.flags | 4 });
1371
+ }
1372
+ toJSON() {
1373
+ return {
1374
+ id: this.id,
1375
+ content: this.content,
1376
+ channelId: this.channelId,
1377
+ guildId: this.guildId,
1378
+ flags: this.flags,
1379
+ pinned: this.pinned,
1380
+ mentionEveryone: this.mentionEveryone,
1381
+ type: this.type,
1382
+ timestamp: this.timestamp.toISOString(),
1383
+ author: { id: this.author.id, username: this.author.username },
1384
+ attachments: [...this.attachments],
1385
+ embeds: [...this.embeds],
1386
+ components: [...this.components],
1387
+ mentions: this.mentions.map((u) => u.id),
1388
+ mentionRoles: [...this.mentionRoles],
1389
+ reference: this.reference,
1390
+ referencedMessage: this.referencedMessage ? this.referencedMessage.id : this.referencedMessage
1391
+ };
1392
+ }
579
1393
  }
580
1394
 
581
1395
  // packages/managers/src/message.ts
@@ -600,10 +1414,7 @@ class MessageManager {
600
1414
  }
601
1415
  async fetch(messageId) {
602
1416
  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);
1417
+ return this.upsert(data);
607
1418
  }
608
1419
  fetchMany(messageIds) {
609
1420
  return Promise.all(Array.from(messageIds, (messageId) => this.fetch(messageId)));
@@ -644,6 +1455,161 @@ class ThreadManager {
644
1455
  return new Channel(data, this.#context);
645
1456
  }
646
1457
  }
1458
+
1459
+ // packages/managers/src/user.ts
1460
+ class UserManager extends ResourceManager {
1461
+ #rest;
1462
+ constructor(rest) {
1463
+ super(async (id) => new User(await rest.get(Routes.userById(id))), (user) => user.id);
1464
+ this.#rest = rest;
1465
+ }
1466
+ async fetchMe() {
1467
+ const data = await this.#rest.get("/users/@me");
1468
+ return this.upsert(new User(data));
1469
+ }
1470
+ async editMe(options) {
1471
+ const data = await this.#rest.patch("/users/@me", options);
1472
+ return this.upsert(new User(data));
1473
+ }
1474
+ async leaveGuild(guildId) {
1475
+ await this.#rest.delete(`/users/@me/guilds/${guildId}`);
1476
+ }
1477
+ async createDM(userId) {
1478
+ return this.#rest.post("/users/@me/channels", {
1479
+ recipient_id: userId
1480
+ });
1481
+ }
1482
+ }
1483
+ // packages/managers/src/guild.ts
1484
+ function withQuery(path, params) {
1485
+ const suffix = params.toString();
1486
+ return suffix ? `${path}?${suffix}` : path;
1487
+ }
1488
+
1489
+ class GuildManager extends ResourceManager {
1490
+ #rest;
1491
+ constructor(rest) {
1492
+ super(async (id) => new Guild(await rest.get(Routes.guild(id))), (guild) => guild.id);
1493
+ this.#rest = rest;
1494
+ }
1495
+ async create(options) {
1496
+ const data = await this.#rest.post("/guilds", options);
1497
+ return this.upsert(new Guild(data));
1498
+ }
1499
+ async edit(id, options) {
1500
+ const data = await this.#rest.patch(Routes.guild(id), options);
1501
+ return this.upsert(new Guild(data));
1502
+ }
1503
+ async deleteGuild(id) {
1504
+ await this.#rest.delete(Routes.guild(id));
1505
+ }
1506
+ async fetchPreview(id) {
1507
+ return this.#rest.get(Routes.guildPreview(id));
1508
+ }
1509
+ async fetchActiveThreads(id) {
1510
+ return this.#rest.get(Routes.guildActiveThreads(id));
1511
+ }
1512
+ async fetchWebhooks(id) {
1513
+ return this.#rest.get(Routes.guildWebhooks(id));
1514
+ }
1515
+ async fetchInvites(id) {
1516
+ return this.#rest.get(Routes.guildInvites(id));
1517
+ }
1518
+ async fetchAuditLog(guildId, options = {}) {
1519
+ const params = new URLSearchParams;
1520
+ if (options.userId)
1521
+ params.set("user_id", options.userId);
1522
+ if (options.actionType !== undefined)
1523
+ params.set("action_type", String(options.actionType));
1524
+ if (options.before)
1525
+ params.set("before", options.before);
1526
+ if (options.after)
1527
+ params.set("after", options.after);
1528
+ if (options.limit !== undefined)
1529
+ params.set("limit", String(Math.min(100, Math.max(1, options.limit))));
1530
+ return this.#rest.get(withQuery(Routes.guildAuditLog(guildId), params));
1531
+ }
1532
+ async fetchMembers(guildId, options = {}) {
1533
+ const params = new URLSearchParams;
1534
+ if (options.limit !== undefined)
1535
+ params.set("limit", String(Math.min(1000, Math.max(1, options.limit))));
1536
+ if (options.after)
1537
+ params.set("after", options.after);
1538
+ return this.#rest.get(withQuery(Routes.guildMembers(guildId), params));
1539
+ }
1540
+ async fetchAutoModerationRules(guildId) {
1541
+ const rules = await this.#rest.get(Routes.guildAutoModerationRules(guildId));
1542
+ return rules.map((r) => new AutoModerationRule(r));
1543
+ }
1544
+ async fetchAutoModerationRule(guildId, ruleId) {
1545
+ const rule = await this.#rest.get(Routes.guildAutoModerationRule(guildId, ruleId));
1546
+ return new AutoModerationRule(rule);
1547
+ }
1548
+ async createAutoModerationRule(guildId, options) {
1549
+ const rule = await this.#rest.post(Routes.guildAutoModerationRules(guildId), options);
1550
+ return new AutoModerationRule(rule);
1551
+ }
1552
+ async editAutoModerationRule(guildId, ruleId, options) {
1553
+ const rule = await this.#rest.patch(Routes.guildAutoModerationRule(guildId, ruleId), options);
1554
+ return new AutoModerationRule(rule);
1555
+ }
1556
+ async deleteAutoModerationRule(guildId, ruleId) {
1557
+ await this.#rest.delete(Routes.guildAutoModerationRule(guildId, ruleId));
1558
+ }
1559
+ }
1560
+ var AuditLogEvent = {
1561
+ GuildUpdate: 1,
1562
+ ChannelCreate: 10,
1563
+ ChannelUpdate: 11,
1564
+ ChannelDelete: 12,
1565
+ ChannelOverwriteCreate: 13,
1566
+ ChannelOverwriteUpdate: 14,
1567
+ ChannelOverwriteDelete: 15,
1568
+ MemberKick: 20,
1569
+ MemberPrune: 21,
1570
+ MemberBanAdd: 22,
1571
+ MemberBanRemove: 23,
1572
+ MemberUpdate: 24,
1573
+ MemberRoleUpdate: 25,
1574
+ MemberMove: 26,
1575
+ MemberDisconnect: 27,
1576
+ BotAdd: 28,
1577
+ RoleCreate: 30,
1578
+ RoleUpdate: 31,
1579
+ RoleDelete: 32,
1580
+ InviteCreate: 40,
1581
+ InviteUpdate: 41,
1582
+ InviteDelete: 42,
1583
+ WebhookCreate: 50,
1584
+ WebhookUpdate: 51,
1585
+ WebhookDelete: 52,
1586
+ EmojiCreate: 60,
1587
+ EmojiUpdate: 61,
1588
+ EmojiDelete: 62,
1589
+ MessageDelete: 72,
1590
+ MessageBulkDelete: 73,
1591
+ MessagePin: 74,
1592
+ MessageUnpin: 75,
1593
+ IntegrationCreate: 80,
1594
+ IntegrationUpdate: 81,
1595
+ IntegrationDelete: 82,
1596
+ StageInstanceCreate: 83,
1597
+ StageInstanceUpdate: 84,
1598
+ StageInstanceDelete: 85,
1599
+ StickerCreate: 90,
1600
+ StickerUpdate: 91,
1601
+ StickerDelete: 92,
1602
+ ScheduledEventCreate: 100,
1603
+ ScheduledEventUpdate: 101,
1604
+ ScheduledEventDelete: 102,
1605
+ ThreadCreate: 110,
1606
+ ThreadUpdate: 111,
1607
+ ThreadDelete: 112,
1608
+ AutoModerationRuleCreate: 140,
1609
+ AutoModerationRuleUpdate: 141,
1610
+ AutoModerationRuleDelete: 142,
1611
+ AutoModerationBlockMessage: 143
1612
+ };
647
1613
  // packages/managers/src/role.ts
648
1614
  class RoleManager extends ResourceManager {
649
1615
  #rest;
@@ -764,25 +1730,46 @@ class ApplicationCommandManager {
764
1730
  await this.#rest.delete(Routes.guildApplicationCommand(this.#applicationId, guildId, commandId));
765
1731
  }
766
1732
  }
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);
1733
+ // packages/managers/src/emoji.ts
1734
+ class EmojiManager extends Manager {
1735
+ #rest;
1736
+ #guildId;
1737
+ constructor(rest, guildId) {
1738
+ super();
1739
+ this.#rest = rest;
1740
+ this.#guildId = guildId;
772
1741
  }
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);
1742
+ async fetch(emojiId) {
1743
+ return this.upsert(await this.#rest.get(Routes.guildEmoji(this.#guildId, emojiId)));
1744
+ }
1745
+ async fetchAll() {
1746
+ const data = await this.#rest.get(Routes.guildEmoji(this.#guildId));
1747
+ return data.map((item) => this.upsert(item));
1748
+ }
1749
+ async create(options) {
1750
+ return this.upsert(await this.#rest.post(Routes.guildEmoji(this.#guildId), options));
1751
+ }
1752
+ async edit(emojiId, options) {
1753
+ return this.upsert(await this.#rest.patch(Routes.guildEmoji(this.#guildId, emojiId), options));
1754
+ }
1755
+ async deleteEmoji(emojiId) {
1756
+ await this.#rest.delete(Routes.guildEmoji(this.#guildId, emojiId));
1757
+ this.delete(emojiId);
1758
+ }
1759
+ upsert(data) {
1760
+ const key = data.id != null ? data.id : `unicode:${data.name ?? ""}`;
1761
+ const existing = this.get(key);
1762
+ const emoji = new Emoji(data);
1763
+ if (existing) {
1764
+ Object.assign(existing, emoji);
1765
+ return existing;
1766
+ }
1767
+ this.set(key, emoji);
1768
+ return emoji;
778
1769
  }
779
1770
  }
780
- var MessageCreateOptions = undefined;
781
- var MessageEditOptions = undefined;
782
- var MessageFetchOptions = undefined;
783
- var MessageThreadOptions = undefined;
784
- var ReactionFetchOptions = undefined;
785
1771
 
1772
+ // packages/managers/src/index.ts
786
1773
  class ChannelManager extends Manager {
787
1774
  #rest;
788
1775
  #context;
@@ -794,7 +1781,15 @@ class ChannelManager extends Manager {
794
1781
  sendMessage: (channelId, options) => this.send(channelId, options),
795
1782
  editMessage: (channelId, messageId, options) => this.editMessage(channelId, messageId, options),
796
1783
  deleteMessage: (channelId, messageId) => this.deleteMessage(channelId, messageId),
797
- crosspostMessage: (channelId, messageId) => this.crosspostMessage(channelId, messageId)
1784
+ crosspostMessage: (channelId, messageId) => this.crosspostMessage(channelId, messageId),
1785
+ editChannel: (channelId, options) => this.edit(channelId, options),
1786
+ deleteChannel: (channelId) => this.deleteChannel(channelId),
1787
+ addReaction: (channelId, messageId, emoji) => this.addReaction(channelId, messageId, emoji),
1788
+ removeOwnReaction: (channelId, messageId, emoji) => this.removeOwnReaction(channelId, messageId, emoji),
1789
+ removeReaction: (channelId, messageId, emoji, userId) => this.removeReaction(channelId, messageId, emoji, userId),
1790
+ removeAllReactions: (channelId, messageId) => this.removeAllReactions(channelId, messageId),
1791
+ pinMessage: (channelId, messageId) => this.pinMessage(channelId, messageId),
1792
+ unpinMessage: (channelId, messageId) => this.unpinMessage(channelId, messageId)
798
1793
  };
799
1794
  }
800
1795
  messages(channelId) {
@@ -809,8 +1804,7 @@ class ChannelManager extends Manager {
809
1804
  return new ThreadManager(this.#rest, this.#context, channelId);
810
1805
  }
811
1806
  async fetch(channelId) {
812
- const data = await this.#rest.get(Routes.channel(channelId));
813
- return this.upsert(data);
1807
+ return this.upsert(await this.#rest.get(Routes.channel(channelId)));
814
1808
  }
815
1809
  async resolve(channelId) {
816
1810
  return this.get(channelId) ?? this.fetch(channelId);
@@ -828,6 +1822,20 @@ class ChannelManager extends Manager {
828
1822
  update(channel) {
829
1823
  return this.set(channel.id, channel);
830
1824
  }
1825
+ async create(guildId, options) {
1826
+ return this.upsert(await this.#rest.post(Routes.guildChannels(guildId), options));
1827
+ }
1828
+ async edit(channelId, options) {
1829
+ return this.upsert(await this.#rest.patch(Routes.channel(channelId), options));
1830
+ }
1831
+ async deleteChannel(channelId) {
1832
+ await this.#rest.delete(Routes.channel(channelId));
1833
+ this.delete(channelId);
1834
+ }
1835
+ delete(channelId) {
1836
+ this.#messageManagers.delete(channelId);
1837
+ return super.delete(channelId);
1838
+ }
831
1839
  send(channelId, options) {
832
1840
  return this.messages(channelId).send(options);
833
1841
  }
@@ -857,8 +1865,7 @@ class ChannelManager extends Manager {
857
1865
  return this.messages(data.channel_id).upsert(data);
858
1866
  }
859
1867
  async editMessage(channelId, messageId, options) {
860
- const data = await this.#rest.patch(Routes.message(channelId, messageId), options);
861
- return this.messages(channelId).upsert(data);
1868
+ return this.messages(channelId).upsert(await this.#rest.patch(Routes.message(channelId, messageId), options));
862
1869
  }
863
1870
  async deleteMessage(channelId, messageId) {
864
1871
  await this.#rest.delete(Routes.message(channelId, messageId));
@@ -868,11 +1875,12 @@ class ChannelManager extends Manager {
868
1875
  return this.messages(channelId).delete(messageId);
869
1876
  }
870
1877
  async crosspostMessage(channelId, messageId) {
871
- const data = await this.#rest.post(Routes.crosspostMessage(channelId, messageId));
872
- return this.messages(channelId).upsert(data);
1878
+ return this.messages(channelId).upsert(await this.#rest.post(Routes.crosspostMessage(channelId, messageId)));
873
1879
  }
874
1880
  async bulkDeleteMessages(channelId, messageIds) {
875
1881
  const ids = [...messageIds];
1882
+ if (ids.length < 2 || ids.length > 100)
1883
+ throw new RangeError("bulkDelete requires between 2 and 100 message IDs.");
876
1884
  await this.#rest.post(Routes.channelBulkDelete(channelId), {
877
1885
  messages: ids
878
1886
  });
@@ -880,7 +1888,7 @@ class ChannelManager extends Manager {
880
1888
  this.messages(channelId).delete(id);
881
1889
  }
882
1890
  async addReaction(channelId, messageId, emoji) {
883
- await this.#rest.put(Routes.messageReactions(channelId, messageId, emoji));
1891
+ await this.#rest.put(`${Routes.messageReactions(channelId, messageId, emoji)}/@me`);
884
1892
  }
885
1893
  async fetchReactions(channelId, messageId, emoji, options = {}) {
886
1894
  const params = new URLSearchParams;
@@ -893,7 +1901,7 @@ class ChannelManager extends Manager {
893
1901
  return data.map((user) => new User(user));
894
1902
  }
895
1903
  async removeOwnReaction(channelId, messageId, emoji) {
896
- await this.#rest.delete(Routes.messageReactions(channelId, messageId, emoji) + "/@me");
1904
+ await this.#rest.delete(`${Routes.messageReactions(channelId, messageId, emoji)}/@me`);
897
1905
  }
898
1906
  async removeReaction(channelId, messageId, emoji, userId) {
899
1907
  await this.#rest.delete(`${Routes.messageReactions(channelId, messageId, emoji)}/${userId}`);
@@ -914,9 +1922,21 @@ class ChannelManager extends Manager {
914
1922
  createThreadFromMessage(channelId, messageId, options) {
915
1923
  return this.threads(channelId).createFromMessage(messageId, options);
916
1924
  }
917
- delete(channelId) {
918
- this.#messageManagers.delete(channelId);
919
- return super.delete(channelId);
1925
+ async fetchPage(channelId, options = {}) {
1926
+ const limit = Math.min(100, Math.max(1, options.limit ?? 50));
1927
+ const messages = await this.fetchMessages(channelId, {
1928
+ ...options,
1929
+ limit
1930
+ });
1931
+ return {
1932
+ messages,
1933
+ before: messages[0]?.id,
1934
+ after: messages[messages.length - 1]?.id,
1935
+ hasMore: messages.length === limit
1936
+ };
1937
+ }
1938
+ async bulkDelete(channelId, messageIds) {
1939
+ return this.bulkDeleteMessages(channelId, messageIds);
920
1940
  }
921
1941
  clear() {
922
1942
  this.#messageManagers.clear();
@@ -928,20 +1948,17 @@ function isMessageQuery(value) {
928
1948
  }
929
1949
  export {
930
1950
  ApplicationCommandManager,
1951
+ AuditLogEvent,
931
1952
  ChannelManager,
1953
+ EmojiManager,
932
1954
  GuildManager,
933
1955
  GuildMemberManager,
934
1956
  Manager,
935
- MessageCreateOptions,
936
- MessageEditOptions,
937
- MessageFetchOptions,
938
1957
  MessageManager,
939
- MessageThreadOptions,
940
- ReactionFetchOptions,
941
1958
  ResourceManager,
942
1959
  RoleManager,
943
1960
  ThreadManager,
944
1961
  UserManager
945
1962
  };
946
1963
 
947
- //# debugId=B1F523C9C7EE890964756E2164756E21
1964
+ //# debugId=EA438691ADA8387364756E2164756E21