lunibee 0.1.6 → 0.1.8

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 (80) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +223 -223
  3. package/dist/builders/commands.d.ts +39 -0
  4. package/dist/builders/components.d.ts +37 -12
  5. package/dist/builders/embed.d.ts +3 -1
  6. package/dist/builders/index.d.ts +2 -2
  7. package/dist/builders/index.js +192 -29
  8. package/dist/builders/index.js.map +9 -7
  9. package/dist/collection/index.d.ts +30 -0
  10. package/dist/collection/index.js +79 -5
  11. package/dist/collection/index.js.map +4 -4
  12. package/dist/core/events.d.ts +88 -2
  13. package/dist/core/index.d.ts +46 -85
  14. package/dist/core/index.js +2395 -789
  15. package/dist/core/index.js.map +44 -22
  16. package/dist/core/permissions.d.ts +112 -53
  17. package/dist/formatters/index.d.ts +43 -3
  18. package/dist/formatters/index.js +64 -1
  19. package/dist/formatters/index.js.map +3 -3
  20. package/dist/handlers/index.js.map +2 -2
  21. package/dist/index.d.ts +2 -2
  22. package/dist/index.js +3783 -1009
  23. package/dist/index.js.map +63 -38
  24. package/dist/managers/emoji.d.ts +38 -0
  25. package/dist/managers/guild-resources.d.ts +109 -0
  26. package/dist/managers/guild.d.ts +117 -1
  27. package/dist/managers/index.d.ts +37 -1
  28. package/dist/managers/index.js +1125 -81
  29. package/dist/managers/index.js.map +25 -20
  30. package/dist/rest/decoder.d.ts +23 -0
  31. package/dist/rest/errors.d.ts +20 -0
  32. package/dist/rest/index.d.ts +119 -25
  33. package/dist/rest/index.js +676 -204
  34. package/dist/rest/index.js.map +14 -6
  35. package/dist/rest/limiter.d.ts +42 -0
  36. package/dist/rest/redis.d.ts +54 -0
  37. package/dist/rest/route.d.ts +31 -0
  38. package/dist/rest/routes.d.ts +24 -0
  39. package/dist/rest/scheduler.d.ts +42 -0
  40. package/dist/rest/store.d.ts +67 -0
  41. package/dist/rest/transport.d.ts +40 -0
  42. package/dist/rest/webhook.d.ts +2 -2
  43. package/dist/sharding/bus.d.ts +31 -0
  44. package/dist/sharding/cluster.d.ts +71 -0
  45. package/dist/sharding/index.d.ts +18 -2
  46. package/dist/sharding/index.js +1202 -317
  47. package/dist/sharding/index.js.map +18 -7
  48. package/dist/structures/audit-log.d.ts +26 -0
  49. package/dist/structures/base.d.ts +40 -0
  50. package/dist/structures/channels.d.ts +56 -0
  51. package/dist/structures/index.d.ts +30 -1
  52. package/dist/structures/index.js +963 -87
  53. package/dist/structures/index.js.map +17 -10
  54. package/dist/structures/interactions.d.ts +12 -52
  55. package/dist/structures/options.d.ts +55 -0
  56. package/dist/structures/resources.d.ts +194 -6
  57. package/dist/types/gateway-events.d.ts +132 -0
  58. package/dist/types/gateway.d.ts +181 -0
  59. package/dist/types/index.d.ts +78 -263
  60. package/dist/types/index.js +44 -2
  61. package/dist/types/index.js.map +5 -4
  62. package/dist/utils/index.js.map +2 -2
  63. package/dist/voice/index.d.ts +116 -0
  64. package/dist/voice/index.js +261 -10
  65. package/dist/voice/index.js.map +3 -3
  66. package/dist/ws/close-codes.d.ts +23 -0
  67. package/dist/ws/decoder.d.ts +58 -0
  68. package/dist/ws/heartbeat.d.ts +87 -0
  69. package/dist/ws/index.d.ts +24 -32
  70. package/dist/ws/index.js +920 -318
  71. package/dist/ws/index.js.map +15 -5
  72. package/dist/ws/opcodes.d.ts +14 -0
  73. package/dist/ws/protocol.d.ts +110 -0
  74. package/dist/ws/reconnect.d.ts +108 -0
  75. package/dist/ws/send-budget.d.ts +17 -0
  76. package/dist/ws/session.d.ts +100 -0
  77. package/dist/ws/state.d.ts +27 -0
  78. package/dist/ws/transport.d.ts +80 -0
  79. package/package.json +23 -22
  80. package/dist/structures/permissions.d.ts +0 -73
@@ -145,6 +145,75 @@ class Collection extends Map {
145
145
  }
146
146
  return result;
147
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
+ }
148
217
  }
149
218
 
150
219
  // packages/managers/src/base.ts
@@ -216,7 +285,7 @@ class ResourceManager extends Manager {
216
285
  // packages/rest/package.json
217
286
  var package_default = {
218
287
  name: "@lunibee/rest",
219
- version: "0.1.6",
288
+ version: "0.1.8",
220
289
  type: "module",
221
290
  module: "./src/index.ts",
222
291
  types: "./src/index.ts",
@@ -266,21 +335,44 @@ var Routes = {
266
335
  threadMembers: (threadId) => `/channels/${snowflake(threadId, "Thread ID")}/thread-members`,
267
336
  guildScheduledEvents: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/scheduled-events`,
268
337
  guildScheduledEvent: (guildId, eventId) => `/guilds/${snowflake(guildId, "Guild ID")}/scheduled-events/${snowflake(eventId, "Event ID")}`,
338
+ guildScheduledEventUsers: (guildId, eventId) => `/guilds/${snowflake(guildId, "Guild ID")}/scheduled-events/${snowflake(eventId, "Event ID")}/users`,
339
+ channelPermission: (channelId, overwriteId) => `/channels/${snowflake(channelId, "Channel ID")}/permissions/${snowflake(overwriteId, "Overwrite ID")}`,
269
340
  guildAutoModerationRules: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/auto-moderation/rules`,
270
341
  guildAutoModerationRule: (guildId, ruleId) => `/guilds/${snowflake(guildId, "Guild ID")}/auto-moderation/rules/${snowflake(ruleId, "Rule ID")}`,
271
342
  voiceRegions: () => "/voice/regions",
272
343
  gateway: () => "/gateway",
273
- gatewayBot: () => "/gateway/bot"
344
+ gatewayBot: () => "/gateway/bot",
345
+ guildAuditLog: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/audit-logs`,
346
+ guildMembers: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/members`,
347
+ guildWelcomeScreen: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/welcome-screen`,
348
+ guildOnboarding: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/onboarding`,
349
+ guildPrune: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/prune`,
350
+ stageInstances: () => "/stage-instances",
351
+ stageInstanceByChannel: (channelId) => `/stage-instances/${snowflake(channelId, "Channel ID")}`,
352
+ invite: (code) => `/invites/${encodeURIComponent(code)}`,
353
+ guildVanity: (guildId) => `/guilds/${snowflake(guildId, "Guild ID")}/vanity-url`,
354
+ guildEmoji: (guildId, emojiId) => emojiId ? `/guilds/${snowflake(guildId, "Guild ID")}/emojis/${snowflake(emojiId, "Emoji ID")}` : `/guilds/${snowflake(guildId, "Guild ID")}/emojis`,
355
+ applicationEmoji: (applicationId, emojiId) => emojiId ? `/applications/${snowflake(applicationId, "Application ID")}/emojis/${snowflake(emojiId, "Emoji ID")}` : `/applications/${snowflake(applicationId, "Application ID")}/emojis`
274
356
  };
275
357
  function snowflake(value, field) {
276
358
  if (!/^\d{1,20}$/.test(value))
277
359
  throw new TypeError(`${field} must be a valid Discord snowflake.`);
278
360
  return value;
279
361
  }
362
+
280
363
  // packages/rest/src/index.ts
281
364
  var LIBRARY_VERSION = package_default.version;
282
365
  var LIBRARY_URL = "https://github.com/Ekretos/lunibee";
283
366
  var USER_AGENT = `DiscordBot (${LIBRARY_URL}, ${package_default.version})`;
367
+ var REQUEST_DATA_KEYS = new Set([
368
+ "body",
369
+ "files",
370
+ "query",
371
+ "headers",
372
+ "reason",
373
+ "auth",
374
+ "signal"
375
+ ]);
284
376
 
285
377
  // packages/structures/src/base.ts
286
378
  class BaseStructure {
@@ -401,6 +493,18 @@ class Channel extends BaseStructure {
401
493
  update(options) {
402
494
  return this.edit(options);
403
495
  }
496
+ isThread() {
497
+ return this.type === 10 || this.type === 11 || this.type === 12;
498
+ }
499
+ isTextBased() {
500
+ return [0, 1, 2, 3, 5, 10, 11, 12, 13].includes(this.type);
501
+ }
502
+ isVoiceBased() {
503
+ return this.type === 2 || this.type === 13;
504
+ }
505
+ isDMBased() {
506
+ return this.type === 1 || this.type === 3;
507
+ }
404
508
  toString() {
405
509
  return `<#${this.id}>`;
406
510
  }
@@ -424,6 +528,13 @@ class Guild extends BaseStructure {
424
528
  vanityUrlCode;
425
529
  nsfwLevel;
426
530
  discoverySplash;
531
+ rulesChannelId;
532
+ systemChannelId;
533
+ systemChannelFlags;
534
+ maxMembers;
535
+ mfaLevel;
536
+ explicitContentFilter;
537
+ defaultMessageNotifications;
427
538
  constructor(data) {
428
539
  super(data.id);
429
540
  if (!data.name)
@@ -445,6 +556,14 @@ class Guild extends BaseStructure {
445
556
  this.vanityUrlCode = data.vanity_url_code ?? null;
446
557
  this.nsfwLevel = data.nsfw_level ?? 0;
447
558
  this.discoverySplash = data.discovery_splash ?? null;
559
+ const d = data;
560
+ this.rulesChannelId = d.rules_channel_id ?? null;
561
+ this.systemChannelId = d.system_channel_id ?? null;
562
+ this.systemChannelFlags = d.system_channel_flags ?? 0;
563
+ this.maxMembers = d.max_members ?? 0;
564
+ this.mfaLevel = d.mfa_level ?? 0;
565
+ this.explicitContentFilter = d.explicit_content_filter ?? 0;
566
+ this.defaultMessageNotifications = d.default_message_notifications ?? 0;
448
567
  }
449
568
  iconURL(options = {}) {
450
569
  if (!this.icon)
@@ -466,12 +585,27 @@ class Guild extends BaseStructure {
466
585
  return null;
467
586
  return cdnURL(`/discovery-splashes/${this.id}`, this.discoverySplash, options);
468
587
  }
588
+ widgetImageURL(style = "shield") {
589
+ return `https://discord.com/api/guilds/${this.id}/widget.png?style=${style}`;
590
+ }
469
591
  hasFeature(feature) {
470
592
  return this.features.includes(feature);
471
593
  }
472
594
  get isCommunity() {
473
595
  return this.hasFeature("COMMUNITY");
474
596
  }
597
+ get isPartnered() {
598
+ return this.hasFeature("PARTNERED");
599
+ }
600
+ get isVerified() {
601
+ return this.hasFeature("VERIFIED");
602
+ }
603
+ get isBoosted() {
604
+ return this.premiumSubscriptionCount > 0;
605
+ }
606
+ get boostLevel() {
607
+ return this.premiumTier;
608
+ }
475
609
  get hasVanityUrl() {
476
610
  return this.vanityUrlCode !== null;
477
611
  }
@@ -482,7 +616,58 @@ class Guild extends BaseStructure {
482
616
  return this.name;
483
617
  }
484
618
  }
485
- // packages/structures/src/permissions.ts
619
+ // packages/core/src/permissions.ts
620
+ var Permission = {
621
+ createInstantInvite: 1n << 0n,
622
+ kickMembers: 1n << 1n,
623
+ banMembers: 1n << 2n,
624
+ administrator: 1n << 3n,
625
+ manageChannels: 1n << 4n,
626
+ manageGuild: 1n << 5n,
627
+ addReactions: 1n << 6n,
628
+ viewAuditLog: 1n << 7n,
629
+ prioritySpeaker: 1n << 8n,
630
+ stream: 1n << 9n,
631
+ viewChannel: 1n << 10n,
632
+ sendMessages: 1n << 11n,
633
+ sendTTSMessages: 1n << 12n,
634
+ manageMessages: 1n << 13n,
635
+ embedLinks: 1n << 14n,
636
+ attachFiles: 1n << 15n,
637
+ readMessageHistory: 1n << 16n,
638
+ mentionEveryone: 1n << 17n,
639
+ useExternalEmojis: 1n << 18n,
640
+ viewGuildInsights: 1n << 19n,
641
+ connect: 1n << 20n,
642
+ speak: 1n << 21n,
643
+ muteMembers: 1n << 22n,
644
+ deafenMembers: 1n << 23n,
645
+ moveMembers: 1n << 24n,
646
+ useVAD: 1n << 25n,
647
+ changeNickname: 1n << 26n,
648
+ manageNicknames: 1n << 27n,
649
+ manageRoles: 1n << 28n,
650
+ manageWebhooks: 1n << 29n,
651
+ manageGuildExpressions: 1n << 30n,
652
+ useApplicationCommands: 1n << 31n,
653
+ requestToSpeak: 1n << 32n,
654
+ manageEvents: 1n << 33n,
655
+ manageThreads: 1n << 34n,
656
+ createPublicThreads: 1n << 35n,
657
+ createPrivateThreads: 1n << 36n,
658
+ useExternalStickers: 1n << 37n,
659
+ sendMessagesInThreads: 1n << 38n,
660
+ useEmbeddedActivities: 1n << 39n,
661
+ moderateMembers: 1n << 40n,
662
+ viewCreatorMonetizationAnalytics: 1n << 41n,
663
+ useSoundboard: 1n << 42n,
664
+ createGuildExpressions: 1n << 43n,
665
+ createEvents: 1n << 44n,
666
+ useExternalSounds: 1n << 45n,
667
+ sendVoiceMessages: 1n << 46n,
668
+ sendPolls: 1n << 49n,
669
+ useExternalApps: 1n << 50n
670
+ };
486
671
  var Permissions = {
487
672
  CreateInstantInvite: 1n << 0n,
488
673
  KickMembers: 1n << 1n,
@@ -534,6 +719,57 @@ var Permissions = {
534
719
  SendPolls: 1n << 49n,
535
720
  UseExternalApps: 1n << 50n
536
721
  };
722
+ var PermissionFlagsBits = {
723
+ CreateInstantInvite: 1n << 0n,
724
+ KickMembers: 1n << 1n,
725
+ BanMembers: 1n << 2n,
726
+ Administrator: 1n << 3n,
727
+ ManageChannels: 1n << 4n,
728
+ ManageGuild: 1n << 5n,
729
+ AddReactions: 1n << 6n,
730
+ ViewAuditLog: 1n << 7n,
731
+ PrioritySpeaker: 1n << 8n,
732
+ Stream: 1n << 9n,
733
+ ViewChannel: 1n << 10n,
734
+ SendMessages: 1n << 11n,
735
+ SendTTSMessages: 1n << 12n,
736
+ ManageMessages: 1n << 13n,
737
+ EmbedLinks: 1n << 14n,
738
+ AttachFiles: 1n << 15n,
739
+ ReadMessageHistory: 1n << 16n,
740
+ MentionEveryone: 1n << 17n,
741
+ UseExternalEmojis: 1n << 18n,
742
+ ViewGuildInsights: 1n << 19n,
743
+ Connect: 1n << 20n,
744
+ Speak: 1n << 21n,
745
+ MuteMembers: 1n << 22n,
746
+ DeafenMembers: 1n << 23n,
747
+ MoveMembers: 1n << 24n,
748
+ UseVAD: 1n << 25n,
749
+ ChangeNickname: 1n << 26n,
750
+ ManageNicknames: 1n << 27n,
751
+ ManageRoles: 1n << 28n,
752
+ ManageWebhooks: 1n << 29n,
753
+ ManageGuildExpressions: 1n << 30n,
754
+ UseApplicationCommands: 1n << 31n,
755
+ RequestToSpeak: 1n << 32n,
756
+ ManageEvents: 1n << 33n,
757
+ ManageThreads: 1n << 34n,
758
+ CreatePublicThreads: 1n << 35n,
759
+ CreatePrivateThreads: 1n << 36n,
760
+ UseExternalStickers: 1n << 37n,
761
+ SendMessagesInThreads: 1n << 38n,
762
+ UseEmbeddedActivities: 1n << 39n,
763
+ ModerateMembers: 1n << 40n,
764
+ ViewCreatorMonetizationAnalytics: 1n << 41n,
765
+ UseSoundboard: 1n << 42n,
766
+ CreateGuildExpressions: 1n << 43n,
767
+ CreateEvents: 1n << 44n,
768
+ UseExternalSounds: 1n << 45n,
769
+ SendVoiceMessages: 1n << 46n,
770
+ SendPolls: 1n << 49n,
771
+ UseExternalApps: 1n << 50n
772
+ };
537
773
 
538
774
  class PermissionSet {
539
775
  bitfield;
@@ -541,8 +777,9 @@ class PermissionSet {
541
777
  try {
542
778
  if (Array.isArray(value)) {
543
779
  let bit = 0n;
544
- for (const item of value)
780
+ for (const item of value) {
545
781
  bit |= this.#resolve(item);
782
+ }
546
783
  this.bitfield = bit;
547
784
  } else if (value instanceof PermissionSet) {
548
785
  this.bitfield = value.bitfield;
@@ -558,22 +795,195 @@ class PermissionSet {
558
795
  throw new TypeError("Permission bitfield must be a valid non-negative integer.", { cause: error });
559
796
  }
560
797
  }
798
+ get createInstantInvite() {
799
+ return (this.bitfield & Permission.createInstantInvite) === Permission.createInstantInvite;
800
+ }
801
+ get kickMembers() {
802
+ return (this.bitfield & Permission.kickMembers) === Permission.kickMembers;
803
+ }
804
+ get banMembers() {
805
+ return (this.bitfield & Permission.banMembers) === Permission.banMembers;
806
+ }
807
+ get administrator() {
808
+ return (this.bitfield & Permission.administrator) === Permission.administrator;
809
+ }
810
+ get manageChannels() {
811
+ return (this.bitfield & Permission.manageChannels) === Permission.manageChannels;
812
+ }
813
+ get manageGuild() {
814
+ return (this.bitfield & Permission.manageGuild) === Permission.manageGuild;
815
+ }
816
+ get addReactions() {
817
+ return (this.bitfield & Permission.addReactions) === Permission.addReactions;
818
+ }
819
+ get viewAuditLog() {
820
+ return (this.bitfield & Permission.viewAuditLog) === Permission.viewAuditLog;
821
+ }
822
+ get prioritySpeaker() {
823
+ return (this.bitfield & Permission.prioritySpeaker) === Permission.prioritySpeaker;
824
+ }
825
+ get stream() {
826
+ return (this.bitfield & Permission.stream) === Permission.stream;
827
+ }
828
+ get viewChannel() {
829
+ return (this.bitfield & Permission.viewChannel) === Permission.viewChannel;
830
+ }
831
+ get sendMessages() {
832
+ return (this.bitfield & Permission.sendMessages) === Permission.sendMessages;
833
+ }
834
+ get sendTTSMessages() {
835
+ return (this.bitfield & Permission.sendTTSMessages) === Permission.sendTTSMessages;
836
+ }
837
+ get manageMessages() {
838
+ return (this.bitfield & Permission.manageMessages) === Permission.manageMessages;
839
+ }
840
+ get embedLinks() {
841
+ return (this.bitfield & Permission.embedLinks) === Permission.embedLinks;
842
+ }
843
+ get attachFiles() {
844
+ return (this.bitfield & Permission.attachFiles) === Permission.attachFiles;
845
+ }
846
+ get readMessageHistory() {
847
+ return (this.bitfield & Permission.readMessageHistory) === Permission.readMessageHistory;
848
+ }
849
+ get mentionEveryone() {
850
+ return (this.bitfield & Permission.mentionEveryone) === Permission.mentionEveryone;
851
+ }
852
+ get useExternalEmojis() {
853
+ return (this.bitfield & Permission.useExternalEmojis) === Permission.useExternalEmojis;
854
+ }
855
+ get viewGuildInsights() {
856
+ return (this.bitfield & Permission.viewGuildInsights) === Permission.viewGuildInsights;
857
+ }
858
+ get connect() {
859
+ return (this.bitfield & Permission.connect) === Permission.connect;
860
+ }
861
+ get speak() {
862
+ return (this.bitfield & Permission.speak) === Permission.speak;
863
+ }
864
+ get muteMembers() {
865
+ return (this.bitfield & Permission.muteMembers) === Permission.muteMembers;
866
+ }
867
+ get deafenMembers() {
868
+ return (this.bitfield & Permission.deafenMembers) === Permission.deafenMembers;
869
+ }
870
+ get moveMembers() {
871
+ return (this.bitfield & Permission.moveMembers) === Permission.moveMembers;
872
+ }
873
+ get useVAD() {
874
+ return (this.bitfield & Permission.useVAD) === Permission.useVAD;
875
+ }
876
+ get changeNickname() {
877
+ return (this.bitfield & Permission.changeNickname) === Permission.changeNickname;
878
+ }
879
+ get manageNicknames() {
880
+ return (this.bitfield & Permission.manageNicknames) === Permission.manageNicknames;
881
+ }
882
+ get manageRoles() {
883
+ return (this.bitfield & Permission.manageRoles) === Permission.manageRoles;
884
+ }
885
+ get manageWebhooks() {
886
+ return (this.bitfield & Permission.manageWebhooks) === Permission.manageWebhooks;
887
+ }
888
+ get manageGuildExpressions() {
889
+ return (this.bitfield & Permission.manageGuildExpressions) === Permission.manageGuildExpressions;
890
+ }
891
+ get useApplicationCommands() {
892
+ return (this.bitfield & Permission.useApplicationCommands) === Permission.useApplicationCommands;
893
+ }
894
+ get requestToSpeak() {
895
+ return (this.bitfield & Permission.requestToSpeak) === Permission.requestToSpeak;
896
+ }
897
+ get manageEvents() {
898
+ return (this.bitfield & Permission.manageEvents) === Permission.manageEvents;
899
+ }
900
+ get manageThreads() {
901
+ return (this.bitfield & Permission.manageThreads) === Permission.manageThreads;
902
+ }
903
+ get createPublicThreads() {
904
+ return (this.bitfield & Permission.createPublicThreads) === Permission.createPublicThreads;
905
+ }
906
+ get createPrivateThreads() {
907
+ return (this.bitfield & Permission.createPrivateThreads) === Permission.createPrivateThreads;
908
+ }
909
+ get useExternalStickers() {
910
+ return (this.bitfield & Permission.useExternalStickers) === Permission.useExternalStickers;
911
+ }
912
+ get sendMessagesInThreads() {
913
+ return (this.bitfield & Permission.sendMessagesInThreads) === Permission.sendMessagesInThreads;
914
+ }
915
+ get useEmbeddedActivities() {
916
+ return (this.bitfield & Permission.useEmbeddedActivities) === Permission.useEmbeddedActivities;
917
+ }
918
+ get moderateMembers() {
919
+ return (this.bitfield & Permission.moderateMembers) === Permission.moderateMembers;
920
+ }
921
+ get viewCreatorMonetizationAnalytics() {
922
+ return (this.bitfield & Permission.viewCreatorMonetizationAnalytics) === Permission.viewCreatorMonetizationAnalytics;
923
+ }
924
+ get useSoundboard() {
925
+ return (this.bitfield & Permission.useSoundboard) === Permission.useSoundboard;
926
+ }
927
+ get createGuildExpressions() {
928
+ return (this.bitfield & Permission.createGuildExpressions) === Permission.createGuildExpressions;
929
+ }
930
+ get createEvents() {
931
+ return (this.bitfield & Permission.createEvents) === Permission.createEvents;
932
+ }
933
+ get useExternalSounds() {
934
+ return (this.bitfield & Permission.useExternalSounds) === Permission.useExternalSounds;
935
+ }
936
+ get sendVoiceMessages() {
937
+ return (this.bitfield & Permission.sendVoiceMessages) === Permission.sendVoiceMessages;
938
+ }
939
+ get sendPolls() {
940
+ return (this.bitfield & Permission.sendPolls) === Permission.sendPolls;
941
+ }
942
+ get useExternalApps() {
943
+ return (this.bitfield & Permission.useExternalApps) === Permission.useExternalApps;
944
+ }
561
945
  has(...permissions) {
562
- return permissions.every((permission) => (this.bitfield & this.#resolve(permission)) === this.#resolve(permission));
946
+ if (permissions.length === 1) {
947
+ const p = permissions[0];
948
+ const bit = typeof p === "bigint" ? p : this.#resolve(p);
949
+ return (this.bitfield & bit) === bit;
950
+ }
951
+ for (let i = 0;i < permissions.length; i++) {
952
+ const p = permissions[i];
953
+ const bit = typeof p === "bigint" ? p : this.#resolve(p);
954
+ if ((this.bitfield & bit) !== bit)
955
+ return false;
956
+ }
957
+ return true;
563
958
  }
564
959
  any(...permissions) {
565
- return permissions.some((permission) => (this.bitfield & this.#resolve(permission)) !== 0n);
960
+ if (permissions.length === 1) {
961
+ const p = permissions[0];
962
+ const bit = typeof p === "bigint" ? p : this.#resolve(p);
963
+ return (this.bitfield & bit) !== 0n;
964
+ }
965
+ for (let i = 0;i < permissions.length; i++) {
966
+ const p = permissions[i];
967
+ const bit = typeof p === "bigint" ? p : this.#resolve(p);
968
+ if ((this.bitfield & bit) !== 0n)
969
+ return true;
970
+ }
971
+ return false;
566
972
  }
567
973
  add(...permissions) {
568
974
  let bitfield = this.bitfield;
569
- for (const permission of permissions)
570
- bitfield |= this.#resolve(permission);
975
+ for (let i = 0;i < permissions.length; i++) {
976
+ const p = permissions[i];
977
+ bitfield |= typeof p === "bigint" ? p : this.#resolve(p);
978
+ }
571
979
  return new PermissionSet(bitfield);
572
980
  }
573
981
  remove(...permissions) {
574
982
  let bitfield = this.bitfield;
575
- for (const permission of permissions)
576
- bitfield &= ~this.#resolve(permission);
983
+ for (let i = 0;i < permissions.length; i++) {
984
+ const p = permissions[i];
985
+ bitfield &= ~(typeof p === "bigint" ? p : this.#resolve(p));
986
+ }
577
987
  return new PermissionSet(bitfield);
578
988
  }
579
989
  equals(other) {
@@ -583,27 +993,31 @@ class PermissionSet {
583
993
  return this.bitfield.toString();
584
994
  }
585
995
  toArray() {
586
- return Object.keys(Permissions).filter((permission) => this.has(permission));
996
+ return Object.keys(Permission).filter((permission) => this.has(permission));
587
997
  }
588
998
  #resolve(permission) {
589
- if (permission instanceof PermissionSet)
590
- return permission.bitfield;
591
999
  if (typeof permission === "bigint")
592
1000
  return permission;
593
1001
  if (typeof permission === "number")
594
1002
  return BigInt(permission);
1003
+ if (permission instanceof PermissionSet)
1004
+ return permission.bitfield;
595
1005
  if (Array.isArray(permission)) {
596
1006
  let bit = 0n;
597
- for (const p of permission)
598
- bit |= this.#resolve(p);
1007
+ for (let i = 0;i < permission.length; i++)
1008
+ bit |= this.#resolve(permission[i]);
599
1009
  return bit;
600
1010
  }
601
1011
  if (typeof permission === "string") {
1012
+ if (permission in Permission)
1013
+ return Permission[permission];
602
1014
  if (permission in Permissions)
603
1015
  return Permissions[permission];
604
- const matchedKey = Object.keys(Permissions).find((k) => k.toLowerCase() === permission.toLowerCase());
605
- if (matchedKey)
606
- return Permissions[matchedKey];
1016
+ if (permission in PermissionFlagsBits)
1017
+ return PermissionFlagsBits[permission];
1018
+ const lower = permission.charAt(0).toLowerCase() + permission.slice(1);
1019
+ if (lower in Permission)
1020
+ return Permission[lower];
607
1021
  return BigInt(permission);
608
1022
  }
609
1023
  return 0n;
@@ -611,12 +1025,103 @@ class PermissionSet {
611
1025
  }
612
1026
 
613
1027
  class PermissionsBitField extends PermissionSet {
1028
+ static Flags = PermissionFlagsBits;
1029
+ static All = Permission;
614
1030
  constructor(value = 0n) {
615
1031
  super(value);
616
1032
  }
617
1033
  }
1034
+ // packages/types/src/gateway.ts
1035
+ var GatewayIntentBits = {
1036
+ Guilds: 1 << 0,
1037
+ GuildMembers: 1 << 1,
1038
+ GuildModeration: 1 << 2,
1039
+ GuildExpressions: 1 << 3,
1040
+ GuildIntegrations: 1 << 4,
1041
+ GuildWebhooks: 1 << 5,
1042
+ GuildInvites: 1 << 6,
1043
+ GuildVoiceStates: 1 << 7,
1044
+ GuildPresences: 1 << 8,
1045
+ GuildMessages: 1 << 9,
1046
+ GuildMessageReactions: 1 << 10,
1047
+ GuildMessageTyping: 1 << 11,
1048
+ DirectMessages: 1 << 12,
1049
+ DirectMessageReactions: 1 << 13,
1050
+ DirectMessageTyping: 1 << 14,
1051
+ MessageContent: 1 << 15,
1052
+ GuildScheduledEvents: 1 << 16,
1053
+ AutoModerationConfiguration: 1 << 20,
1054
+ AutoModerationExecution: 1 << 21,
1055
+ GuildMessagePolls: 1 << 24,
1056
+ DirectMessagePolls: 1 << 25
1057
+ };
1058
+ var IntentBits = {
1059
+ guild: 1 << 0,
1060
+ guilds: 1 << 0,
1061
+ guildMembers: 1 << 1,
1062
+ guildModeration: 1 << 2,
1063
+ guildBans: 1 << 2,
1064
+ guildExpressions: 1 << 3,
1065
+ guildEmojis: 1 << 3,
1066
+ guildEmojisAndStickers: 1 << 3,
1067
+ guildIntegrations: 1 << 4,
1068
+ guildWebhooks: 1 << 5,
1069
+ guildInvites: 1 << 6,
1070
+ guildVoiceStates: 1 << 7,
1071
+ guildPresences: 1 << 8,
1072
+ guildMessages: 1 << 9,
1073
+ guildMessage: 1 << 9,
1074
+ guildMessageReactions: 1 << 10,
1075
+ guildMessageTyping: 1 << 11,
1076
+ directMessages: 1 << 12,
1077
+ directMessageReactions: 1 << 13,
1078
+ directMessageTyping: 1 << 14,
1079
+ messageContent: 1 << 15,
1080
+ guildScheduledEvents: 1 << 16,
1081
+ autoModerationConfiguration: 1 << 20,
1082
+ autoModerationExecution: 1 << 21,
1083
+ guildMessagePolls: 1 << 24,
1084
+ directMessagePolls: 1 << 25
1085
+ };
1086
+ // packages/ws/src/close-codes.ts
1087
+ var GatewayCloseCodes = {
1088
+ UnknownError: 4000,
1089
+ UnknownOpcode: 4001,
1090
+ DecodeError: 4002,
1091
+ NotAuthenticated: 4003,
1092
+ AuthenticationFailed: 4004,
1093
+ AlreadyAuthenticated: 4005,
1094
+ InvalidSeq: 4007,
1095
+ RateLimited: 4008,
1096
+ SessionTimedOut: 4009,
1097
+ InvalidShard: 4010,
1098
+ ShardingRequired: 4011,
1099
+ InvalidAPIVersion: 4012,
1100
+ InvalidIntents: 4013,
1101
+ DisallowedIntents: 4014
1102
+ };
618
1103
 
1104
+ // packages/ws/src/reconnect.ts
1105
+ var FATAL_CLOSE_CODES = [
1106
+ GatewayCloseCodes.AuthenticationFailed,
1107
+ GatewayCloseCodes.InvalidShard,
1108
+ GatewayCloseCodes.ShardingRequired,
1109
+ GatewayCloseCodes.InvalidAPIVersion,
1110
+ GatewayCloseCodes.InvalidIntents,
1111
+ GatewayCloseCodes.DisallowedIntents
1112
+ ];
1113
+ var IDENTIFY_CLOSE_CODES = [
1114
+ GatewayCloseCodes.InvalidSeq,
1115
+ GatewayCloseCodes.SessionTimedOut
1116
+ ];
619
1117
  // packages/structures/src/resources.ts
1118
+ function toDateOrNull(value) {
1119
+ if (!value)
1120
+ return null;
1121
+ const date = new Date(value);
1122
+ return Number.isNaN(date.getTime()) ? null : date;
1123
+ }
1124
+
620
1125
  class GuildMember {
621
1126
  user;
622
1127
  guildId;
@@ -625,6 +1130,10 @@ class GuildMember {
625
1130
  pending;
626
1131
  joinedAt;
627
1132
  permissions;
1133
+ avatarHash;
1134
+ premiumSince;
1135
+ timedOutUntil;
1136
+ flags;
628
1137
  constructor(data) {
629
1138
  this.user = new User(data.user);
630
1139
  if (!/^\d{1,20}$/.test(data.guild_id))
@@ -637,10 +1146,25 @@ class GuildMember {
637
1146
  if (this.joinedAt?.toString() === "Invalid Date")
638
1147
  throw new RangeError("Member joined_at must be a valid date.");
639
1148
  this.permissions = new PermissionsBitField(data.permissions ?? 0n);
1149
+ this.avatarHash = data.avatar ?? null;
1150
+ this.premiumSince = toDateOrNull(data.premium_since);
1151
+ this.timedOutUntil = toDateOrNull(data.communication_disabled_until);
1152
+ this.flags = data.flags ?? 0;
640
1153
  }
641
1154
  get displayName() {
642
1155
  return this.nickname ?? this.user.displayName;
643
1156
  }
1157
+ get isTimedOut() {
1158
+ return this.timedOutUntil !== null && this.timedOutUntil > new Date;
1159
+ }
1160
+ avatarURL(options = {}) {
1161
+ if (this.avatarHash)
1162
+ return cdnURL(`/guilds/${this.guildId}/users/${this.user.id}/avatars`, this.avatarHash, options);
1163
+ return this.user.avatarURL(options);
1164
+ }
1165
+ displayAvatarURL(options = {}) {
1166
+ return this.avatarURL(options) ?? this.user.displayAvatarURL(options);
1167
+ }
644
1168
  toString() {
645
1169
  return this.user.toString();
646
1170
  }
@@ -653,6 +1177,10 @@ class Role extends BaseStructure {
653
1177
  permissions;
654
1178
  managed;
655
1179
  mentionable;
1180
+ position;
1181
+ unicodeEmoji;
1182
+ iconHash;
1183
+ tags;
656
1184
  constructor(data) {
657
1185
  super(data.id);
658
1186
  if (!data.name)
@@ -663,64 +1191,212 @@ class Role extends BaseStructure {
663
1191
  this.permissions = new PermissionsBitField(data.permissions ?? 0n);
664
1192
  this.managed = data.managed ?? false;
665
1193
  this.mentionable = data.mentionable ?? false;
1194
+ this.position = data.position ?? 0;
1195
+ this.unicodeEmoji = data.unicode_emoji ?? null;
1196
+ this.iconHash = data.icon ?? null;
1197
+ this.tags = data.tags ?? null;
1198
+ }
1199
+ get colorHex() {
1200
+ return `#${this.color.toString(16).padStart(6, "0").toUpperCase()}`;
1201
+ }
1202
+ iconURL(options = {}) {
1203
+ if (!this.iconHash)
1204
+ return null;
1205
+ return cdnURL(`/role-icons/${this.id}`, this.iconHash, options);
1206
+ }
1207
+ isEveryone(guildId) {
1208
+ return this.id === guildId;
666
1209
  }
667
1210
  toString() {
668
1211
  return `<@&${this.id}>`;
669
1212
  }
670
1213
  }
671
- // packages/types/src/index.ts
672
- var GatewayIntentBits = {
673
- Guilds: 1 << 0,
674
- GuildMembers: 1 << 1,
675
- GuildModeration: 1 << 2,
676
- GuildExpressions: 1 << 3,
677
- GuildIntegrations: 1 << 4,
678
- GuildWebhooks: 1 << 5,
679
- GuildInvites: 1 << 6,
680
- GuildVoiceStates: 1 << 7,
681
- GuildPresences: 1 << 8,
682
- GuildMessages: 1 << 9,
683
- GuildMessageReactions: 1 << 10,
684
- GuildMessageTyping: 1 << 11,
685
- DirectMessages: 1 << 12,
686
- DirectMessageReactions: 1 << 13,
687
- DirectMessageTyping: 1 << 14,
688
- MessageContent: 1 << 15,
689
- GuildScheduledEvents: 1 << 16,
690
- AutoModerationConfiguration: 1 << 20,
691
- AutoModerationExecution: 1 << 21,
692
- GuildMessagePolls: 1 << 24,
693
- DirectMessagePolls: 1 << 25
694
- };
695
- var IntentBits = {
696
- guild: 1 << 0,
697
- guilds: 1 << 0,
698
- guildMembers: 1 << 1,
699
- guildModeration: 1 << 2,
700
- guildBans: 1 << 2,
701
- guildExpressions: 1 << 3,
702
- guildEmojis: 1 << 3,
703
- guildEmojisAndStickers: 1 << 3,
704
- guildIntegrations: 1 << 4,
705
- guildWebhooks: 1 << 5,
706
- guildInvites: 1 << 6,
707
- guildVoiceStates: 1 << 7,
708
- guildPresences: 1 << 8,
709
- guildMessages: 1 << 9,
710
- guildMessage: 1 << 9,
711
- guildMessageReactions: 1 << 10,
712
- guildMessageTyping: 1 << 11,
713
- directMessages: 1 << 12,
714
- directMessageReactions: 1 << 13,
715
- directMessageTyping: 1 << 14,
716
- messageContent: 1 << 15,
717
- guildScheduledEvents: 1 << 16,
718
- autoModerationConfiguration: 1 << 20,
719
- autoModerationExecution: 1 << 21,
720
- guildMessagePolls: 1 << 24,
721
- directMessagePolls: 1 << 25
722
- };
1214
+
1215
+ class TextChannel extends Channel {
1216
+ constructor(data, context) {
1217
+ super(data, context);
1218
+ }
1219
+ toString() {
1220
+ return `<#${this.id}>`;
1221
+ }
1222
+ }
1223
+ class Emoji extends BaseStructure {
1224
+ name;
1225
+ roleIds;
1226
+ user;
1227
+ requireColons;
1228
+ managed;
1229
+ animated;
1230
+ available;
1231
+ constructor(data) {
1232
+ super(data.id ?? "0");
1233
+ if (data.id === null)
1234
+ this.id = "unicode";
1235
+ this.name = data.name;
1236
+ this.roleIds = data.roles ?? [];
1237
+ this.user = data.user ? new User(data.user) : null;
1238
+ this.requireColons = data.require_colons ?? false;
1239
+ this.managed = data.managed ?? false;
1240
+ this.animated = data.animated ?? false;
1241
+ this.available = data.available ?? true;
1242
+ }
1243
+ url(options = {}) {
1244
+ if (!this.id || this.id === "unicode")
1245
+ return null;
1246
+ const ext = options.extension ?? (this.animated ? "gif" : "png");
1247
+ const size = options.size ? `?size=${options.size}` : "";
1248
+ return `${CDN_BASE}/emojis/${this.id}.${ext}${size}`;
1249
+ }
1250
+ toString() {
1251
+ return this.id !== "unicode" ? `<${this.animated ? "a" : ""}:${this.name}:${this.id}>` : this.name ?? "";
1252
+ }
1253
+ }
1254
+
1255
+ class AutoModerationRule extends BaseStructure {
1256
+ guildId;
1257
+ name;
1258
+ creatorId;
1259
+ eventType;
1260
+ triggerType;
1261
+ triggerMetadata;
1262
+ actions;
1263
+ enabled;
1264
+ exemptRoles;
1265
+ exemptChannels;
1266
+ constructor(data) {
1267
+ super(data.id);
1268
+ if (!/^\d{1,20}$/.test(data.guild_id))
1269
+ throw new TypeError("AutoModerationRule guild_id must be a valid snowflake.");
1270
+ this.guildId = data.guild_id;
1271
+ this.name = data.name;
1272
+ this.creatorId = data.creator_id;
1273
+ this.eventType = data.event_type;
1274
+ this.triggerType = data.trigger_type;
1275
+ this.triggerMetadata = data.trigger_metadata;
1276
+ this.actions = data.actions;
1277
+ this.enabled = data.enabled;
1278
+ this.exemptRoles = data.exempt_roles;
1279
+ this.exemptChannels = data.exempt_channels;
1280
+ }
1281
+ toJSON() {
1282
+ return {
1283
+ id: this.id,
1284
+ guildId: this.guildId,
1285
+ name: this.name,
1286
+ creatorId: this.creatorId,
1287
+ eventType: this.eventType,
1288
+ triggerType: this.triggerType,
1289
+ triggerMetadata: this.triggerMetadata,
1290
+ actions: this.actions,
1291
+ enabled: this.enabled,
1292
+ exemptRoles: this.exemptRoles,
1293
+ exemptChannels: this.exemptChannels
1294
+ };
1295
+ }
1296
+ }
1297
+ // packages/structures/src/channels.ts
1298
+ class NewsChannel extends TextChannel {
1299
+ }
1300
+
1301
+ class DMChannel extends Channel {
1302
+ recipients;
1303
+ ownerId;
1304
+ constructor(data, context) {
1305
+ super(data, context);
1306
+ this.recipients = (data.recipients ?? []).map((u) => new User(u));
1307
+ this.ownerId = data.owner_id ?? null;
1308
+ }
1309
+ }
1310
+
1311
+ class VoiceChannel extends Channel {
1312
+ bitrate;
1313
+ userLimit;
1314
+ rtcRegion;
1315
+ videoQualityMode;
1316
+ constructor(data, context) {
1317
+ super(data, context);
1318
+ this.bitrate = data.bitrate ?? 64000;
1319
+ this.userLimit = data.user_limit ?? 0;
1320
+ this.rtcRegion = data.rtc_region ?? null;
1321
+ this.videoQualityMode = data.video_quality_mode ?? 1;
1322
+ }
1323
+ }
1324
+
1325
+ class StageChannel extends VoiceChannel {
1326
+ }
1327
+
1328
+ class CategoryChannel extends Channel {
1329
+ }
1330
+
1331
+ class ThreadChannel extends Channel {
1332
+ ownerId;
1333
+ messageCount;
1334
+ memberCount;
1335
+ metadata;
1336
+ constructor(data, context) {
1337
+ super(data, context);
1338
+ this.ownerId = data.owner_id ?? null;
1339
+ this.messageCount = data.message_count ?? 0;
1340
+ this.memberCount = data.member_count ?? 0;
1341
+ this.metadata = data.thread_metadata ?? null;
1342
+ }
1343
+ get archived() {
1344
+ return this.metadata?.archived ?? false;
1345
+ }
1346
+ get locked() {
1347
+ return this.metadata?.locked ?? false;
1348
+ }
1349
+ get autoArchiveDuration() {
1350
+ return this.metadata?.auto_archive_duration ?? null;
1351
+ }
1352
+ }
1353
+
1354
+ class ForumChannel extends Channel {
1355
+ availableTags;
1356
+ defaultReactionEmoji;
1357
+ defaultThreadRateLimitPerUser;
1358
+ defaultAutoArchiveDuration;
1359
+ constructor(data, context) {
1360
+ super(data, context);
1361
+ this.availableTags = data.available_tags ?? [];
1362
+ this.defaultReactionEmoji = data.default_reaction_emoji ?? null;
1363
+ this.defaultThreadRateLimitPerUser = data.default_thread_rate_limit_per_user ?? 0;
1364
+ this.defaultAutoArchiveDuration = data.default_auto_archive_duration ?? null;
1365
+ }
1366
+ }
1367
+
1368
+ class MediaChannel extends ForumChannel {
1369
+ }
1370
+ function createChannel(data, context) {
1371
+ switch (data.type) {
1372
+ case 0:
1373
+ return new TextChannel(data, context);
1374
+ case 1:
1375
+ case 3:
1376
+ return new DMChannel(data, context);
1377
+ case 2:
1378
+ return new VoiceChannel(data, context);
1379
+ case 4:
1380
+ return new CategoryChannel(data, context);
1381
+ case 5:
1382
+ return new NewsChannel(data, context);
1383
+ case 10:
1384
+ case 11:
1385
+ case 12:
1386
+ return new ThreadChannel(data, context);
1387
+ case 13:
1388
+ return new StageChannel(data, context);
1389
+ case 15:
1390
+ return new ForumChannel(data, context);
1391
+ case 16:
1392
+ return new MediaChannel(data, context);
1393
+ default:
1394
+ return new Channel(data, context);
1395
+ }
1396
+ }
723
1397
  // packages/structures/src/index.ts
1398
+ var NON_SYSTEM_MESSAGE_TYPES = new Set([0, 19, 20, 23]);
1399
+
724
1400
  class Message extends BaseStructure {
725
1401
  content;
726
1402
  author;
@@ -766,6 +1442,12 @@ class Message extends BaseStructure {
766
1442
  get embedsSuppressed() {
767
1443
  return (this.flags & 4) !== 0;
768
1444
  }
1445
+ get createdTimestamp() {
1446
+ return this.timestamp.getTime();
1447
+ }
1448
+ get createdAt() {
1449
+ return this.timestamp;
1450
+ }
769
1451
  edit(options) {
770
1452
  if (!this.#context)
771
1453
  throw new Error("This message is not attached to a client.");
@@ -820,6 +1502,51 @@ class Message extends BaseStructure {
820
1502
  throw new Error("This message is not attached to a client.");
821
1503
  return this.#context.unpinMessage(this.channelId, this.id);
822
1504
  }
1505
+ get isEphemeral() {
1506
+ return (this.flags & 64) !== 0;
1507
+ }
1508
+ get isPinned() {
1509
+ return this.pinned;
1510
+ }
1511
+ get isSystemMessage() {
1512
+ return !NON_SYSTEM_MESSAGE_TYPES.has(this.type);
1513
+ }
1514
+ get isCrosspost() {
1515
+ return (this.flags & 2) !== 0;
1516
+ }
1517
+ get hasAttachments() {
1518
+ return this.attachments.length > 0;
1519
+ }
1520
+ get hasEmbeds() {
1521
+ return this.embeds.length > 0;
1522
+ }
1523
+ get hasComponents() {
1524
+ return this.components.length > 0;
1525
+ }
1526
+ suppressEmbeds() {
1527
+ return this.edit({ flags: this.flags | 4 });
1528
+ }
1529
+ toJSON() {
1530
+ return {
1531
+ id: this.id,
1532
+ content: this.content,
1533
+ channelId: this.channelId,
1534
+ guildId: this.guildId,
1535
+ flags: this.flags,
1536
+ pinned: this.pinned,
1537
+ mentionEveryone: this.mentionEveryone,
1538
+ type: this.type,
1539
+ timestamp: this.timestamp.toISOString(),
1540
+ author: { id: this.author.id, username: this.author.username },
1541
+ attachments: [...this.attachments],
1542
+ embeds: [...this.embeds],
1543
+ components: [...this.components],
1544
+ mentions: this.mentions.map((u) => u.id),
1545
+ mentionRoles: [...this.mentionRoles],
1546
+ reference: this.reference,
1547
+ referencedMessage: this.referencedMessage ? this.referencedMessage.id : this.referencedMessage
1548
+ };
1549
+ }
823
1550
  }
824
1551
 
825
1552
  // packages/managers/src/message.ts
@@ -882,7 +1609,7 @@ class ThreadManager {
882
1609
  auto_archive_duration: options.autoArchiveDuration,
883
1610
  rate_limit_per_user: options.rateLimitPerUser
884
1611
  });
885
- return new Channel(data, this.#context);
1612
+ return createChannel(data, this.#context);
886
1613
  }
887
1614
  }
888
1615
 
@@ -910,13 +1637,173 @@ class UserManager extends ResourceManager {
910
1637
  });
911
1638
  }
912
1639
  }
1640
+ // packages/managers/src/guild-resources.ts
1641
+ function withQuery(path, params) {
1642
+ const query = new URLSearchParams;
1643
+ for (const [key, value] of Object.entries(params))
1644
+ if (value !== undefined)
1645
+ query.set(key, String(value));
1646
+ const suffix = query.toString();
1647
+ return suffix ? `${path}?${suffix}` : path;
1648
+ }
1649
+
1650
+ class GuildBanManager extends Manager {
1651
+ #rest;
1652
+ guildId;
1653
+ constructor(rest, guildId) {
1654
+ super();
1655
+ this.#rest = rest;
1656
+ this.guildId = guildId;
1657
+ }
1658
+ async fetch(userId) {
1659
+ const ban = await this.#rest.get(Routes.guildBan(this.guildId, userId));
1660
+ this.set(ban.user.id, ban);
1661
+ return ban;
1662
+ }
1663
+ async fetchAll(options = {}) {
1664
+ const limit = options.limit === undefined ? undefined : Math.min(1000, Math.max(1, options.limit));
1665
+ const bans = await this.#rest.get(withQuery(Routes.guildBans(this.guildId), {
1666
+ limit,
1667
+ before: options.before,
1668
+ after: options.after
1669
+ }));
1670
+ for (const ban of bans)
1671
+ this.set(ban.user.id, ban);
1672
+ return bans;
1673
+ }
1674
+ async create(userId, options = {}) {
1675
+ await this.#rest.put(Routes.guildBan(this.guildId, userId), { delete_message_seconds: options.deleteMessageSeconds }, { reason: options.reason });
1676
+ }
1677
+ async remove(userId, reason) {
1678
+ await this.#rest.delete(Routes.guildBan(this.guildId, userId), {
1679
+ reason
1680
+ });
1681
+ this.delete(userId);
1682
+ }
1683
+ }
1684
+
1685
+ class GuildScheduledEventManager extends Manager {
1686
+ #rest;
1687
+ guildId;
1688
+ constructor(rest, guildId) {
1689
+ super();
1690
+ this.#rest = rest;
1691
+ this.guildId = guildId;
1692
+ }
1693
+ #store(event) {
1694
+ this.set(event.id, event);
1695
+ return event;
1696
+ }
1697
+ async fetch(eventId, options = {}) {
1698
+ return this.#store(await this.#rest.get(withQuery(Routes.guildScheduledEvent(this.guildId, eventId), {
1699
+ with_user_count: options.withUserCount
1700
+ })));
1701
+ }
1702
+ async fetchAll(options = {}) {
1703
+ const events = await this.#rest.get(withQuery(Routes.guildScheduledEvents(this.guildId), {
1704
+ with_user_count: options.withUserCount
1705
+ }));
1706
+ return events.map((event) => this.#store(event));
1707
+ }
1708
+ async create(options, reason) {
1709
+ return this.#store(await this.#rest.post(Routes.guildScheduledEvents(this.guildId), options, { reason }));
1710
+ }
1711
+ async edit(eventId, options, reason) {
1712
+ return this.#store(await this.#rest.patch(Routes.guildScheduledEvent(this.guildId, eventId), options, { reason }));
1713
+ }
1714
+ async remove(eventId) {
1715
+ await this.#rest.delete(Routes.guildScheduledEvent(this.guildId, eventId));
1716
+ this.delete(eventId);
1717
+ }
1718
+ async fetchSubscribers(eventId, options = {}) {
1719
+ const limit = options.limit === undefined ? undefined : Math.min(100, Math.max(1, options.limit));
1720
+ return this.#rest.get(withQuery(Routes.guildScheduledEventUsers(this.guildId, eventId), {
1721
+ limit,
1722
+ with_member: options.withMember,
1723
+ before: options.before,
1724
+ after: options.after
1725
+ }));
1726
+ }
1727
+ }
1728
+
1729
+ class StageInstanceManager extends Manager {
1730
+ #rest;
1731
+ constructor(rest) {
1732
+ super();
1733
+ this.#rest = rest;
1734
+ }
1735
+ #store(stage) {
1736
+ this.set(stage.channel_id, stage);
1737
+ return stage;
1738
+ }
1739
+ async create(channelId, options, reason) {
1740
+ return this.#store(await this.#rest.post(Routes.stageInstances(), {
1741
+ channel_id: channelId,
1742
+ topic: options.topic,
1743
+ privacy_level: options.privacyLevel,
1744
+ send_start_notification: options.sendStartNotification,
1745
+ guild_scheduled_event_id: options.guildScheduledEventId
1746
+ }, { reason }));
1747
+ }
1748
+ async fetch(channelId) {
1749
+ return this.#store(await this.#rest.get(Routes.stageInstanceByChannel(channelId)));
1750
+ }
1751
+ async edit(channelId, options, reason) {
1752
+ return this.#store(await this.#rest.patch(Routes.stageInstanceByChannel(channelId), { topic: options.topic, privacy_level: options.privacyLevel }, { reason }));
1753
+ }
1754
+ async remove(channelId, reason) {
1755
+ await this.#rest.delete(Routes.stageInstanceByChannel(channelId), {
1756
+ reason
1757
+ });
1758
+ this.delete(channelId);
1759
+ }
1760
+ }
1761
+
1762
+ class PermissionOverwriteManager {
1763
+ #rest;
1764
+ channelId;
1765
+ constructor(rest, channelId) {
1766
+ this.#rest = rest;
1767
+ this.channelId = channelId;
1768
+ }
1769
+ async edit(overwriteId, options, reason) {
1770
+ await this.#rest.put(Routes.channelPermission(this.channelId, overwriteId), {
1771
+ type: options.type,
1772
+ allow: BigInt(options.allow ?? 0).toString(),
1773
+ deny: BigInt(options.deny ?? 0).toString()
1774
+ }, { reason });
1775
+ }
1776
+ async remove(overwriteId, reason) {
1777
+ await this.#rest.delete(Routes.channelPermission(this.channelId, overwriteId), { reason });
1778
+ }
1779
+ }
1780
+
913
1781
  // packages/managers/src/guild.ts
1782
+ function withQuery2(path, params) {
1783
+ const suffix = params.toString();
1784
+ return suffix ? `${path}?${suffix}` : path;
1785
+ }
1786
+
914
1787
  class GuildManager extends ResourceManager {
915
1788
  #rest;
1789
+ #bans = new Map;
1790
+ #scheduledEvents = new Map;
916
1791
  constructor(rest) {
917
1792
  super(async (id) => new Guild(await rest.get(Routes.guild(id))), (guild) => guild.id);
918
1793
  this.#rest = rest;
919
1794
  }
1795
+ bans(guildId) {
1796
+ let manager = this.#bans.get(guildId);
1797
+ if (!manager)
1798
+ this.#bans.set(guildId, manager = new GuildBanManager(this.#rest, guildId));
1799
+ return manager;
1800
+ }
1801
+ scheduledEvents(guildId) {
1802
+ let manager = this.#scheduledEvents.get(guildId);
1803
+ if (!manager)
1804
+ this.#scheduledEvents.set(guildId, manager = new GuildScheduledEventManager(this.#rest, guildId));
1805
+ return manager;
1806
+ }
920
1807
  async create(options) {
921
1808
  const data = await this.#rest.post("/guilds", options);
922
1809
  return this.upsert(new Guild(data));
@@ -940,7 +1827,101 @@ class GuildManager extends ResourceManager {
940
1827
  async fetchInvites(id) {
941
1828
  return this.#rest.get(Routes.guildInvites(id));
942
1829
  }
1830
+ async fetchAuditLog(guildId, options = {}) {
1831
+ const params = new URLSearchParams;
1832
+ if (options.userId)
1833
+ params.set("user_id", options.userId);
1834
+ if (options.actionType !== undefined)
1835
+ params.set("action_type", String(options.actionType));
1836
+ if (options.before)
1837
+ params.set("before", options.before);
1838
+ if (options.after)
1839
+ params.set("after", options.after);
1840
+ if (options.limit !== undefined)
1841
+ params.set("limit", String(Math.min(100, Math.max(1, options.limit))));
1842
+ return this.#rest.get(withQuery2(Routes.guildAuditLog(guildId), params));
1843
+ }
1844
+ async fetchMembers(guildId, options = {}) {
1845
+ const params = new URLSearchParams;
1846
+ if (options.limit !== undefined)
1847
+ params.set("limit", String(Math.min(1000, Math.max(1, options.limit))));
1848
+ if (options.after)
1849
+ params.set("after", options.after);
1850
+ return this.#rest.get(withQuery2(Routes.guildMembers(guildId), params));
1851
+ }
1852
+ async fetchAutoModerationRules(guildId) {
1853
+ const rules = await this.#rest.get(Routes.guildAutoModerationRules(guildId));
1854
+ return rules.map((r) => new AutoModerationRule(r));
1855
+ }
1856
+ async fetchAutoModerationRule(guildId, ruleId) {
1857
+ const rule = await this.#rest.get(Routes.guildAutoModerationRule(guildId, ruleId));
1858
+ return new AutoModerationRule(rule);
1859
+ }
1860
+ async createAutoModerationRule(guildId, options) {
1861
+ const rule = await this.#rest.post(Routes.guildAutoModerationRules(guildId), options);
1862
+ return new AutoModerationRule(rule);
1863
+ }
1864
+ async editAutoModerationRule(guildId, ruleId, options) {
1865
+ const rule = await this.#rest.patch(Routes.guildAutoModerationRule(guildId, ruleId), options);
1866
+ return new AutoModerationRule(rule);
1867
+ }
1868
+ async deleteAutoModerationRule(guildId, ruleId) {
1869
+ await this.#rest.delete(Routes.guildAutoModerationRule(guildId, ruleId));
1870
+ }
943
1871
  }
1872
+ var AuditLogEvent = {
1873
+ GuildUpdate: 1,
1874
+ ChannelCreate: 10,
1875
+ ChannelUpdate: 11,
1876
+ ChannelDelete: 12,
1877
+ ChannelOverwriteCreate: 13,
1878
+ ChannelOverwriteUpdate: 14,
1879
+ ChannelOverwriteDelete: 15,
1880
+ MemberKick: 20,
1881
+ MemberPrune: 21,
1882
+ MemberBanAdd: 22,
1883
+ MemberBanRemove: 23,
1884
+ MemberUpdate: 24,
1885
+ MemberRoleUpdate: 25,
1886
+ MemberMove: 26,
1887
+ MemberDisconnect: 27,
1888
+ BotAdd: 28,
1889
+ RoleCreate: 30,
1890
+ RoleUpdate: 31,
1891
+ RoleDelete: 32,
1892
+ InviteCreate: 40,
1893
+ InviteUpdate: 41,
1894
+ InviteDelete: 42,
1895
+ WebhookCreate: 50,
1896
+ WebhookUpdate: 51,
1897
+ WebhookDelete: 52,
1898
+ EmojiCreate: 60,
1899
+ EmojiUpdate: 61,
1900
+ EmojiDelete: 62,
1901
+ MessageDelete: 72,
1902
+ MessageBulkDelete: 73,
1903
+ MessagePin: 74,
1904
+ MessageUnpin: 75,
1905
+ IntegrationCreate: 80,
1906
+ IntegrationUpdate: 81,
1907
+ IntegrationDelete: 82,
1908
+ StageInstanceCreate: 83,
1909
+ StageInstanceUpdate: 84,
1910
+ StageInstanceDelete: 85,
1911
+ StickerCreate: 90,
1912
+ StickerUpdate: 91,
1913
+ StickerDelete: 92,
1914
+ ScheduledEventCreate: 100,
1915
+ ScheduledEventUpdate: 101,
1916
+ ScheduledEventDelete: 102,
1917
+ ThreadCreate: 110,
1918
+ ThreadUpdate: 111,
1919
+ ThreadDelete: 112,
1920
+ AutoModerationRuleCreate: 140,
1921
+ AutoModerationRuleUpdate: 141,
1922
+ AutoModerationRuleDelete: 142,
1923
+ AutoModerationBlockMessage: 143
1924
+ };
944
1925
  // packages/managers/src/role.ts
945
1926
  class RoleManager extends ResourceManager {
946
1927
  #rest;
@@ -997,9 +1978,7 @@ class GuildMemberManager extends ResourceManager {
997
1978
  this.delete(userId);
998
1979
  }
999
1980
  async ban(userId, options = {}) {
1000
- await this.#rest.put(Routes.guildBan(this.guildId, userId), {
1001
- delete_message_seconds: options.deleteMessageSeconds
1002
- });
1981
+ await this.#rest.put(Routes.guildBan(this.guildId, userId), { delete_message_seconds: options.deleteMessageSeconds }, { reason: options.reason });
1003
1982
  this.delete(userId);
1004
1983
  }
1005
1984
  async unban(userId) {
@@ -1061,6 +2040,44 @@ class ApplicationCommandManager {
1061
2040
  await this.#rest.delete(Routes.guildApplicationCommand(this.#applicationId, guildId, commandId));
1062
2041
  }
1063
2042
  }
2043
+ // packages/managers/src/emoji.ts
2044
+ class EmojiManager extends Manager {
2045
+ #rest;
2046
+ #guildId;
2047
+ constructor(rest, guildId) {
2048
+ super();
2049
+ this.#rest = rest;
2050
+ this.#guildId = guildId;
2051
+ }
2052
+ async fetch(emojiId) {
2053
+ return this.upsert(await this.#rest.get(Routes.guildEmoji(this.#guildId, emojiId)));
2054
+ }
2055
+ async fetchAll() {
2056
+ const data = await this.#rest.get(Routes.guildEmoji(this.#guildId));
2057
+ return data.map((item) => this.upsert(item));
2058
+ }
2059
+ async create(options) {
2060
+ return this.upsert(await this.#rest.post(Routes.guildEmoji(this.#guildId), options));
2061
+ }
2062
+ async edit(emojiId, options) {
2063
+ return this.upsert(await this.#rest.patch(Routes.guildEmoji(this.#guildId, emojiId), options));
2064
+ }
2065
+ async deleteEmoji(emojiId) {
2066
+ await this.#rest.delete(Routes.guildEmoji(this.#guildId, emojiId));
2067
+ this.delete(emojiId);
2068
+ }
2069
+ upsert(data) {
2070
+ const key = data.id != null ? data.id : `unicode:${data.name ?? ""}`;
2071
+ const existing = this.get(key);
2072
+ const emoji = new Emoji(data);
2073
+ if (existing) {
2074
+ Object.assign(existing, emoji);
2075
+ return existing;
2076
+ }
2077
+ this.set(key, emoji);
2078
+ return emoji;
2079
+ }
2080
+ }
1064
2081
 
1065
2082
  // packages/managers/src/index.ts
1066
2083
  class ChannelManager extends Manager {
@@ -1093,6 +2110,9 @@ class ChannelManager extends Manager {
1093
2110
  }
1094
2111
  return manager;
1095
2112
  }
2113
+ permissionOverwrites(channelId) {
2114
+ return new PermissionOverwriteManager(this.#rest, channelId);
2115
+ }
1096
2116
  threads(channelId) {
1097
2117
  return new ThreadManager(this.#rest, this.#context, channelId);
1098
2118
  }
@@ -1104,7 +2124,7 @@ class ChannelManager extends Manager {
1104
2124
  }
1105
2125
  upsert(data) {
1106
2126
  const existing = this.get(data.id);
1107
- const channel = new Channel(data, this.#context);
2127
+ const channel = createChannel(data, this.#context);
1108
2128
  if (existing) {
1109
2129
  Object.assign(existing, channel);
1110
2130
  return existing;
@@ -1123,8 +2143,11 @@ class ChannelManager extends Manager {
1123
2143
  }
1124
2144
  async deleteChannel(channelId) {
1125
2145
  await this.#rest.delete(Routes.channel(channelId));
2146
+ this.delete(channelId);
2147
+ }
2148
+ delete(channelId) {
1126
2149
  this.#messageManagers.delete(channelId);
1127
- super.delete(channelId);
2150
+ return super.delete(channelId);
1128
2151
  }
1129
2152
  send(channelId, options) {
1130
2153
  return this.messages(channelId).send(options);
@@ -1169,6 +2192,8 @@ class ChannelManager extends Manager {
1169
2192
  }
1170
2193
  async bulkDeleteMessages(channelId, messageIds) {
1171
2194
  const ids = [...messageIds];
2195
+ if (ids.length < 2 || ids.length > 100)
2196
+ throw new RangeError("bulkDelete requires between 2 and 100 message IDs.");
1172
2197
  await this.#rest.post(Routes.channelBulkDelete(channelId), {
1173
2198
  messages: ids
1174
2199
  });
@@ -1176,7 +2201,7 @@ class ChannelManager extends Manager {
1176
2201
  this.messages(channelId).delete(id);
1177
2202
  }
1178
2203
  async addReaction(channelId, messageId, emoji) {
1179
- await this.#rest.put(Routes.messageReactions(channelId, messageId, emoji));
2204
+ await this.#rest.put(`${Routes.messageReactions(channelId, messageId, emoji)}/@me`);
1180
2205
  }
1181
2206
  async fetchReactions(channelId, messageId, emoji, options = {}) {
1182
2207
  const params = new URLSearchParams;
@@ -1210,9 +2235,21 @@ class ChannelManager extends Manager {
1210
2235
  createThreadFromMessage(channelId, messageId, options) {
1211
2236
  return this.threads(channelId).createFromMessage(messageId, options);
1212
2237
  }
1213
- delete(channelId) {
1214
- this.#messageManagers.delete(channelId);
1215
- return super.delete(channelId);
2238
+ async fetchPage(channelId, options = {}) {
2239
+ const limit = Math.min(100, Math.max(1, options.limit ?? 50));
2240
+ const messages = await this.fetchMessages(channelId, {
2241
+ ...options,
2242
+ limit
2243
+ });
2244
+ return {
2245
+ messages,
2246
+ before: messages[0]?.id,
2247
+ after: messages[messages.length - 1]?.id,
2248
+ hasMore: messages.length === limit
2249
+ };
2250
+ }
2251
+ async bulkDelete(channelId, messageIds) {
2252
+ return this.bulkDeleteMessages(channelId, messageIds);
1216
2253
  }
1217
2254
  clear() {
1218
2255
  this.#messageManagers.clear();
@@ -1224,15 +2261,22 @@ function isMessageQuery(value) {
1224
2261
  }
1225
2262
  export {
1226
2263
  ApplicationCommandManager,
2264
+ AuditLogEvent,
2265
+ ResourceManager as CachedManager,
1227
2266
  ChannelManager,
2267
+ EmojiManager,
2268
+ GuildBanManager,
1228
2269
  GuildManager,
1229
2270
  GuildMemberManager,
2271
+ GuildScheduledEventManager,
1230
2272
  Manager,
1231
2273
  MessageManager,
2274
+ PermissionOverwriteManager,
1232
2275
  ResourceManager,
1233
2276
  RoleManager,
2277
+ StageInstanceManager,
1234
2278
  ThreadManager,
1235
2279
  UserManager
1236
2280
  };
1237
2281
 
1238
- //# debugId=53F2FF9551439B3964756E2164756E21
2282
+ //# debugId=E5CAD3E6B2BD672164756E2164756E21