seyfert 4.4.1 → 4.6.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 (180) hide show
  1. package/README.md +7 -1
  2. package/lib/api/Routes/guilds.d.ts +12 -1
  3. package/lib/api/Routes/index.d.ts +3 -1
  4. package/lib/api/Routes/invites.d.ts +1 -1
  5. package/lib/api/Routes/oauth2.d.ts +11 -0
  6. package/lib/api/Routes/oauth2.js +2 -0
  7. package/lib/api/Routes/skus.d.ts +11 -4
  8. package/lib/api/Routes/users.d.ts +2 -1
  9. package/lib/api/Routes/voice.d.ts +4 -0
  10. package/lib/api/Routes/webhooks.d.ts +1 -1
  11. package/lib/api/api.d.ts +15 -5
  12. package/lib/api/api.js +243 -114
  13. package/lib/api/bucket.js +13 -7
  14. package/lib/api/shared.d.ts +3 -1
  15. package/lib/api/utils/constants.d.ts +1 -1
  16. package/lib/api/utils/constants.js +1 -1
  17. package/lib/builders/Attachment.d.ts +6 -1
  18. package/lib/builders/Attachment.js +13 -9
  19. package/lib/builders/CheckboxGroup.js +1 -1
  20. package/lib/builders/FileUpload.d.ts +8 -1
  21. package/lib/builders/FileUpload.js +9 -0
  22. package/lib/builders/RadioGroup.js +1 -1
  23. package/lib/client/base.d.ts +3 -3
  24. package/lib/client/client.d.ts +1 -1
  25. package/lib/client/client.js +5 -4
  26. package/lib/client/collectors.d.ts +10 -8
  27. package/lib/client/transformers.d.ts +5 -0
  28. package/lib/client/workerclient.d.ts +8 -1
  29. package/lib/client/workerclient.js +34 -14
  30. package/lib/commands/applications/chat.d.ts +6 -4
  31. package/lib/commands/applications/options.d.ts +6 -4
  32. package/lib/commands/applications/shared.d.ts +2 -2
  33. package/lib/commands/handle.d.ts +7 -3
  34. package/lib/commands/handle.js +36 -11
  35. package/lib/commands/handler.js +11 -0
  36. package/lib/commands/optionresolver.d.ts +6 -7
  37. package/lib/common/it/error.d.ts +13 -0
  38. package/lib/common/it/error.js +15 -1
  39. package/lib/common/it/logger.js +12 -9
  40. package/lib/common/shorters/application.d.ts +1 -1
  41. package/lib/common/shorters/application.js +1 -1
  42. package/lib/common/shorters/bans.js +1 -1
  43. package/lib/common/shorters/guilds.js +5 -1
  44. package/lib/common/shorters/interaction.js +7 -4
  45. package/lib/common/shorters/invites.d.ts +5 -0
  46. package/lib/common/shorters/members.js +2 -1
  47. package/lib/common/shorters/messages.js +2 -2
  48. package/lib/common/shorters/threads.js +1 -1
  49. package/lib/common/shorters/webhook.js +3 -3
  50. package/lib/common/types/util.d.ts +7 -0
  51. package/lib/components/componentcommand.js +2 -2
  52. package/lib/components/customId.d.ts +3 -0
  53. package/lib/components/customId.js +11 -0
  54. package/lib/components/handler.js +2 -3
  55. package/lib/components/modalcommand.js +2 -2
  56. package/lib/events/hooks/invite.d.ts +1 -0
  57. package/lib/events/hooks/presence.d.ts +1 -0
  58. package/lib/events/hooks/thread.d.ts +1 -0
  59. package/lib/index.d.ts +1 -1
  60. package/lib/index.js +2 -1
  61. package/lib/structures/AnonymousGuild.d.ts +1 -1
  62. package/lib/structures/AnonymousGuild.js +1 -1
  63. package/lib/structures/Guild.d.ts +3 -0
  64. package/lib/structures/GuildMember.d.ts +2 -2
  65. package/lib/structures/GuildMember.js +22 -4
  66. package/lib/structures/GuildPreview.d.ts +1 -1
  67. package/lib/structures/GuildPreview.js +1 -1
  68. package/lib/structures/GuildRole.d.ts +13 -0
  69. package/lib/structures/GuildRole.js +21 -0
  70. package/lib/structures/GuildTemplate.js +1 -1
  71. package/lib/structures/Interaction.d.ts +7 -7
  72. package/lib/structures/Interaction.js +35 -21
  73. package/lib/structures/Message.d.ts +2 -1
  74. package/lib/structures/channels.d.ts +29 -16
  75. package/lib/structures/channels.js +59 -19
  76. package/lib/structures/extra/BaseGuild.d.ts +4 -4
  77. package/lib/structures/extra/BaseGuild.js +4 -4
  78. package/lib/types/gateway.d.ts +243 -239
  79. package/lib/types/index.d.ts +2 -2
  80. package/lib/types/payloads/_interactions/_applicationCommands/_chatInput/attachment.d.ts +5 -2
  81. package/lib/types/payloads/_interactions/_applicationCommands/_chatInput/shared.d.ts +2 -2
  82. package/lib/types/payloads/_interactions/_applicationCommands/_chatInput/shared.js +1 -1
  83. package/lib/types/payloads/_interactions/_applicationCommands/chatInput.d.ts +7 -7
  84. package/lib/types/payloads/_interactions/_applicationCommands/contextMenu.d.ts +13 -13
  85. package/lib/types/payloads/_interactions/_applicationCommands/permissions.d.ts +4 -4
  86. package/lib/types/payloads/_interactions/_applicationCommands/permissions.js +2 -2
  87. package/lib/types/payloads/_interactions/applicationCommands.d.ts +10 -10
  88. package/lib/types/payloads/_interactions/applicationCommands.js +4 -4
  89. package/lib/types/payloads/_interactions/autocomplete.d.ts +2 -2
  90. package/lib/types/payloads/_interactions/base.d.ts +13 -7
  91. package/lib/types/payloads/_interactions/modalSubmit.d.ts +4 -4
  92. package/lib/types/payloads/_interactions/responses.d.ts +10 -10
  93. package/lib/types/payloads/_interactions/responses.js +2 -2
  94. package/lib/types/payloads/application.d.ts +21 -15
  95. package/lib/types/payloads/application.js +7 -7
  96. package/lib/types/payloads/auditLog.d.ts +22 -17
  97. package/lib/types/payloads/auditLog.js +7 -2
  98. package/lib/types/payloads/autoModeration.d.ts +11 -11
  99. package/lib/types/payloads/autoModeration.js +5 -5
  100. package/lib/types/payloads/channel.d.ts +87 -78
  101. package/lib/types/payloads/channel.js +16 -11
  102. package/lib/types/payloads/components.d.ts +41 -31
  103. package/lib/types/payloads/components.js +9 -5
  104. package/lib/types/payloads/emoji.d.ts +2 -2
  105. package/lib/types/payloads/emoji.js +1 -1
  106. package/lib/types/payloads/gateway.d.ts +33 -29
  107. package/lib/types/payloads/gateway.js +5 -5
  108. package/lib/types/payloads/guild.d.ts +68 -68
  109. package/lib/types/payloads/guild.js +14 -14
  110. package/lib/types/payloads/guildScheduledEvent.d.ts +11 -11
  111. package/lib/types/payloads/guildScheduledEvent.js +3 -3
  112. package/lib/types/payloads/index.d.ts +2 -2
  113. package/lib/types/payloads/interactions.d.ts +3 -3
  114. package/lib/types/payloads/invite.d.ts +11 -11
  115. package/lib/types/payloads/invite.js +3 -3
  116. package/lib/types/payloads/monetization.d.ts +4 -4
  117. package/lib/types/payloads/monetization.js +2 -2
  118. package/lib/types/payloads/oauth2.d.ts +21 -17
  119. package/lib/types/payloads/oauth2.js +21 -17
  120. package/lib/types/payloads/permissions.d.ts +5 -5
  121. package/lib/types/payloads/permissions.js +2 -2
  122. package/lib/types/payloads/poll.d.ts +7 -7
  123. package/lib/types/payloads/poll.js +2 -2
  124. package/lib/types/payloads/soundboard.d.ts +2 -2
  125. package/lib/types/payloads/soundboard.js +1 -1
  126. package/lib/types/payloads/stageInstance.d.ts +5 -5
  127. package/lib/types/payloads/stageInstance.js +1 -1
  128. package/lib/types/payloads/sticker.d.ts +8 -8
  129. package/lib/types/payloads/sticker.js +3 -3
  130. package/lib/types/payloads/teams.d.ts +8 -8
  131. package/lib/types/payloads/teams.js +3 -3
  132. package/lib/types/payloads/template.d.ts +3 -3
  133. package/lib/types/payloads/template.js +1 -1
  134. package/lib/types/payloads/user.d.ts +24 -22
  135. package/lib/types/payloads/user.js +7 -5
  136. package/lib/types/payloads/voice.d.ts +4 -4
  137. package/lib/types/payloads/voice.js +1 -1
  138. package/lib/types/payloads/webhokEvents.d.ts +5 -5
  139. package/lib/types/payloads/webhokEvents.js +2 -2
  140. package/lib/types/payloads/webhook.d.ts +4 -4
  141. package/lib/types/payloads/webhook.js +1 -1
  142. package/lib/types/rest/application.d.ts +14 -14
  143. package/lib/types/rest/auditLog.d.ts +1 -1
  144. package/lib/types/rest/autoModeration.d.ts +7 -7
  145. package/lib/types/rest/channel.d.ts +79 -74
  146. package/lib/types/rest/channel.js +1 -1
  147. package/lib/types/rest/emoji.d.ts +8 -8
  148. package/lib/types/rest/gateway.d.ts +2 -2
  149. package/lib/types/rest/guild.d.ts +98 -98
  150. package/lib/types/rest/guild.js +5 -5
  151. package/lib/types/rest/guildScheduledEvent.d.ts +11 -11
  152. package/lib/types/rest/index.d.ts +34 -3
  153. package/lib/types/rest/index.js +33 -2
  154. package/lib/types/rest/interactions.d.ts +48 -48
  155. package/lib/types/rest/invite.d.ts +5 -5
  156. package/lib/types/rest/monetization.d.ts +9 -9
  157. package/lib/types/rest/monetization.js +1 -1
  158. package/lib/types/rest/oauth2.d.ts +22 -18
  159. package/lib/types/rest/poll.d.ts +4 -4
  160. package/lib/types/rest/soundboard.d.ts +8 -8
  161. package/lib/types/rest/stageInstance.d.ts +6 -6
  162. package/lib/types/rest/sticker.d.ts +10 -10
  163. package/lib/types/rest/template.d.ts +11 -11
  164. package/lib/types/rest/user.d.ts +18 -14
  165. package/lib/types/rest/voice.d.ts +5 -5
  166. package/lib/types/rest/webhook.d.ts +38 -38
  167. package/lib/types/utils/index.d.ts +19 -19
  168. package/lib/types/utils/index.js +19 -19
  169. package/lib/websocket/SharedTypes.d.ts +2 -2
  170. package/lib/websocket/constants/index.js +2 -2
  171. package/lib/websocket/discord/heartbeater.d.ts +1 -0
  172. package/lib/websocket/discord/heartbeater.js +8 -0
  173. package/lib/websocket/discord/shard.d.ts +19 -10
  174. package/lib/websocket/discord/shard.js +255 -122
  175. package/lib/websocket/discord/sharder.d.ts +2 -2
  176. package/lib/websocket/discord/sharder.js +2 -2
  177. package/lib/websocket/discord/shared.d.ts +7 -2
  178. package/lib/websocket/discord/workermanager.d.ts +3 -1
  179. package/lib/websocket/discord/workermanager.js +31 -24
  180. package/package.json +3 -3
@@ -85,9 +85,7 @@ class WorkerManager extends Map {
85
85
  }
86
86
  const id = workerId ?? this.calculateWorkerId(shardId);
87
87
  if (!this.has(id)) {
88
- throw new common_1.SeyfertError('WORKER_NOT_FOUND', {
89
- metadata: { ...{ workerId: id }, detail: `Worker #${id} doesn't exist` },
90
- });
88
+ throw this.createWorkerNotFoundError(id);
91
89
  }
92
90
  const data = await this.getWorkerInfo(id);
93
91
  return data.shards.reduce((acc, prv) => acc + prv.latency, 0) / data.shards.length;
@@ -95,22 +93,25 @@ class WorkerManager extends Map {
95
93
  calculateShardId(guildId) {
96
94
  return Number((BigInt(guildId) >> 22n) % BigInt(this.totalShards));
97
95
  }
96
+ createWorkerNotFoundError(workerId) {
97
+ return new common_1.SeyfertError('WORKER_NOT_FOUND', {
98
+ metadata: { workerId, detail: `Worker #${workerId} doesn't exist` },
99
+ });
100
+ }
98
101
  calculateWorkerId(shardId) {
99
- const workerId = Math.floor((shardId - this.shardStart) / this.shardsPerWorker);
100
- if (workerId >= this.totalWorkers) {
102
+ const minimumShardId = this.shardStart;
103
+ const maximumShardId = this.shardEnd - 1;
104
+ if (shardId < minimumShardId || shardId > maximumShardId) {
101
105
  throw new common_1.SeyfertError('INVALID_SHARD_ID', {
102
106
  metadata: {
103
- ...{
104
- shardId,
105
- shardStart: this.shardStart,
106
- shardsPerWorker: this.shardsPerWorker,
107
- totalWorkers: this.totalWorkers,
108
- },
109
- detail: 'Invalid shardId',
107
+ shardId,
108
+ minimumShardId,
109
+ maximumShardId,
110
+ detail: `Invalid shardId ${shardId}: expected ${minimumShardId}..${maximumShardId}.`,
110
111
  },
111
112
  });
112
113
  }
113
- return workerId;
114
+ return Math.floor((shardId - minimumShardId) / this.shardsPerWorker);
114
115
  }
115
116
  postMessage(id, body) {
116
117
  const worker = this.get(id);
@@ -185,6 +186,7 @@ class WorkerManager extends Map {
185
186
  metadata: { detail: 'Cannot create worker without worker_threads.' },
186
187
  });
187
188
  const env = {
189
+ ...this.options.workerEnv,
188
190
  SEYFERT_SPAWNING: 'true',
189
191
  };
190
192
  if (workerData.resharding)
@@ -196,7 +198,7 @@ class WorkerManager extends Map {
196
198
  switch (this.options.mode) {
197
199
  case 'threads': {
198
200
  const worker = new worker_threads.Worker(workerData.path, {
199
- env,
201
+ env: { ...process.env, ...env },
200
202
  });
201
203
  worker.on('message', data => this.handleWorkerMessage(data));
202
204
  worker.on('error', err => {
@@ -413,9 +415,12 @@ class WorkerManager extends Map {
413
415
  });
414
416
  }
415
417
  const response = await this.rest.request(message.method, message.url, message.requestOptions);
418
+ const encodedResponse = response instanceof ArrayBuffer ? Array.from(new Uint8Array(response)) : response;
419
+ const responseType = response instanceof ArrayBuffer ? 'arrayBuffer' : undefined;
416
420
  this.postMessage(message.workerId, {
417
421
  nonce: message.nonce,
418
- response,
422
+ response: encodedResponse,
423
+ responseType,
419
424
  type: 'API_RESPONSE',
420
425
  });
421
426
  }
@@ -442,7 +447,7 @@ class WorkerManager extends Map {
442
447
  toWorkerId: message.toWorkerId,
443
448
  vars: message.vars,
444
449
  });
445
- this.generateSendPromise(nonce, 'Eval timeout').then(val => this.postMessage(message.workerId, {
450
+ this.generateSendPromise(nonce, 'Worker evaluation').then(val => this.postMessage(message.workerId, {
446
451
  nonce: message.nonce,
447
452
  response: val,
448
453
  type: 'EVAL_RESPONSE',
@@ -457,11 +462,13 @@ class WorkerManager extends Map {
457
462
  return this.generateNonce();
458
463
  return uuid;
459
464
  }
460
- generateSendPromise(nonce, message = 'Timeout') {
465
+ generateSendPromise(nonce, operation = 'Worker request') {
461
466
  return new Promise((res, rej) => {
462
467
  const timeout = setTimeout(() => {
463
468
  this.promises.delete(nonce);
464
- rej(new common_1.SeyfertError('WORKER_TIMEOUT', { metadata: { ...{ nonce }, detail: message } }));
469
+ rej(new common_1.SeyfertError('WORKER_TIMEOUT', {
470
+ metadata: { nonce, operation, detail: `${operation} timed out (nonce: ${nonce}).` },
471
+ }));
465
472
  }, 60e3);
466
473
  this.promises.set(nonce, { resolve: res, timeout });
467
474
  });
@@ -470,7 +477,7 @@ class WorkerManager extends Map {
470
477
  const workerId = this.calculateWorkerId(shardId);
471
478
  const worker = this.has(workerId);
472
479
  if (!worker) {
473
- throw new common_1.SeyfertError('INTERNAL_ERROR', { metadata: { detail: `Worker #${workerId} doesn't exist` } });
480
+ throw this.createWorkerNotFoundError(workerId);
474
481
  }
475
482
  const nonce = this.generateNonce();
476
483
  this.postMessage(workerId, {
@@ -479,26 +486,26 @@ class WorkerManager extends Map {
479
486
  nonce,
480
487
  ...data,
481
488
  });
482
- return this.generateSendPromise(nonce, 'Shard send payload timeout');
489
+ return this.generateSendPromise(nonce, 'Shard payload send');
483
490
  }
484
491
  async getShardInfo(shardId) {
485
492
  const workerId = this.calculateWorkerId(shardId);
486
493
  const worker = this.has(workerId);
487
494
  if (!worker) {
488
- throw new common_1.SeyfertError('INTERNAL_ERROR', { metadata: { detail: `Worker #${workerId} doesn't exist` } });
495
+ throw this.createWorkerNotFoundError(workerId);
489
496
  }
490
497
  const nonce = this.generateNonce();
491
498
  this.postMessage(workerId, { shardId, nonce, type: 'SHARD_INFO' });
492
- return this.generateSendPromise(nonce, 'Get shard info timeout');
499
+ return this.generateSendPromise(nonce, 'Shard info request');
493
500
  }
494
501
  async getWorkerInfo(workerId) {
495
502
  const worker = this.has(workerId);
496
503
  if (!worker) {
497
- throw new common_1.SeyfertError('INTERNAL_ERROR', { metadata: { detail: `Worker #${workerId} doesn't exist` } });
504
+ throw this.createWorkerNotFoundError(workerId);
498
505
  }
499
506
  const nonce = this.generateNonce();
500
507
  this.postMessage(workerId, { nonce, type: 'WORKER_INFO' });
501
- return this.generateSendPromise(nonce, 'Get worker info timeout');
508
+ return this.generateSendPromise(nonce, 'Worker info request');
502
509
  }
503
510
  tellWorker(workerId, func, vars) {
504
511
  const nonce = this.generateNonce();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "seyfert",
3
- "version": "4.4.1",
3
+ "version": "4.6.0",
4
4
  "description": "The most advanced framework for discord bots",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",
@@ -28,7 +28,7 @@
28
28
  "@types/node": "^24.10.0",
29
29
  "husky": "^9.1.7",
30
30
  "typescript": "^5.9.3",
31
- "vitest": "^3.2.4"
31
+ "vitest": "^4.1.10"
32
32
  },
33
33
  "homepage": "https://seyfert.dev",
34
34
  "repository": {
@@ -70,4 +70,4 @@
70
70
  "esbuild"
71
71
  ]
72
72
  }
73
- }
73
+ }