seyfert 2.1.0 → 2.1.1-dev-11310514874.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 (240) hide show
  1. package/lib/api/Router.d.ts +2 -2
  2. package/lib/api/Router.js +2 -1
  3. package/lib/api/Routes/applications.d.ts +29 -30
  4. package/lib/api/Routes/cdn.d.ts +6 -1
  5. package/lib/api/Routes/channels.d.ts +44 -45
  6. package/lib/api/Routes/gateway.d.ts +3 -4
  7. package/lib/api/Routes/guilds.d.ts +81 -80
  8. package/lib/api/Routes/index.d.ts +3 -1
  9. package/lib/api/Routes/interactions.d.ts +6 -6
  10. package/lib/api/Routes/invites.d.ts +3 -4
  11. package/lib/api/Routes/skus.d.ts +4 -5
  12. package/lib/api/Routes/soundboard.d.ts +23 -0
  13. package/lib/api/Routes/soundboard.js +2 -0
  14. package/lib/api/Routes/stage-instances.d.ts +5 -6
  15. package/lib/api/Routes/stickers.d.ts +3 -4
  16. package/lib/api/Routes/users.d.ts +11 -12
  17. package/lib/api/Routes/voice.d.ts +2 -3
  18. package/lib/api/Routes/webhooks.d.ts +16 -15
  19. package/lib/api/api.d.ts +17 -11
  20. package/lib/api/api.js +12 -10
  21. package/lib/api/shared.d.ts +1 -1
  22. package/lib/api/utils/constants.d.ts +2 -0
  23. package/lib/api/utils/constants.js +2 -1
  24. package/lib/builders/ActionRow.d.ts +1 -1
  25. package/lib/builders/Attachment.d.ts +2 -2
  26. package/lib/builders/Attachment.js +1 -1
  27. package/lib/builders/Button.d.ts +1 -1
  28. package/lib/builders/Button.js +1 -1
  29. package/lib/builders/Embed.d.ts +1 -1
  30. package/lib/builders/Embed.js +2 -2
  31. package/lib/builders/Modal.d.ts +1 -1
  32. package/lib/builders/Poll.d.ts +1 -1
  33. package/lib/builders/Poll.js +1 -1
  34. package/lib/builders/SelectMenu.d.ts +1 -1
  35. package/lib/builders/SelectMenu.js +1 -1
  36. package/lib/builders/types.d.ts +2 -1
  37. package/lib/cache/adapters/default.js +5 -3
  38. package/lib/cache/adapters/limited.d.ts +1 -2
  39. package/lib/cache/adapters/limited.js +34 -30
  40. package/lib/cache/adapters/workeradapter.js +3 -1
  41. package/lib/cache/index.d.ts +8 -11
  42. package/lib/cache/index.js +38 -37
  43. package/lib/cache/resources/bans.d.ts +2 -2
  44. package/lib/cache/resources/bans.js +1 -1
  45. package/lib/cache/resources/channels.d.ts +1 -1
  46. package/lib/cache/resources/default/guild-related.d.ts +1 -2
  47. package/lib/cache/resources/emojis.d.ts +2 -2
  48. package/lib/cache/resources/emojis.js +1 -1
  49. package/lib/cache/resources/guilds.d.ts +2 -2
  50. package/lib/cache/resources/guilds.js +7 -11
  51. package/lib/cache/resources/members.d.ts +2 -2
  52. package/lib/cache/resources/members.js +1 -1
  53. package/lib/cache/resources/messages.d.ts +2 -2
  54. package/lib/cache/resources/messages.js +3 -3
  55. package/lib/cache/resources/overwrites.d.ts +1 -1
  56. package/lib/cache/resources/roles.d.ts +2 -2
  57. package/lib/cache/resources/roles.js +1 -1
  58. package/lib/cache/resources/stickers.d.ts +2 -2
  59. package/lib/cache/resources/stickers.js +1 -1
  60. package/lib/cache/resources/users.d.ts +2 -2
  61. package/lib/cache/resources/users.js +1 -1
  62. package/lib/cache/resources/voice-states.d.ts +2 -2
  63. package/lib/cache/resources/voice-states.js +1 -1
  64. package/lib/client/base.d.ts +9 -14
  65. package/lib/client/base.js +43 -44
  66. package/lib/client/client.d.ts +3 -7
  67. package/lib/client/client.js +24 -41
  68. package/lib/client/collectors.js +1 -1
  69. package/lib/client/httpclient.d.ts +1 -1
  70. package/lib/client/transformers.d.ts +37 -34
  71. package/lib/client/transformers.js +66 -63
  72. package/lib/client/workerclient.d.ts +10 -11
  73. package/lib/client/workerclient.js +180 -75
  74. package/lib/collection.d.ts +3 -3
  75. package/lib/commands/applications/chat.d.ts +3 -3
  76. package/lib/commands/applications/chat.js +5 -6
  77. package/lib/commands/applications/chatcontext.d.ts +6 -6
  78. package/lib/commands/applications/chatcontext.js +16 -8
  79. package/lib/commands/applications/entryPoint.d.ts +1 -1
  80. package/lib/commands/applications/entrycontext.d.ts +6 -6
  81. package/lib/commands/applications/entrycontext.js +4 -4
  82. package/lib/commands/applications/menu.d.ts +1 -1
  83. package/lib/commands/applications/menucontext.d.ts +5 -5
  84. package/lib/commands/applications/menucontext.js +6 -6
  85. package/lib/commands/applications/options.d.ts +4 -4
  86. package/lib/commands/applications/shared.d.ts +5 -2
  87. package/lib/commands/basecontext.d.ts +1 -1
  88. package/lib/commands/decorators.d.ts +10 -10
  89. package/lib/commands/decorators.js +5 -4
  90. package/lib/commands/handle.d.ts +9 -9
  91. package/lib/commands/handle.js +94 -68
  92. package/lib/commands/handler.d.ts +5 -5
  93. package/lib/commands/handler.js +21 -17
  94. package/lib/commands/optionresolver.d.ts +4 -4
  95. package/lib/commands/optionresolver.js +3 -3
  96. package/lib/common/it/formatter.d.ts +21 -21
  97. package/lib/common/it/formatter.js +40 -41
  98. package/lib/common/it/logger.js +1 -1
  99. package/lib/common/it/utils.d.ts +4 -3
  100. package/lib/common/it/utils.js +52 -27
  101. package/lib/common/shorters/application.d.ts +2 -3
  102. package/lib/common/shorters/application.js +3 -3
  103. package/lib/common/shorters/bans.js +1 -1
  104. package/lib/common/shorters/channels.d.ts +3 -3
  105. package/lib/common/shorters/channels.js +3 -3
  106. package/lib/common/shorters/emojis.js +4 -4
  107. package/lib/common/shorters/guilds.d.ts +3 -3
  108. package/lib/common/shorters/guilds.js +5 -9
  109. package/lib/common/shorters/interaction.d.ts +3 -3
  110. package/lib/common/shorters/interaction.js +6 -5
  111. package/lib/common/shorters/members.d.ts +4 -5
  112. package/lib/common/shorters/members.js +6 -7
  113. package/lib/common/shorters/messages.d.ts +1 -1
  114. package/lib/common/shorters/messages.js +4 -4
  115. package/lib/common/shorters/reactions.d.ts +1 -1
  116. package/lib/common/shorters/reactions.js +1 -1
  117. package/lib/common/shorters/roles.js +1 -1
  118. package/lib/common/shorters/templates.js +2 -2
  119. package/lib/common/shorters/threads.d.ts +1 -1
  120. package/lib/common/shorters/threads.js +17 -11
  121. package/lib/common/shorters/webhook.d.ts +1 -1
  122. package/lib/common/shorters/webhook.js +4 -4
  123. package/lib/common/types/options.d.ts +2 -2
  124. package/lib/common/types/resolvables.d.ts +1 -1
  125. package/lib/common/types/util.d.ts +4 -1
  126. package/lib/common/types/write.d.ts +1 -1
  127. package/lib/components/BaseComponent.js +1 -1
  128. package/lib/components/ButtonComponent.d.ts +1 -1
  129. package/lib/components/componentcommand.d.ts +1 -1
  130. package/lib/components/componentcontext.d.ts +4 -4
  131. package/lib/components/componentcontext.js +1 -1
  132. package/lib/components/handler.d.ts +10 -8
  133. package/lib/components/handler.js +16 -13
  134. package/lib/components/index.js +2 -1
  135. package/lib/components/modalcontext.d.ts +2 -2
  136. package/lib/components/modalcontext.js +1 -1
  137. package/lib/deps/mixer.d.ts +1 -1
  138. package/lib/events/handler.d.ts +5 -5
  139. package/lib/events/handler.js +66 -16
  140. package/lib/events/hooks/application_command.d.ts +1 -1
  141. package/lib/events/hooks/auto_moderation.d.ts +1 -1
  142. package/lib/events/hooks/auto_moderation.js +1 -1
  143. package/lib/events/hooks/channel.d.ts +1 -1
  144. package/lib/events/hooks/dispatch.d.ts +1 -1
  145. package/lib/events/hooks/entitlement.d.ts +4 -5
  146. package/lib/events/hooks/entitlement.js +4 -4
  147. package/lib/events/hooks/guild.d.ts +3 -3
  148. package/lib/events/hooks/guild.js +1 -1
  149. package/lib/events/hooks/index.d.ts +1 -0
  150. package/lib/events/hooks/index.js +1 -0
  151. package/lib/events/hooks/integration.d.ts +1 -1
  152. package/lib/events/hooks/integration.js +1 -1
  153. package/lib/events/hooks/interactions.d.ts +3 -3
  154. package/lib/events/hooks/invite.d.ts +1 -1
  155. package/lib/events/hooks/message.d.ts +3 -3
  156. package/lib/events/hooks/message.js +1 -1
  157. package/lib/events/hooks/presence.d.ts +2 -2
  158. package/lib/events/hooks/soundboard.d.ts +155 -0
  159. package/lib/events/hooks/soundboard.js +28 -0
  160. package/lib/events/hooks/stage.d.ts +2 -2
  161. package/lib/events/hooks/thread.d.ts +2 -2
  162. package/lib/events/hooks/thread.js +2 -2
  163. package/lib/events/hooks/typing.d.ts +1 -1
  164. package/lib/events/hooks/typing.js +1 -1
  165. package/lib/events/hooks/user.d.ts +2 -2
  166. package/lib/events/hooks/voice.d.ts +2 -2
  167. package/lib/events/hooks/voice.js +1 -1
  168. package/lib/events/hooks/webhook.d.ts +1 -1
  169. package/lib/index.d.ts +2 -2
  170. package/lib/index.js +3 -5
  171. package/lib/langs/handler.d.ts +2 -2
  172. package/lib/structures/Guild.d.ts +7 -4
  173. package/lib/structures/Guild.js +1 -1
  174. package/lib/structures/GuildBan.d.ts +1 -1
  175. package/lib/structures/GuildMember.d.ts +7 -5
  176. package/lib/structures/GuildMember.js +5 -3
  177. package/lib/structures/GuildRole.d.ts +1 -1
  178. package/lib/structures/GuildTemplate.d.ts +1 -1
  179. package/lib/structures/Interaction.d.ts +17 -14
  180. package/lib/structures/Interaction.js +28 -21
  181. package/lib/structures/Message.d.ts +4 -7
  182. package/lib/structures/Message.js +5 -5
  183. package/lib/structures/Poll.d.ts +3 -3
  184. package/lib/structures/Sticker.d.ts +2 -2
  185. package/lib/structures/Sticker.js +1 -1
  186. package/lib/structures/VoiceState.d.ts +2 -1
  187. package/lib/structures/VoiceState.js +1 -1
  188. package/lib/structures/Webhook.d.ts +3 -3
  189. package/lib/structures/Webhook.js +1 -1
  190. package/lib/structures/channels.d.ts +4 -4
  191. package/lib/structures/channels.js +6 -5
  192. package/lib/structures/extra/BitField.d.ts +3 -3
  193. package/lib/structures/extra/BitField.js +34 -33
  194. package/lib/structures/extra/DiscordBase.js +1 -1
  195. package/lib/structures/extra/Permissions.d.ts +2 -0
  196. package/lib/structures/extra/Permissions.js +21 -0
  197. package/lib/types/gateway.d.ts +53 -5
  198. package/lib/types/payloads/_interactions/base.d.ts +1 -1
  199. package/lib/types/payloads/channel.d.ts +2 -2
  200. package/lib/types/payloads/guild.d.ts +9 -1
  201. package/lib/types/payloads/guild.js +8 -0
  202. package/lib/types/payloads/index.d.ts +1 -0
  203. package/lib/types/payloads/index.js +1 -0
  204. package/lib/types/payloads/soundboard.d.ts +23 -0
  205. package/lib/types/payloads/soundboard.js +5 -0
  206. package/lib/types/payloads/user.js +0 -1
  207. package/lib/types/rest/application.d.ts +3 -3
  208. package/lib/types/rest/auditLog.d.ts +1 -1
  209. package/lib/types/rest/channel.d.ts +2 -2
  210. package/lib/types/rest/guild.d.ts +2 -2
  211. package/lib/types/rest/guildScheduledEvent.d.ts +1 -1
  212. package/lib/types/rest/index.d.ts +1 -0
  213. package/lib/types/rest/index.js +1 -0
  214. package/lib/types/rest/oauth2.d.ts +1 -1
  215. package/lib/types/rest/poll.d.ts +1 -1
  216. package/lib/types/rest/soundboard.d.ts +64 -0
  217. package/lib/types/rest/soundboard.js +2 -0
  218. package/lib/types/rest/stageInstance.d.ts +1 -1
  219. package/lib/types/rest/template.d.ts +1 -1
  220. package/lib/types/rest/user.d.ts +1 -1
  221. package/lib/types/rest/webhook.d.ts +1 -1
  222. package/lib/types/utils/index.d.ts +11 -2
  223. package/lib/types/utils/index.js +10 -2
  224. package/lib/websocket/SharedTypes.d.ts +11 -2
  225. package/lib/websocket/constants/index.js +0 -10
  226. package/lib/websocket/discord/basesocket.d.ts +1 -1
  227. package/lib/websocket/discord/shard.d.ts +1 -1
  228. package/lib/websocket/discord/shard.js +25 -16
  229. package/lib/websocket/discord/sharder.d.ts +9 -6
  230. package/lib/websocket/discord/sharder.js +91 -74
  231. package/lib/websocket/discord/shared.d.ts +3 -14
  232. package/lib/websocket/discord/socket/custom.js +19 -6
  233. package/lib/websocket/discord/worker.d.ts +8 -2
  234. package/lib/websocket/discord/workermanager.d.ts +42 -17
  235. package/lib/websocket/discord/workermanager.js +144 -37
  236. package/lib/websocket/structures/timeout.d.ts +4 -5
  237. package/lib/websocket/structures/timeout.js +23 -24
  238. package/package.json +72 -70
  239. package/lib/cache/resources/threads.d.ts +0 -14
  240. package/lib/cache/resources/threads.js +0 -32
@@ -2,18 +2,18 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WorkerClient = void 0;
4
4
  exports.generateShardInfo = generateShardInfo;
5
- const types_1 = require("../types");
6
5
  const node_crypto_1 = require("node:crypto");
7
6
  const __1 = require("..");
8
7
  const cache_1 = require("../cache");
9
8
  const common_1 = require("../common");
10
9
  const events_1 = require("../events");
10
+ const types_1 = require("../types");
11
11
  const websocket_1 = require("../websocket");
12
12
  const base_1 = require("./base");
13
- const collectors_1 = require("./collectors");
14
- const transformers_1 = require("./transformers");
15
13
  const memberUpdate_1 = require("../websocket/discord/events/memberUpdate");
16
14
  const presenceUpdate_1 = require("../websocket/discord/events/presenceUpdate");
15
+ const collectors_1 = require("./collectors");
16
+ const transformers_1 = require("./transformers");
17
17
  let workerData;
18
18
  let manager;
19
19
  try {
@@ -27,11 +27,15 @@ try {
27
27
  workerProxy: process.env.SEYFERT_WORKER_WORKERPROXY === 'true',
28
28
  totalShards: Number(process.env.SEYFERT_WORKER_TOTALSHARDS),
29
29
  mode: process.env.SEYFERT_WORKER_MODE,
30
+ resharding: process.env.SEYFERT_WORKER_RESHARDING === 'true',
30
31
  };
31
32
  }
32
- catch { }
33
+ catch {
34
+ //
35
+ }
33
36
  class WorkerClient extends base_1.BaseClient {
34
37
  __handleGuilds = new Set();
38
+ __handleGuildsResharding;
35
39
  memberUpdateHandler = new memberUpdate_1.MemberUpdateHandler();
36
40
  presenceUpdateHandler = new presenceUpdate_1.PresenceUpdateHandler();
37
41
  collectors = new collectors_1.Collectors();
@@ -39,6 +43,8 @@ class WorkerClient extends base_1.BaseClient {
39
43
  me;
40
44
  promises = new Map();
41
45
  shards = new Map();
46
+ resharding = new Map();
47
+ _ready;
42
48
  __setServicesCache;
43
49
  constructor(options) {
44
50
  super(options);
@@ -54,22 +60,11 @@ class WorkerClient extends base_1.BaseClient {
54
60
  this.shards.forEach(s => (acc += s.latency));
55
61
  return acc / this.shards.size;
56
62
  }
57
- setServices({ ...rest }) {
63
+ setServices(rest) {
58
64
  super.setServices(rest);
59
65
  if (rest.cache) {
60
66
  this.__setServicesCache = true;
61
67
  }
62
- if (rest.handlers && 'events' in rest.handlers) {
63
- if (!rest.handlers.events) {
64
- this.events = undefined;
65
- }
66
- else if (typeof rest.handlers.events === 'function') {
67
- this.events = new events_1.EventHandler(this);
68
- }
69
- else {
70
- this.events = rest.handlers.events;
71
- }
72
- }
73
68
  }
74
69
  setWorkerData(data) {
75
70
  workerData = data;
@@ -123,9 +118,12 @@ class WorkerClient extends base_1.BaseClient {
123
118
  });
124
119
  }
125
120
  this.postMessage({
126
- type: 'WORKER_START',
121
+ type: workerData.resharding ? 'WORKER_START_RESHARDING' : 'WORKER_START',
127
122
  workerId: workerData.workerId,
128
123
  });
124
+ if (workerData.resharding) {
125
+ this.__handleGuildsResharding = new Set();
126
+ }
129
127
  await super.start(options);
130
128
  await this.loadEvents(options.eventsDir);
131
129
  this.cache.intents = workerData.intents;
@@ -169,6 +167,17 @@ class WorkerClient extends base_1.BaseClient {
169
167
  });
170
168
  }
171
169
  break;
170
+ case 'ALLOW_CONNECT_RESHARDING':
171
+ {
172
+ const shard = this.resharding.get(data.shardId);
173
+ if (!shard) {
174
+ this.logger.fatal('Worker trying reshard non-existent shard');
175
+ return;
176
+ }
177
+ shard.options.presence = data.presence;
178
+ await shard.connect();
179
+ }
180
+ break;
172
181
  case 'ALLOW_CONNECT':
173
182
  {
174
183
  const shard = this.shards.get(data.shardId);
@@ -180,39 +189,96 @@ class WorkerClient extends base_1.BaseClient {
180
189
  await shard.connect();
181
190
  }
182
191
  break;
183
- case 'SPAWN_SHARDS':
192
+ case 'SPAWN_SHARDS_RESHARDING':
184
193
  {
185
- const onPacket = this.onPacket.bind(this);
186
- const handlePayload = this.options?.handlePayload?.bind(this);
194
+ let shardsConnected = 0;
187
195
  const self = this;
188
- const { sendPayloadToParent } = this.options;
189
196
  for (const id of workerData.shards) {
190
- let shard = this.shards.get(id);
191
- if (!shard) {
192
- shard = new websocket_1.Shard(id, {
193
- token: workerData.token,
194
- intents: workerData.intents,
195
- info: data.info,
196
- compress: data.compress,
197
- debugger: this.debugger,
198
- properties: {
199
- ...websocket_1.properties,
200
- ...this.options.gateway?.properties,
201
- },
202
- async handlePayload(shardId, payload) {
203
- await handlePayload?.(shardId, payload);
204
- await onPacket(payload, shardId);
205
- if (sendPayloadToParent)
197
+ const existsShard = this.resharding.has(id);
198
+ if (existsShard) {
199
+ this.logger.warn(`Trying to re-spawn existing shard #${id}`);
200
+ continue;
201
+ }
202
+ const shard = new websocket_1.Shard(id, {
203
+ token: workerData.token,
204
+ intents: workerData.intents,
205
+ info: data.info,
206
+ compress: data.compress,
207
+ debugger: this.debugger,
208
+ properties: {
209
+ ...websocket_1.properties,
210
+ ...this.options.gateway?.properties,
211
+ },
212
+ handlePayload(_, payload) {
213
+ if (payload.t === 'GUILD_CREATE' || payload.t === 'GUILD_DELETE') {
214
+ self.__handleGuildsResharding.delete(payload.d.id);
215
+ if (!self.__handleGuildsResharding?.size && shardsConnected === workerData.shards.length) {
216
+ delete self.__handleGuildsResharding;
206
217
  self.postMessage({
218
+ type: 'WORKER_READY_RESHARDING',
207
219
  workerId: workerData.workerId,
208
- shardId,
209
- type: 'RECEIVE_PAYLOAD',
210
- payload,
211
220
  });
212
- },
213
- });
214
- this.shards.set(id, shard);
221
+ }
222
+ }
223
+ if (payload.t !== 'READY')
224
+ return;
225
+ shardsConnected++;
226
+ for (const guild of payload.d.guilds) {
227
+ self.__handleGuildsResharding.add(guild.id);
228
+ }
229
+ if (shardsConnected === workerData.shards.length &&
230
+ !(0, common_1.hasIntent)(workerData.intents, types_1.GatewayIntentBits.Guilds)) {
231
+ delete self.__handleGuildsResharding;
232
+ self.postMessage({
233
+ type: 'WORKER_READY_RESHARDING',
234
+ workerId: workerData.workerId,
235
+ });
236
+ }
237
+ },
238
+ });
239
+ this.resharding.set(id, shard);
240
+ this.postMessage({
241
+ type: 'CONNECT_QUEUE_RESHARDING',
242
+ shardId: id,
243
+ workerId: workerData.workerId,
244
+ });
245
+ }
246
+ }
247
+ break;
248
+ case 'SPAWN_SHARDS':
249
+ {
250
+ const onPacket = this.onPacket.bind(this);
251
+ const handlePayload = this.options?.handlePayload?.bind(this);
252
+ const self = this;
253
+ for (const id of workerData.shards) {
254
+ const existsShard = this.shards.has(id);
255
+ if (existsShard) {
256
+ this.logger.warn(`Trying to spawn existing shard #${id}`);
257
+ continue;
215
258
  }
259
+ const shard = new websocket_1.Shard(id, {
260
+ token: workerData.token,
261
+ intents: workerData.intents,
262
+ info: data.info,
263
+ compress: data.compress,
264
+ debugger: this.debugger,
265
+ properties: {
266
+ ...websocket_1.properties,
267
+ ...this.options.gateway?.properties,
268
+ },
269
+ async handlePayload(shardId, payload) {
270
+ await handlePayload?.(shardId, payload);
271
+ await onPacket(payload, shardId);
272
+ if (self.options.sendPayloadToParent)
273
+ self.postMessage({
274
+ workerId: workerData.workerId,
275
+ shardId,
276
+ type: 'RECEIVE_PAYLOAD',
277
+ payload,
278
+ });
279
+ },
280
+ });
281
+ this.shards.set(id, shard);
216
282
  this.postMessage({
217
283
  type: 'CONNECT_QUEUE',
218
284
  shardId: id,
@@ -289,14 +355,47 @@ class WorkerClient extends base_1.BaseClient {
289
355
  evalResponse.resolve(data.response);
290
356
  }
291
357
  break;
358
+ case 'WORKER_ALREADY_EXISTS_RESHARDING':
359
+ {
360
+ this.__handleGuildsResharding = new Set();
361
+ this.postMessage({
362
+ type: 'WORKER_START_RESHARDING',
363
+ workerId: workerData.workerId,
364
+ });
365
+ }
366
+ break;
367
+ case 'DISCONNECT_ALL_SHARDS_RESHARDING':
368
+ {
369
+ for (const i of this.shards.values()) {
370
+ await i.disconnect();
371
+ }
372
+ this.postMessage({
373
+ type: 'DISCONNECTED_ALL_SHARDS_RESHARDING',
374
+ workerId: workerData.workerId,
375
+ });
376
+ }
377
+ break;
378
+ case 'CONNECT_ALL_SHARDS_RESHARDING':
379
+ {
380
+ this.shards.clear();
381
+ const handlePayload = this.options?.handlePayload?.bind(this);
382
+ for (const [id, shard] of this.resharding) {
383
+ this.shards.set(id, shard);
384
+ shard.options.handlePayload = async (shardId, packet) => {
385
+ await handlePayload?.(shardId, packet);
386
+ return this.onPacket(packet, shardId);
387
+ };
388
+ }
389
+ this.resharding.clear();
390
+ }
391
+ break;
292
392
  }
293
393
  }
294
- generateNonce(large = true) {
394
+ generateNonce() {
295
395
  const uuid = (0, node_crypto_1.randomUUID)();
296
- const nonce = large ? uuid : uuid.split('-')[0];
297
- if (this.promises.has(nonce))
298
- return this.generateNonce(large);
299
- return nonce;
396
+ if (this.promises.has(uuid))
397
+ return this.generateNonce();
398
+ return uuid;
300
399
  }
301
400
  generateSendPromise(nonce, message = 'Timeout') {
302
401
  return new Promise((res, rej) => {
@@ -364,42 +463,48 @@ class WorkerClient extends base_1.BaseClient {
364
463
  default: {
365
464
  switch (packet.t) {
366
465
  case 'INTERACTION_CREATE':
367
- await this.events?.execute(packet.t, packet, this, shardId);
368
- await this.handleCommand.interaction(packet.d, shardId);
466
+ {
467
+ await this.events?.execute(packet.t, packet, this, shardId);
468
+ await this.handleCommand.interaction(packet.d, shardId);
469
+ }
369
470
  break;
370
471
  case 'MESSAGE_CREATE':
371
- await this.events?.execute(packet.t, packet, this, shardId);
372
- await this.handleCommand.message(packet.d, shardId);
472
+ {
473
+ await this.events?.execute(packet.t, packet, this, shardId);
474
+ await this.handleCommand.message(packet.d, shardId);
475
+ }
373
476
  break;
374
477
  case 'READY':
375
- if (!this.__handleGuilds)
376
- this.__handleGuilds = new Set();
377
- for (const g of packet.d.guilds) {
378
- this.__handleGuilds?.add(g.id);
379
- }
380
- this.botId = packet.d.user.id;
381
- this.applicationId = packet.d.application.id;
382
- this.me = transformers_1.Transformers.ClientUser(this, packet.d.user, packet.d.application);
383
- await this.events?.execute(packet.t, packet, this, shardId);
384
- if ([...this.shards.values()].every(shard => shard.data.session_id)) {
385
- this.postMessage({
386
- type: 'WORKER_SHARDS_CONNECTED',
387
- workerId: this.workerId,
388
- });
389
- await this.events?.runEvent('WORKER_SHARDS_CONNECTED', this, this.me, -1);
390
- }
391
- if (!(this.__handleGuilds?.size &&
392
- (workerData.intents & types_1.GatewayIntentBits.Guilds) === types_1.GatewayIntentBits.Guilds)) {
393
- if ([...this.shards.values()].every(shard => shard.data.session_id)) {
478
+ {
479
+ if (!this.__handleGuilds)
480
+ this.__handleGuilds = new Set();
481
+ for (const g of packet.d.guilds) {
482
+ this.__handleGuilds?.add(g.id);
483
+ }
484
+ this.botId = packet.d.user.id;
485
+ this.applicationId = packet.d.application.id;
486
+ this.me = transformers_1.Transformers.ClientUser(this, packet.d.user, packet.d.application);
487
+ await this.events?.execute(packet.t, packet, this, shardId);
488
+ if (!this._ready && [...this.shards.values()].every(shard => shard.data.session_id)) {
489
+ this._ready = true;
394
490
  this.postMessage({
395
- type: 'WORKER_READY',
491
+ type: 'WORKER_SHARDS_CONNECTED',
396
492
  workerId: this.workerId,
397
493
  });
398
- await this.events?.runEvent('WORKER_READY', this, this.me, -1);
494
+ await this.events?.runEvent('WORKER_SHARDS_CONNECTED', this, this.me, -1);
495
+ }
496
+ if (!(0, common_1.hasIntent)(workerData.intents, types_1.GatewayIntentBits.Guilds)) {
497
+ if ([...this.shards.values()].every(shard => shard.data.session_id)) {
498
+ this.postMessage({
499
+ type: 'WORKER_READY',
500
+ workerId: this.workerId,
501
+ });
502
+ await this.events?.runEvent('WORKER_READY', this, this.me, -1);
503
+ }
504
+ delete this.__handleGuilds;
399
505
  }
400
- delete this.__handleGuilds;
506
+ this.debugger?.debug(`#${shardId}[${packet.d.user.username}](${this.botId}) is online...`);
401
507
  }
402
- this.debugger?.debug(`#${shardId}[${packet.d.user.username}](${this.botId}) is online...`);
403
508
  break;
404
509
  default:
405
510
  await this.events?.execute(packet.t, packet, this, shardId);
@@ -229,9 +229,9 @@ export declare class LimitedCollection<K, V> {
229
229
  private resetTimeout;
230
230
  private stopTimeout;
231
231
  private startTimeout;
232
- keys(): IterableIterator<K>;
233
- values(): IterableIterator<LimitedCollectionData<V>>;
234
- entries(): IterableIterator<[K, LimitedCollectionData<V>]>;
232
+ keys(): MapIterator<K>;
233
+ values(): MapIterator<LimitedCollectionData<V>>;
234
+ entries(): MapIterator<[K, LimitedCollectionData<V>]>;
235
235
  clear(): void;
236
236
  private clearExpired;
237
237
  }
@@ -1,12 +1,12 @@
1
- import { ApplicationCommandOptionType, ApplicationCommandType, type ApplicationIntegrationType, type InteractionContextType, type APIApplicationCommandBasicOption, type APIApplicationCommandOption, type LocaleString } from '../../types';
2
1
  import type { PermissionStrings, SeyfertNumberOption, SeyfertStringOption } from '../..';
3
2
  import type { Attachment } from '../../builders';
3
+ import type { GuildRoleStructure, InteractionGuildMemberStructure, UserStructure } from '../../client/transformers';
4
4
  import { type Awaitable, type FlatObjectKeys } from '../../common';
5
5
  import type { AllChannels, AutocompleteInteraction } from '../../structures';
6
+ import { type APIApplicationCommandBasicOption, type APIApplicationCommandOption, ApplicationCommandOptionType, ApplicationCommandType, type ApplicationIntegrationType, type InteractionContextType, type LocaleString } from '../../types';
6
7
  import type { Groups, RegisteredMiddlewares } from '../decorators';
7
8
  import type { CommandContext } from './chatcontext';
8
9
  import type { DefaultLocale, ExtraProps, IgnoreCommand, OKFunction, OnOptionsReturnObject, StopFunction, UsingClient } from './shared';
9
- import type { GuildRoleStructure, InteractionGuildMemberStructure, UserStructure } from '../../client/transformers';
10
10
  export interface ReturnOptionsTypes {
11
11
  1: never;
12
12
  2: never;
@@ -150,6 +150,6 @@ export declare abstract class SubCommand extends BaseCommand {
150
150
  contexts: BaseCommand["contexts"];
151
151
  integration_types: BaseCommand["integrationTypes"];
152
152
  };
153
- abstract run(context: CommandContext<any>): any;
153
+ abstract run(context: CommandContext): any;
154
154
  }
155
155
  export {};
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SubCommand = exports.Command = exports.BaseCommand = void 0;
4
- const types_1 = require("../../types");
5
- const common_1 = require("../../common");
6
4
  const node_util_1 = require("node:util");
5
+ const common_1 = require("../../common");
6
+ const types_1 = require("../../types");
7
7
  class BaseCommand {
8
8
  middlewares = [];
9
9
  __filePath;
@@ -89,13 +89,12 @@ class BaseCommand {
89
89
  running = false;
90
90
  return res({ pass: true });
91
91
  };
92
- function next(obj) {
92
+ function next(...args) {
93
93
  if (!running) {
94
94
  return;
95
95
  }
96
- if (arguments.length) {
97
- // @ts-expect-error
98
- context[global ? 'globalMetadata' : 'metadata'][middlewares[index]] = obj;
96
+ if (args.length) {
97
+ context[global ? 'globalMetadata' : 'metadata'][middlewares[index]] = args[0];
99
98
  }
100
99
  if (++index >= middlewares.length) {
101
100
  running = false;
@@ -1,4 +1,5 @@
1
- import type { AllChannels, InferWithPrefix, Message, ReturnCache } from '../..';
1
+ import type { AllChannels, InferWithPrefix, ReturnCache } from '../..';
2
+ import type { GuildMemberStructure, GuildStructure, InteractionGuildMemberStructure, MessageStructure, OptionResolverStructure, WebhookMessageStructure } from '../../client/transformers';
2
3
  import type { If, UnionToTuple, When } from '../../common';
3
4
  import type { InteractionCreateBodyRequest, InteractionMessageUpdateBodyRequest } from '../../common/types/write';
4
5
  import { ChatInputCommandInteraction } from '../../structures';
@@ -6,7 +7,6 @@ import { BaseContext } from '../basecontext';
6
7
  import type { RegisteredMiddlewares } from '../decorators';
7
8
  import type { Command, ContextOptions, OptionsRecord, SubCommand } from './chat';
8
9
  import type { CommandMetadata, ExtendContext, GlobalMetadata, UsingClient } from './shared';
9
- import type { GuildMemberStructure, GuildStructure, InteractionGuildMemberStructure, MessageStructure, OptionResolverStructure, WebhookMessageStructure } from '../../client/transformers';
10
10
  export interface CommandContext<T extends OptionsRecord = {}, M extends keyof RegisteredMiddlewares = never> extends BaseContext, ExtendContext {
11
11
  }
12
12
  export declare class CommandContext<T extends OptionsRecord = {}, M extends keyof RegisteredMiddlewares = never> extends BaseContext {
@@ -26,11 +26,11 @@ export declare class CommandContext<T extends OptionsRecord = {}, M extends keyo
26
26
  get(locale?: string): import("./shared").DefaultLocale;
27
27
  };
28
28
  get fullCommandName(): string;
29
- write<FR extends boolean = false>(body: InteractionCreateBodyRequest, fetchReply?: FR): Promise<When<FR, WebhookMessageStructure | MessageStructure, void | WebhookMessageStructure | MessageStructure>>;
30
- deferReply(ephemeral?: boolean): Promise<void | Message>;
31
- editResponse(body: InteractionMessageUpdateBodyRequest): Promise<Message | import("../..").WebhookMessage>;
29
+ write<WR extends boolean = false>(body: InteractionCreateBodyRequest, withResponse?: WR): Promise<When<WR, WebhookMessageStructure | When<InferWithPrefix, MessageStructure, never>, void | WebhookMessageStructure | When<InferWithPrefix, MessageStructure, never>>>;
30
+ deferReply<WR extends boolean = false>(ephemeral?: boolean, withResponse?: WR): Promise<When<WR, WebhookMessageStructure | When<InferWithPrefix, MessageStructure, never>, When<InferWithPrefix, MessageStructure, never> | undefined>>;
31
+ editResponse(body: InteractionMessageUpdateBodyRequest): Promise<When<InferWithPrefix, WebhookMessageStructure | MessageStructure, WebhookMessageStructure>>;
32
32
  deleteResponse(): Promise<void>;
33
- editOrReply<FR extends boolean = false>(body: InteractionCreateBodyRequest | InteractionMessageUpdateBodyRequest, fetchReply?: FR): Promise<When<FR, WebhookMessageStructure | MessageStructure, void | WebhookMessageStructure | MessageStructure>>;
33
+ editOrReply<WR extends boolean = false>(body: InteractionCreateBodyRequest | InteractionMessageUpdateBodyRequest, withResponse?: WR): Promise<When<WR, WebhookMessageStructure | When<InferWithPrefix, MessageStructure, never>, void | WebhookMessageStructure | When<InferWithPrefix, MessageStructure, never>>>;
34
34
  fetchResponse(): Promise<If<InferWithPrefix, WebhookMessageStructure | MessageStructure | undefined, WebhookMessageStructure | undefined>>;
35
35
  channel(mode?: 'rest' | 'flow'): Promise<If<InferWithPrefix, AllChannels | undefined, AllChannels>>;
36
36
  channel(mode?: 'cache'): ReturnCache<If<InferWithPrefix, AllChannels | undefined, AllChannels>>;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CommandContext = void 0;
4
- const types_1 = require("../../types");
5
4
  const structures_1 = require("../../structures");
5
+ const types_1 = require("../../types");
6
6
  const basecontext_1 = require("../basecontext");
7
7
  class CommandContext extends basecontext_1.BaseContext {
8
8
  client;
@@ -37,21 +37,29 @@ class CommandContext extends basecontext_1.BaseContext {
37
37
  get fullCommandName() {
38
38
  return this.resolver.fullCommandName;
39
39
  }
40
- async write(body, fetchReply) {
40
+ async write(body, withResponse) {
41
41
  if (this.interaction)
42
- return this.interaction.write(body, fetchReply);
42
+ return this.interaction.write(body, withResponse);
43
43
  const options = this.client.options?.commands;
44
44
  return (this.messageResponse = await this.message[!this.messageResponse && options?.reply?.(this) ? 'reply' : 'write'](body));
45
45
  }
46
- async deferReply(ephemeral = false) {
46
+ async deferReply(ephemeral = false, withResponse) {
47
47
  if (this.interaction)
48
- return this.interaction.deferReply(ephemeral ? types_1.MessageFlags.Ephemeral : undefined);
48
+ return this.interaction.deferReply(ephemeral ? types_1.MessageFlags.Ephemeral : undefined, withResponse);
49
+ this.__deferred = true;
49
50
  const options = this.client.options?.commands;
50
51
  return (this.messageResponse = await this.message[options?.reply?.(this) ? 'reply' : 'write'](options?.deferReplyResponse?.(this) ?? { content: 'Thinking...' }));
51
52
  }
52
53
  async editResponse(body) {
53
54
  if (this.interaction)
54
55
  return this.interaction.editResponse(body);
56
+ if (this.__deferred && !this.__edited) {
57
+ this.__edited = true;
58
+ if (this.messageResponse?.content)
59
+ body.content ??= '';
60
+ if (this.messageResponse?.embeds.length)
61
+ body.embeds ??= [];
62
+ }
55
63
  return (this.messageResponse = await this.messageResponse.edit(body));
56
64
  }
57
65
  deleteResponse() {
@@ -59,13 +67,13 @@ class CommandContext extends basecontext_1.BaseContext {
59
67
  return this.interaction.deleteResponse();
60
68
  return this.messageResponse.delete();
61
69
  }
62
- editOrReply(body, fetchReply) {
70
+ editOrReply(body, withResponse) {
63
71
  if (this.interaction)
64
- return this.interaction.editOrReply(body, fetchReply);
72
+ return this.interaction.editOrReply(body, withResponse);
65
73
  if (this.messageResponse) {
66
74
  return this.editResponse(body);
67
75
  }
68
- return this.write(body, fetchReply);
76
+ return this.write(body, withResponse);
69
77
  }
70
78
  async fetchResponse() {
71
79
  if (this.interaction)
@@ -1,5 +1,5 @@
1
1
  import { type PermissionStrings } from '../../common';
2
- import { ApplicationCommandType, type EntryPointCommandHandlerType, type ApplicationIntegrationType, type InteractionContextType, type LocaleString } from '../../types';
2
+ import { ApplicationCommandType, type ApplicationIntegrationType, type EntryPointCommandHandlerType, type InteractionContextType, type LocaleString } from '../../types';
3
3
  import type { RegisteredMiddlewares } from '../decorators';
4
4
  import type { EntryPointContext } from './entrycontext';
5
5
  import type { ExtraProps, UsingClient } from './shared';
@@ -1,11 +1,11 @@
1
1
  import type { ReturnCache } from '../..';
2
+ import type { GuildMemberStructure, GuildStructure, MessageStructure, WebhookMessageStructure } from '../../client/transformers';
2
3
  import type { InteractionCreateBodyRequest, InteractionMessageUpdateBodyRequest, ModalCreateBodyRequest, UnionToTuple, When } from '../../common';
3
4
  import type { AllChannels, EntryPointInteraction } from '../../structures';
4
5
  import { BaseContext } from '../basecontext';
5
6
  import type { RegisteredMiddlewares } from '../decorators';
6
- import type { CommandMetadata, ExtendContext, GlobalMetadata, UsingClient } from './shared';
7
- import type { GuildMemberStructure, GuildStructure, MessageStructure, WebhookMessageStructure } from '../../client/transformers';
8
7
  import type { EntryPointCommand } from './entryPoint';
8
+ import type { CommandMetadata, ExtendContext, GlobalMetadata, UsingClient } from './shared';
9
9
  export interface EntryPointContext<M extends keyof RegisteredMiddlewares = never> extends BaseContext, ExtendContext {
10
10
  }
11
11
  export declare class EntryPointContext<M extends keyof RegisteredMiddlewares = never> extends BaseContext {
@@ -20,12 +20,12 @@ export declare class EntryPointContext<M extends keyof RegisteredMiddlewares = n
20
20
  get(locale?: string): import("./shared").DefaultLocale;
21
21
  };
22
22
  get fullCommandName(): string;
23
- write<FR extends boolean = false>(body: InteractionCreateBodyRequest, fetchReply?: FR): Promise<When<FR, WebhookMessageStructure, void | WebhookMessageStructure>>;
24
- modal(body: ModalCreateBodyRequest): Promise<void>;
25
- deferReply(ephemeral?: boolean): Promise<void>;
23
+ write<WR extends boolean = false>(body: InteractionCreateBodyRequest, withResponse?: WR): Promise<When<WR, WebhookMessageStructure, void | WebhookMessageStructure>>;
24
+ modal(body: ModalCreateBodyRequest): Promise<undefined>;
25
+ deferReply<WR extends boolean = false>(ephemeral?: boolean): Promise<When<WR, WebhookMessageStructure, undefined>>;
26
26
  editResponse(body: InteractionMessageUpdateBodyRequest): Promise<import("../..").WebhookMessage>;
27
27
  deleteResponse(): Promise<void | undefined>;
28
- editOrReply<FR extends boolean = false>(body: InteractionCreateBodyRequest | InteractionMessageUpdateBodyRequest, fetchReply?: FR): Promise<When<FR, WebhookMessageStructure | MessageStructure, void | WebhookMessageStructure | MessageStructure>>;
28
+ editOrReply<WR extends boolean = false>(body: InteractionCreateBodyRequest | InteractionMessageUpdateBodyRequest, withResponse?: WR): Promise<When<WR, WebhookMessageStructure | MessageStructure, void | WebhookMessageStructure | MessageStructure>>;
29
29
  fetchResponse(): Promise<import("../..").WebhookMessage | undefined>;
30
30
  channel(mode?: 'rest' | 'flow'): Promise<AllChannels>;
31
31
  channel(mode?: 'cache'): ReturnCache<AllChannels>;
@@ -23,8 +23,8 @@ class EntryPointContext extends basecontext_1.BaseContext {
23
23
  get fullCommandName() {
24
24
  return this.command.name;
25
25
  }
26
- write(body, fetchReply) {
27
- return this.interaction.write(body, fetchReply);
26
+ write(body, withResponse) {
27
+ return this.interaction.write(body, withResponse);
28
28
  }
29
29
  modal(body) {
30
30
  return this.interaction.modal(body);
@@ -38,8 +38,8 @@ class EntryPointContext extends basecontext_1.BaseContext {
38
38
  deleteResponse() {
39
39
  return this.interaction.deleteResponse();
40
40
  }
41
- editOrReply(body, fetchReply) {
42
- return this.interaction.editOrReply(body, fetchReply);
41
+ editOrReply(body, withResponse) {
42
+ return this.interaction.editOrReply(body, withResponse);
43
43
  }
44
44
  fetchResponse() {
45
45
  return this.interaction.fetchResponse();
@@ -1,5 +1,5 @@
1
- import type { ApplicationCommandType, ApplicationIntegrationType, InteractionContextType, LocaleString } from '../../types';
2
1
  import { type PermissionStrings } from '../../common';
2
+ import type { ApplicationCommandType, ApplicationIntegrationType, InteractionContextType, LocaleString } from '../../types';
3
3
  import type { RegisteredMiddlewares } from '../decorators';
4
4
  import type { MenuCommandContext } from './menucontext';
5
5
  import type { ExtraProps, UsingClient } from './shared';
@@ -1,10 +1,10 @@
1
1
  import type { ContextMenuCommand, ReturnCache } from '../..';
2
+ import { type GuildMemberStructure, type GuildStructure, type MessageStructure, type UserStructure, type WebhookMessageStructure } from '../../client/transformers';
2
3
  import { type InteractionCreateBodyRequest, type InteractionMessageUpdateBodyRequest, type ModalCreateBodyRequest, type UnionToTuple, type When } from '../../common';
3
4
  import type { AllChannels, MessageCommandInteraction, UserCommandInteraction } from '../../structures';
4
5
  import { BaseContext } from '../basecontext';
5
6
  import type { RegisteredMiddlewares } from '../decorators';
6
7
  import type { CommandMetadata, ExtendContext, GlobalMetadata, UsingClient } from './shared';
7
- import { type GuildMemberStructure, type GuildStructure, type MessageStructure, type UserStructure, type WebhookMessageStructure } from '../../client/transformers';
8
8
  export type InteractionTarget<T> = T extends MessageCommandInteraction ? MessageStructure : UserStructure;
9
9
  export interface MenuCommandContext<T extends MessageCommandInteraction | UserCommandInteraction, M extends keyof RegisteredMiddlewares = never> extends BaseContext, ExtendContext {
10
10
  }
@@ -21,12 +21,12 @@ export declare class MenuCommandContext<T extends MessageCommandInteraction | Us
21
21
  get(locale?: string): import("./shared").DefaultLocale;
22
22
  };
23
23
  get fullCommandName(): string;
24
- write<FR extends boolean = false>(body: InteractionCreateBodyRequest, fetchReply?: FR): Promise<When<FR, WebhookMessageStructure, void | WebhookMessageStructure>>;
25
- modal(body: ModalCreateBodyRequest): Promise<void>;
26
- deferReply(ephemeral?: boolean): Promise<void>;
24
+ write<WR extends boolean = false>(body: InteractionCreateBodyRequest, withResponse?: WR): Promise<When<WR, WebhookMessageStructure, void | WebhookMessageStructure>>;
25
+ modal(body: ModalCreateBodyRequest): Promise<undefined>;
26
+ deferReply<WR extends boolean = false>(ephemeral?: boolean): Promise<When<WR, WebhookMessageStructure, undefined>>;
27
27
  editResponse(body: InteractionMessageUpdateBodyRequest): Promise<import("../..").WebhookMessage>;
28
28
  deleteResponse(): Promise<void | undefined>;
29
- editOrReply<FR extends boolean = false>(body: InteractionCreateBodyRequest | InteractionMessageUpdateBodyRequest, fetchReply?: FR): Promise<When<FR, WebhookMessageStructure | MessageStructure, void | WebhookMessageStructure | MessageStructure>>;
29
+ editOrReply<WR extends boolean = false>(body: InteractionCreateBodyRequest | InteractionMessageUpdateBodyRequest, withResponse?: WR): Promise<When<WR, WebhookMessageStructure | MessageStructure, void | WebhookMessageStructure | MessageStructure>>;
30
30
  fetchResponse(): Promise<import("../..").WebhookMessage | undefined>;
31
31
  channel(mode?: 'rest' | 'flow'): Promise<AllChannels>;
32
32
  channel(mode?: 'cache'): ReturnCache<AllChannels>;