lunibee 0.1.7 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +225 -223
  3. package/dist/builders/commands.d.ts +6 -4
  4. package/dist/builders/components.d.ts +23 -0
  5. package/dist/builders/index.d.ts +2 -2
  6. package/dist/builders/index.js +120 -24
  7. package/dist/builders/index.js.map +9 -8
  8. package/dist/collection/index.d.ts +68 -1
  9. package/dist/collection/index.js +335 -1
  10. package/dist/collection/index.js.map +4 -4
  11. package/dist/core/collector.d.ts +13 -0
  12. package/dist/core/events.d.ts +112 -2
  13. package/dist/core/index.d.ts +30 -93
  14. package/dist/core/index.js +3386 -957
  15. package/dist/core/index.js.map +48 -24
  16. package/dist/core/permissions.d.ts +48 -0
  17. package/dist/formatters/index.js.map +1 -1
  18. package/dist/handlers/index.js.map +1 -1
  19. package/dist/index.d.ts +1 -1
  20. package/dist/index.js +3806 -1193
  21. package/dist/index.js.map +64 -43
  22. package/dist/managers/advanced.d.ts +116 -0
  23. package/dist/managers/base.d.ts +13 -2
  24. package/dist/managers/emoji.d.ts +1 -1
  25. package/dist/managers/guild-resources.d.ts +109 -0
  26. package/dist/managers/guild.d.ts +33 -2
  27. package/dist/managers/index.d.ts +44 -6
  28. package/dist/managers/index.js +1186 -150
  29. package/dist/managers/index.js.map +27 -21
  30. package/dist/managers/message.d.ts +10 -1
  31. package/dist/rest/decoder.d.ts +23 -0
  32. package/dist/rest/errors.d.ts +53 -0
  33. package/dist/rest/index.d.ts +21 -17
  34. package/dist/rest/index.js +526 -264
  35. package/dist/rest/index.js.map +14 -8
  36. package/dist/rest/limiter.d.ts +42 -0
  37. package/dist/rest/redis.d.ts +18 -1
  38. package/dist/rest/route.d.ts +31 -0
  39. package/dist/rest/routes.d.ts +22 -0
  40. package/dist/rest/scheduler.d.ts +42 -0
  41. package/dist/rest/store.d.ts +29 -0
  42. package/dist/rest/transport.d.ts +40 -0
  43. package/dist/sharding/bus.d.ts +31 -0
  44. package/dist/sharding/cluster.d.ts +10 -0
  45. package/dist/sharding/index.d.ts +39 -2
  46. package/dist/sharding/index.js +1105 -404
  47. package/dist/sharding/index.js.map +18 -8
  48. package/dist/structures/base.d.ts +10 -0
  49. package/dist/structures/channels.d.ts +56 -0
  50. package/dist/structures/index.d.ts +1 -0
  51. package/dist/structures/index.js +305 -311
  52. package/dist/structures/index.js.map +18 -14
  53. package/dist/structures/interactions.d.ts +38 -52
  54. package/dist/structures/options.d.ts +55 -0
  55. package/dist/structures/resources.d.ts +3 -3
  56. package/dist/types/gateway-events.d.ts +132 -0
  57. package/dist/types/gateway.d.ts +197 -0
  58. package/dist/types/index.d.ts +53 -260
  59. package/dist/types/index.js +44 -2
  60. package/dist/types/index.js.map +5 -4
  61. package/dist/utils/index.js.map +1 -1
  62. package/dist/voice/index.d.ts +32 -1
  63. package/dist/voice/index.js +73 -7
  64. package/dist/voice/index.js.map +3 -3
  65. package/dist/ws/close-codes.d.ts +23 -0
  66. package/dist/ws/decoder.d.ts +58 -0
  67. package/dist/ws/heartbeat.d.ts +87 -0
  68. package/dist/ws/index.d.ts +18 -65
  69. package/dist/ws/index.js +911 -385
  70. package/dist/ws/index.js.map +15 -5
  71. package/dist/ws/opcodes.d.ts +14 -0
  72. package/dist/ws/protocol.d.ts +110 -0
  73. package/dist/ws/reconnect.d.ts +108 -0
  74. package/dist/ws/send-budget.d.ts +17 -0
  75. package/dist/ws/session.d.ts +100 -0
  76. package/dist/ws/state.d.ts +27 -0
  77. package/dist/ws/transport.d.ts +80 -0
  78. package/package.json +21 -20
@@ -71,6 +71,7 @@ class Channel extends BaseStructure {
71
71
  nsfw;
72
72
  rateLimitPerUser;
73
73
  position;
74
+ permissionOverwrites;
74
75
  #context;
75
76
  constructor(data, context) {
76
77
  super(data.id);
@@ -84,6 +85,7 @@ class Channel extends BaseStructure {
84
85
  this.nsfw = data.nsfw;
85
86
  this.rateLimitPerUser = data.rate_limit_per_user;
86
87
  this.position = data.position;
88
+ this.permissionOverwrites = (data.permission_overwrites ?? []).map((overwrite) => ({ ...overwrite }));
87
89
  this.#context = context;
88
90
  }
89
91
  sendMessage(options) {
@@ -118,6 +120,18 @@ class Channel extends BaseStructure {
118
120
  update(options) {
119
121
  return this.edit(options);
120
122
  }
123
+ isThread() {
124
+ return this.type === 10 || this.type === 11 || this.type === 12;
125
+ }
126
+ isTextBased() {
127
+ return [0, 1, 2, 3, 5, 10, 11, 12, 13].includes(this.type);
128
+ }
129
+ isVoiceBased() {
130
+ return this.type === 2 || this.type === 13;
131
+ }
132
+ isDMBased() {
133
+ return this.type === 1 || this.type === 3;
134
+ }
121
135
  toString() {
122
136
  return `<#${this.id}>`;
123
137
  }
@@ -278,8 +292,11 @@ var Permission = {
278
292
  createEvents: 1n << 44n,
279
293
  useExternalSounds: 1n << 45n,
280
294
  sendVoiceMessages: 1n << 46n,
295
+ setVoiceChannelStatus: 1n << 48n,
281
296
  sendPolls: 1n << 49n,
282
- useExternalApps: 1n << 50n
297
+ useExternalApps: 1n << 50n,
298
+ pinMessages: 1n << 51n,
299
+ bypassSlowmode: 1n << 52n
283
300
  };
284
301
  var Permissions = {
285
302
  CreateInstantInvite: 1n << 0n,
@@ -329,8 +346,11 @@ var Permissions = {
329
346
  CreateEvents: 1n << 44n,
330
347
  UseExternalSounds: 1n << 45n,
331
348
  SendVoiceMessages: 1n << 46n,
349
+ SetVoiceChannelStatus: 1n << 48n,
332
350
  SendPolls: 1n << 49n,
333
- UseExternalApps: 1n << 50n
351
+ UseExternalApps: 1n << 50n,
352
+ PinMessages: 1n << 51n,
353
+ BypassSlowmode: 1n << 52n
334
354
  };
335
355
  var PermissionFlagsBits = {
336
356
  CreateInstantInvite: 1n << 0n,
@@ -380,8 +400,11 @@ var PermissionFlagsBits = {
380
400
  CreateEvents: 1n << 44n,
381
401
  UseExternalSounds: 1n << 45n,
382
402
  SendVoiceMessages: 1n << 46n,
403
+ SetVoiceChannelStatus: 1n << 48n,
383
404
  SendPolls: 1n << 49n,
384
- UseExternalApps: 1n << 50n
405
+ UseExternalApps: 1n << 50n,
406
+ PinMessages: 1n << 51n,
407
+ BypassSlowmode: 1n << 52n
385
408
  };
386
409
 
387
410
  class PermissionSet {
@@ -583,6 +606,10 @@ class PermissionSet {
583
606
  }
584
607
  return false;
585
608
  }
609
+ missing(...permissions) {
610
+ const wanted = new PermissionSet(permissions);
611
+ return wanted.toArray().filter((name) => !this.has(name));
612
+ }
586
613
  add(...permissions) {
587
614
  let bitfield = this.bitfield;
588
615
  for (let i = 0;i < permissions.length; i++) {
@@ -644,7 +671,8 @@ class PermissionsBitField extends PermissionSet {
644
671
  super(value);
645
672
  }
646
673
  }
647
- // packages/types/src/index.ts
674
+ var ALL_PERMISSIONS = Object.values(Permission).reduce((bits, bit) => bits | bit, 0n);
675
+ // packages/types/src/gateway.ts
648
676
  var GatewayIntentBits = {
649
677
  Guilds: 1 << 0,
650
678
  GuildMembers: 1 << 1,
@@ -696,6 +724,7 @@ var IntentBits = {
696
724
  guildMessagePolls: 1 << 24,
697
725
  directMessagePolls: 1 << 25
698
726
  };
727
+ // packages/types/src/index.ts
699
728
  var InteractionResponseType = {
700
729
  Pong: 1,
701
730
  ChannelMessage: 4,
@@ -705,262 +734,10 @@ var InteractionResponseType = {
705
734
  Autocomplete: 8,
706
735
  Modal: 9
707
736
  };
708
- // packages/collection/src/index.ts
709
- class Collection extends Map {
710
- first() {
711
- for (const value of this.values())
712
- return value;
713
- return;
714
- }
715
- firstKey() {
716
- for (const key of this.keys())
717
- return key;
718
- return;
719
- }
720
- last() {
721
- let value;
722
- for (const item of this.values())
723
- value = item;
724
- return value;
725
- }
726
- lastKey() {
727
- let key;
728
- for (const item of this.keys())
729
- key = item;
730
- return key;
731
- }
732
- find(predicate) {
733
- for (const [key, value] of this) {
734
- if (predicate(value, key, this))
735
- return value;
736
- }
737
- return;
738
- }
739
- filter(predicate) {
740
- const result = new Collection;
741
- for (const [key, value] of this) {
742
- if (predicate(value, key, this))
743
- result.set(key, value);
744
- }
745
- return result;
746
- }
747
- map(transform) {
748
- const result = [];
749
- for (const [key, value] of this) {
750
- result.push(transform(value, key, this));
751
- }
752
- return result;
753
- }
754
- some(predicate) {
755
- for (const [key, value] of this) {
756
- if (predicate(value, key, this))
757
- return true;
758
- }
759
- return false;
760
- }
761
- every(predicate) {
762
- for (const [key, value] of this) {
763
- if (!predicate(value, key, this))
764
- return false;
765
- }
766
- return true;
767
- }
768
- each(callback) {
769
- for (const [key, value] of this) {
770
- callback(value, key, this);
771
- }
772
- return this;
773
- }
774
- array() {
775
- return [...this.values()];
776
- }
777
- keyArray() {
778
- return [...this.keys()];
779
- }
780
- entriesArray() {
781
- return [...this.entries()];
782
- }
783
- clone() {
784
- const copy = new Collection;
785
- for (const [key, value] of this)
786
- copy.set(key, value);
787
- return copy;
788
- }
789
- hasAll(...keys) {
790
- for (let i = 0;i < keys.length; i++) {
791
- if (!this.has(keys[i]))
792
- return false;
793
- }
794
- return true;
795
- }
796
- hasAny(...keys) {
797
- for (let i = 0;i < keys.length; i++) {
798
- if (this.has(keys[i]))
799
- return true;
800
- }
801
- return false;
802
- }
803
- findKey(predicate) {
804
- for (const [key, value] of this) {
805
- if (predicate(value, key, this))
806
- return key;
807
- }
808
- return;
809
- }
810
- someEntry(predicate) {
811
- return this.some(predicate);
812
- }
813
- sweep(predicate) {
814
- let removed = 0;
815
- for (const [key, value] of this) {
816
- if (predicate(value, key, this) && this.delete(key))
817
- removed++;
818
- }
819
- return removed;
820
- }
821
- firstEntry() {
822
- for (const [key, value] of this)
823
- return [key, value];
824
- return;
825
- }
826
- lastEntry() {
827
- let entry;
828
- for (const item of this)
829
- entry = [item[0], item[1]];
830
- return entry;
831
- }
832
- union(other) {
833
- const result = this.clone();
834
- for (const [key, value] of other)
835
- result.set(key, value);
836
- return result;
837
- }
838
- intersection(other) {
839
- const result = new Collection;
840
- for (const [key, value] of this) {
841
- if (other.has(key))
842
- result.set(key, value);
843
- }
844
- return result;
845
- }
846
- difference(other) {
847
- const result = new Collection;
848
- for (const [key, value] of this) {
849
- if (!other.has(key))
850
- result.set(key, value);
851
- }
852
- return result;
853
- }
854
- partition(predicate) {
855
- const pass = new Collection;
856
- const fail = new Collection;
857
- for (const [key, value] of this) {
858
- if (predicate(value, key, this))
859
- pass.set(key, value);
860
- else
861
- fail.set(key, value);
862
- }
863
- return [pass, fail];
864
- }
865
- tap(fn) {
866
- fn(this);
867
- return this;
868
- }
869
- flatMap(transform) {
870
- const result = [];
871
- for (const [key, value] of this) {
872
- for (const item of transform(value, key, this))
873
- result.push(item);
874
- }
875
- return result;
876
- }
877
- reduce(fn, initialValue) {
878
- let acc = initialValue;
879
- for (const [key, value] of this)
880
- acc = fn(acc, value, key, this);
881
- return acc;
882
- }
883
- sorted(comparator) {
884
- const decorated = [...this.entries()].map((entry, index) => ({
885
- entry,
886
- index
887
- }));
888
- if (comparator)
889
- decorated.sort((x, y) => {
890
- const comparison = comparator(x.entry[1], y.entry[1], x.entry[0], y.entry[0]);
891
- return comparison !== 0 ? comparison : x.index - y.index;
892
- });
893
- const result = new Collection;
894
- for (const { entry } of decorated)
895
- result.set(entry[0], entry[1]);
896
- return result;
897
- }
898
- random() {
899
- const arr = [...this.values()];
900
- if (!arr.length)
901
- return;
902
- return arr[Math.floor(Math.random() * arr.length)];
903
- }
904
- randomKey() {
905
- const arr = [...this.keys()];
906
- if (!arr.length)
907
- return;
908
- return arr[Math.floor(Math.random() * arr.length)];
909
- }
910
- at(index) {
911
- const arr = [...this.values()];
912
- const i = index < 0 ? arr.length + index : index;
913
- return arr[i];
914
- }
915
- keyAt(index) {
916
- const arr = [...this.keys()];
917
- const i = index < 0 ? arr.length + index : index;
918
- return arr[i];
919
- }
920
- toJSON() {
921
- return [...this.entries()];
922
- }
923
- }
924
-
925
- // packages/managers/src/base.ts
926
- class Manager {
927
- cache = new Collection;
928
- get(id) {
929
- return this.cache.get(id);
930
- }
931
- has(id) {
932
- return this.cache.has(id);
933
- }
934
- set(id, value) {
935
- this.cache.set(id, value);
936
- return this;
937
- }
938
- delete(id) {
939
- return this.cache.delete(id);
940
- }
941
- clear() {
942
- this.cache.clear();
943
- }
944
- get size() {
945
- return this.cache.size;
946
- }
947
- first() {
948
- return this.cache.first();
949
- }
950
- values() {
951
- return this.cache.array();
952
- }
953
- find(predicate) {
954
- return this.cache.find(predicate);
955
- }
956
- [Symbol.iterator]() {
957
- return this.cache[Symbol.iterator]();
958
- }
959
- }
960
737
  // packages/rest/package.json
961
738
  var package_default = {
962
739
  name: "@lunibee/rest",
963
- version: "0.1.7",
740
+ version: "0.2.0",
964
741
  type: "module",
965
742
  module: "./src/index.ts",
966
743
  types: "./src/index.ts",
@@ -968,6 +745,7 @@ var package_default = {
968
745
  ".": "./src/index.ts"
969
746
  }
970
747
  };
748
+
971
749
  // packages/rest/src/index.ts
972
750
  var LIBRARY_VERSION = package_default.version;
973
751
  var LIBRARY_URL = "https://github.com/Ekretos/lunibee";
@@ -981,6 +759,40 @@ var REQUEST_DATA_KEYS = new Set([
981
759
  "auth",
982
760
  "signal"
983
761
  ]);
762
+ // packages/managers/src/index.ts
763
+ var BULK_DELETE_MAX_AGE_MS = 14 * 24 * 60 * 60000;
764
+
765
+ // packages/ws/src/close-codes.ts
766
+ var GatewayCloseCodes = {
767
+ UnknownError: 4000,
768
+ UnknownOpcode: 4001,
769
+ DecodeError: 4002,
770
+ NotAuthenticated: 4003,
771
+ AuthenticationFailed: 4004,
772
+ AlreadyAuthenticated: 4005,
773
+ InvalidSeq: 4007,
774
+ RateLimited: 4008,
775
+ SessionTimedOut: 4009,
776
+ InvalidShard: 4010,
777
+ ShardingRequired: 4011,
778
+ InvalidAPIVersion: 4012,
779
+ InvalidIntents: 4013,
780
+ DisallowedIntents: 4014
781
+ };
782
+
783
+ // packages/ws/src/reconnect.ts
784
+ var FATAL_CLOSE_CODES = [
785
+ GatewayCloseCodes.AuthenticationFailed,
786
+ GatewayCloseCodes.InvalidShard,
787
+ GatewayCloseCodes.ShardingRequired,
788
+ GatewayCloseCodes.InvalidAPIVersion,
789
+ GatewayCloseCodes.InvalidIntents,
790
+ GatewayCloseCodes.DisallowedIntents
791
+ ];
792
+ var IDENTIFY_CLOSE_CODES = [
793
+ GatewayCloseCodes.InvalidSeq,
794
+ GatewayCloseCodes.SessionTimedOut
795
+ ];
984
796
  // packages/structures/src/resources.ts
985
797
  function toDateOrNull(value) {
986
798
  if (!value)
@@ -1166,7 +978,9 @@ class Emoji extends BaseStructure {
1166
978
  animated;
1167
979
  available;
1168
980
  constructor(data) {
1169
- super(data.id ?? "unicode");
981
+ super(data.id ?? "0");
982
+ if (data.id === null)
983
+ this.id = "unicode";
1170
984
  this.name = data.name;
1171
985
  this.roleIds = data.roles ?? [];
1172
986
  this.user = data.user ? new User(data.user) : null;
@@ -1299,14 +1113,107 @@ class GuildOnboarding2 extends BaseStructure {
1299
1113
  this.mode = data.mode;
1300
1114
  }
1301
1115
  }
1302
- // packages/structures/src/interactions.ts
1303
- var InteractionType = {
1304
- Ping: 1,
1305
- ApplicationCommand: 2,
1306
- MessageComponent: 3,
1307
- ApplicationCommandAutocomplete: 4,
1308
- ModalSubmit: 5
1309
- };
1116
+ // packages/structures/src/channels.ts
1117
+ class NewsChannel extends TextChannel {
1118
+ }
1119
+
1120
+ class DMChannel extends Channel {
1121
+ recipients;
1122
+ ownerId;
1123
+ constructor(data, context) {
1124
+ super(data, context);
1125
+ this.recipients = (data.recipients ?? []).map((u) => new User(u));
1126
+ this.ownerId = data.owner_id ?? null;
1127
+ }
1128
+ }
1129
+
1130
+ class VoiceChannel extends Channel {
1131
+ bitrate;
1132
+ userLimit;
1133
+ rtcRegion;
1134
+ videoQualityMode;
1135
+ constructor(data, context) {
1136
+ super(data, context);
1137
+ this.bitrate = data.bitrate ?? 64000;
1138
+ this.userLimit = data.user_limit ?? 0;
1139
+ this.rtcRegion = data.rtc_region ?? null;
1140
+ this.videoQualityMode = data.video_quality_mode ?? 1;
1141
+ }
1142
+ }
1143
+
1144
+ class StageChannel extends VoiceChannel {
1145
+ }
1146
+
1147
+ class CategoryChannel extends Channel {
1148
+ }
1149
+
1150
+ class ThreadChannel extends Channel {
1151
+ ownerId;
1152
+ messageCount;
1153
+ memberCount;
1154
+ metadata;
1155
+ constructor(data, context) {
1156
+ super(data, context);
1157
+ this.ownerId = data.owner_id ?? null;
1158
+ this.messageCount = data.message_count ?? 0;
1159
+ this.memberCount = data.member_count ?? 0;
1160
+ this.metadata = data.thread_metadata ?? null;
1161
+ }
1162
+ get archived() {
1163
+ return this.metadata?.archived ?? false;
1164
+ }
1165
+ get locked() {
1166
+ return this.metadata?.locked ?? false;
1167
+ }
1168
+ get autoArchiveDuration() {
1169
+ return this.metadata?.auto_archive_duration ?? null;
1170
+ }
1171
+ }
1172
+
1173
+ class ForumChannel extends Channel {
1174
+ availableTags;
1175
+ defaultReactionEmoji;
1176
+ defaultThreadRateLimitPerUser;
1177
+ defaultAutoArchiveDuration;
1178
+ constructor(data, context) {
1179
+ super(data, context);
1180
+ this.availableTags = data.available_tags ?? [];
1181
+ this.defaultReactionEmoji = data.default_reaction_emoji ?? null;
1182
+ this.defaultThreadRateLimitPerUser = data.default_thread_rate_limit_per_user ?? 0;
1183
+ this.defaultAutoArchiveDuration = data.default_auto_archive_duration ?? null;
1184
+ }
1185
+ }
1186
+
1187
+ class MediaChannel extends ForumChannel {
1188
+ }
1189
+ function createChannel(data, context) {
1190
+ switch (data.type) {
1191
+ case 0:
1192
+ return new TextChannel(data, context);
1193
+ case 1:
1194
+ case 3:
1195
+ return new DMChannel(data, context);
1196
+ case 2:
1197
+ return new VoiceChannel(data, context);
1198
+ case 4:
1199
+ return new CategoryChannel(data, context);
1200
+ case 5:
1201
+ return new NewsChannel(data, context);
1202
+ case 10:
1203
+ case 11:
1204
+ case 12:
1205
+ return new ThreadChannel(data, context);
1206
+ case 13:
1207
+ return new StageChannel(data, context);
1208
+ case 15:
1209
+ return new ForumChannel(data, context);
1210
+ case 16:
1211
+ return new MediaChannel(data, context);
1212
+ default:
1213
+ return new Channel(data, context);
1214
+ }
1215
+ }
1216
+ // packages/structures/src/options.ts
1310
1217
  var OptionType = {
1311
1218
  SubCommand: 1,
1312
1219
  SubCommandGroup: 2,
@@ -1362,6 +1269,12 @@ class CommandOptions {
1362
1269
  }
1363
1270
  return this.#subcommandGroup;
1364
1271
  }
1272
+ getFocused(full = false) {
1273
+ const focused = this.#options.find((o) => o.focused);
1274
+ if (!focused)
1275
+ throw new TypeError("No focused option was provided.");
1276
+ return full ? focused : focused.value ?? "";
1277
+ }
1365
1278
  getString(name, required = false) {
1366
1279
  const opt = this.#get(name);
1367
1280
  if (!opt || opt.type !== OptionType.String) {
@@ -1467,6 +1380,25 @@ class CommandOptions {
1467
1380
  return this.#options;
1468
1381
  }
1469
1382
  }
1383
+ // packages/structures/src/interactions.ts
1384
+ var InteractionType = {
1385
+ Ping: 1,
1386
+ ApplicationCommand: 2,
1387
+ MessageComponent: 3,
1388
+ ApplicationCommandAutocomplete: 4,
1389
+ ModalSubmit: 5
1390
+ };
1391
+ var EPHEMERAL = 64;
1392
+ var TOKEN_LIFETIME_MS = 15 * 60000;
1393
+ var DISCORD_EPOCH = 1420070400000n;
1394
+ function toMessageData(options) {
1395
+ if (typeof options === "string")
1396
+ return { content: options };
1397
+ const { ephemeral, ...data } = options;
1398
+ if (ephemeral)
1399
+ data.flags = (typeof data.flags === "number" ? data.flags : 0) | EPHEMERAL;
1400
+ return data;
1401
+ }
1470
1402
 
1471
1403
  class InteractionResponse {
1472
1404
  type;
@@ -1481,21 +1413,17 @@ class InteractionResponse {
1481
1413
  return this.data === undefined ? { type: this.type } : { type: this.type, data: this.data };
1482
1414
  }
1483
1415
  static message(options) {
1484
- const data = { ...options };
1485
- if (options.ephemeral) {
1486
- data.flags = (typeof options.flags === "number" ? options.flags : 0) | 64;
1487
- }
1488
- return new InteractionResponse(InteractionResponseType.ChannelMessage, data);
1416
+ return new InteractionResponse(InteractionResponseType.ChannelMessage, toMessageData(options));
1489
1417
  }
1490
1418
  static defer(ephemeral = false) {
1491
- return new InteractionResponse(InteractionResponseType.DeferredChannelMessage, ephemeral ? { flags: 64 } : undefined);
1419
+ return new InteractionResponse(InteractionResponseType.DeferredChannelMessage, ephemeral ? { flags: EPHEMERAL } : undefined);
1492
1420
  }
1493
1421
  static pong() {
1494
1422
  return new InteractionResponse(InteractionResponseType.Pong);
1495
1423
  }
1496
1424
  }
1497
1425
 
1498
- class Interaction2 {
1426
+ class Interaction {
1499
1427
  id;
1500
1428
  applicationId;
1501
1429
  token;
@@ -1506,6 +1434,7 @@ class Interaction2 {
1506
1434
  replied = false;
1507
1435
  deferred = false;
1508
1436
  #client;
1437
+ #acknowledging = false;
1509
1438
  constructor(client, data) {
1510
1439
  if (!data.id || !data.token)
1511
1440
  throw new TypeError("Interaction ID and token are required.");
@@ -1530,10 +1459,82 @@ class Interaction2 {
1530
1459
  isAutocomplete() {
1531
1460
  return this.type === InteractionType.ApplicationCommandAutocomplete;
1532
1461
  }
1462
+ #componentType() {
1463
+ return this.isMessageComponent() ? this.data.data?.component_type ?? 0 : 0;
1464
+ }
1465
+ isButton() {
1466
+ return this.#componentType() === 2;
1467
+ }
1468
+ isStringSelectMenu() {
1469
+ return this.#componentType() === 3;
1470
+ }
1471
+ isUserSelectMenu() {
1472
+ return this.#componentType() === 5;
1473
+ }
1474
+ isRoleSelectMenu() {
1475
+ return this.#componentType() === 6;
1476
+ }
1477
+ isMentionableSelectMenu() {
1478
+ return this.#componentType() === 7;
1479
+ }
1480
+ isChannelSelectMenu() {
1481
+ return this.#componentType() === 8;
1482
+ }
1483
+ isAnySelectMenu() {
1484
+ return [3, 5, 6, 7, 8].includes(this.#componentType());
1485
+ }
1533
1486
  assertUnacknowledged() {
1534
- if (this.replied || this.deferred)
1487
+ if (this.replied || this.deferred || this.#acknowledging)
1535
1488
  throw new Error("Interaction has already been acknowledged.");
1536
1489
  }
1490
+ async acknowledge(response, state) {
1491
+ this.assertUnacknowledged();
1492
+ this.#acknowledging = true;
1493
+ try {
1494
+ const result = await this.postResponse(response);
1495
+ this[state] = true;
1496
+ return result;
1497
+ } finally {
1498
+ this.#acknowledging = false;
1499
+ }
1500
+ }
1501
+ get user() {
1502
+ const raw = this.data.member?.user ?? this.data.user;
1503
+ return raw ? new User(raw) : null;
1504
+ }
1505
+ get member() {
1506
+ const raw = this.data.member;
1507
+ if (!raw || !this.guildId)
1508
+ return null;
1509
+ return new GuildMember({
1510
+ ...raw,
1511
+ guild_id: this.guildId
1512
+ });
1513
+ }
1514
+ get createdTimestamp() {
1515
+ return Number((BigInt(this.id) >> 22n) + DISCORD_EPOCH);
1516
+ }
1517
+ get expiresAt() {
1518
+ return new Date(this.createdTimestamp + TOKEN_LIFETIME_MS);
1519
+ }
1520
+ get isExpired() {
1521
+ return Date.now() >= this.createdTimestamp + TOKEN_LIFETIME_MS;
1522
+ }
1523
+ #webhookMessage(method, messageId, data) {
1524
+ if (!this.#client.interactionWebhookMessage)
1525
+ return Promise.reject(new Error("This interaction client does not support webhook message access."));
1526
+ return this.#client.interactionWebhookMessage(method, this.applicationId, this.token, messageId, data);
1527
+ }
1528
+ fetchReply() {
1529
+ this.assertAcknowledged();
1530
+ return this.#webhookMessage("GET", "@original");
1531
+ }
1532
+ editFollowUp(messageId, options) {
1533
+ return this.#webhookMessage("PATCH", messageId, toMessageData(options));
1534
+ }
1535
+ async deleteFollowUp(messageId) {
1536
+ await this.#webhookMessage("DELETE", messageId);
1537
+ }
1537
1538
  assertAcknowledged() {
1538
1539
  if (!this.replied && !this.deferred)
1539
1540
  throw new Error("Interaction has not been acknowledged.");
@@ -1542,45 +1543,31 @@ class Interaction2 {
1542
1543
  return this.#client.postInteractionResponse(this.id, this.token, response);
1543
1544
  }
1544
1545
  async reply(options) {
1545
- this.assertUnacknowledged();
1546
- const payload = typeof options === "string" ? { content: options } : options;
1547
- const result = await this.#client.postInteractionResponse(this.id, this.token, InteractionResponse.message(payload));
1548
- this.replied = true;
1549
- return result;
1546
+ return this.acknowledge(InteractionResponse.message(toMessageData(options)), "replied");
1550
1547
  }
1551
1548
  async deferReply(ephemeral = false) {
1552
- this.assertUnacknowledged();
1553
- await this.#client.postInteractionResponse(this.id, this.token, InteractionResponse.defer(ephemeral));
1554
- this.deferred = true;
1549
+ await this.acknowledge(InteractionResponse.defer(ephemeral), "deferred");
1555
1550
  }
1556
1551
  editReply(options) {
1557
1552
  this.assertAcknowledged();
1558
- return this.#client.editInteractionReply(this.token, options);
1553
+ return this.#client.editInteractionReply(this.token, toMessageData(options));
1559
1554
  }
1560
1555
  deleteReply() {
1561
1556
  this.assertAcknowledged();
1562
1557
  return this.#client.deleteInteractionReply(this.token);
1563
1558
  }
1564
1559
  followUp(options) {
1565
- const payload = typeof options === "string" ? { content: options } : options;
1566
- return this.#client.followUpInteraction(this.token, payload);
1560
+ return this.#client.followUpInteraction(this.token, toMessageData(options));
1567
1561
  }
1568
1562
  async update(options) {
1569
- this.assertUnacknowledged();
1570
- const payload = typeof options === "string" ? { content: options } : options;
1571
- const result = await this.#client.postInteractionResponse(this.id, this.token, new InteractionResponse(InteractionResponseType.MessageUpdate, payload));
1572
- this.replied = true;
1573
- return result;
1563
+ return this.acknowledge(new InteractionResponse(InteractionResponseType.MessageUpdate, toMessageData(options)), "replied");
1574
1564
  }
1575
1565
  async showModal(modal) {
1576
- this.assertUnacknowledged();
1577
- const result = await this.#client.postInteractionResponse(this.id, this.token, new InteractionResponse(InteractionResponseType.Modal, modal));
1578
- this.replied = true;
1579
- return result;
1566
+ return this.acknowledge(new InteractionResponse(InteractionResponseType.Modal, modal), "replied");
1580
1567
  }
1581
1568
  }
1582
1569
 
1583
- class CommandInteraction extends Interaction2 {
1570
+ class CommandInteraction extends Interaction {
1584
1571
  options;
1585
1572
  get commandName() {
1586
1573
  return typeof this.data.data?.name === "string" ? this.data.data.name : "";
@@ -1593,7 +1580,7 @@ class CommandInteraction extends Interaction2 {
1593
1580
  }
1594
1581
  }
1595
1582
 
1596
- class ComponentInteraction extends Interaction2 {
1583
+ class ComponentInteraction extends Interaction {
1597
1584
  get customId() {
1598
1585
  return this.data?.data?.custom_id ?? "";
1599
1586
  }
@@ -1604,20 +1591,14 @@ class ComponentInteraction extends Interaction2 {
1604
1591
  return this.data?.data?.values ?? [];
1605
1592
  }
1606
1593
  async deferUpdate() {
1607
- this.assertUnacknowledged();
1608
- await this.postResponse(new InteractionResponse(InteractionResponseType.DeferredMessageUpdate));
1609
- this.deferred = true;
1594
+ await this.acknowledge(new InteractionResponse(InteractionResponseType.DeferredMessageUpdate), "deferred");
1610
1595
  }
1611
1596
  async update(options) {
1612
- this.assertUnacknowledged();
1613
- const payload = typeof options === "string" ? { content: options } : options;
1614
- const result = await this.postResponse(new InteractionResponse(InteractionResponseType.MessageUpdate, payload));
1615
- this.replied = true;
1616
- return result;
1597
+ return this.acknowledge(new InteractionResponse(InteractionResponseType.MessageUpdate, toMessageData(options)), "replied");
1617
1598
  }
1618
1599
  }
1619
1600
 
1620
- class ModalSubmitInteraction extends Interaction2 {
1601
+ class ModalSubmitInteraction extends Interaction {
1621
1602
  get customId() {
1622
1603
  return this.data?.data?.custom_id ?? "";
1623
1604
  }
@@ -1639,7 +1620,12 @@ class ModalSubmitInteraction extends Interaction2 {
1639
1620
  }
1640
1621
  }
1641
1622
 
1642
- class AutocompleteInteraction extends Interaction2 {
1623
+ class AutocompleteInteraction extends Interaction {
1624
+ options;
1625
+ constructor(client, data) {
1626
+ super(client, data);
1627
+ this.options = new CommandOptions(data.data?.options ?? []);
1628
+ }
1643
1629
  get commandName() {
1644
1630
  return this.data?.data?.name ?? "";
1645
1631
  }
@@ -1651,8 +1637,7 @@ class AutocompleteInteraction extends Interaction2 {
1651
1637
  if (!Array.isArray(choices))
1652
1638
  throw new TypeError("Autocomplete choices must be an array.");
1653
1639
  const response = new InteractionResponse(InteractionResponseType.Autocomplete, { choices });
1654
- await this.postResponse(response);
1655
- this.replied = true;
1640
+ await this.acknowledge(response, "replied");
1656
1641
  }
1657
1642
  }
1658
1643
  function findFocused(options) {
@@ -1678,7 +1663,7 @@ function createInteraction(client, data) {
1678
1663
  case InteractionType.ModalSubmit:
1679
1664
  return new ModalSubmitInteraction(client, data);
1680
1665
  default:
1681
- return new Interaction2(client, data);
1666
+ return new Interaction(client, data);
1682
1667
  }
1683
1668
  }
1684
1669
  // packages/structures/src/embed.ts
@@ -2008,33 +1993,42 @@ export {
2008
1993
  AutoModerationRule,
2009
1994
  AutocompleteInteraction,
2010
1995
  BaseStructure,
1996
+ CategoryChannel,
2011
1997
  Channel,
2012
1998
  CommandInteraction,
2013
1999
  CommandOptions,
2014
2000
  ComponentInteraction,
2001
+ DMChannel,
2015
2002
  Embed,
2016
2003
  Emoji,
2004
+ ForumChannel,
2017
2005
  Guild,
2018
2006
  GuildMember,
2019
2007
  GuildOnboarding2 as GuildOnboarding,
2020
2008
  GuildWelcomeScreen2 as GuildWelcomeScreen,
2021
- Interaction2 as Interaction,
2009
+ Interaction,
2022
2010
  InteractionResponse,
2023
2011
  InteractionResponseType,
2024
2012
  InteractionType,
2025
2013
  Invite,
2014
+ MediaChannel,
2026
2015
  Message,
2027
2016
  ModalSubmitInteraction,
2017
+ NewsChannel,
2028
2018
  OnboardingPrompt,
2029
2019
  OnboardingPromptOption,
2030
2020
  PermissionsBitField,
2031
2021
  Role,
2022
+ StageChannel,
2032
2023
  TextChannel,
2024
+ ThreadChannel,
2033
2025
  User,
2026
+ VoiceChannel,
2034
2027
  Webhook,
2035
2028
  WebhookType,
2036
2029
  WelcomeScreenChannel,
2030
+ createChannel,
2037
2031
  createInteraction
2038
2032
  };
2039
2033
 
2040
- //# debugId=889BE16B7674B4BA64756E2164756E21
2034
+ //# debugId=39460C3E91D6CD3564756E2164756E21