seyfert 0.1.0 → 1.0.1

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 (198) hide show
  1. package/README.md +19 -30
  2. package/lib/api/CDN.d.ts +0 -8
  3. package/lib/api/CDN.js +7 -13
  4. package/lib/api/Router.d.ts +2 -2
  5. package/lib/api/Router.js +1 -1
  6. package/lib/api/Routes/applications.d.ts +1 -1
  7. package/lib/api/Routes/channels.d.ts +1 -1
  8. package/lib/api/Routes/gateway.d.ts +1 -1
  9. package/lib/api/Routes/guilds.d.ts +1 -1
  10. package/lib/api/Routes/interactions.d.ts +1 -1
  11. package/lib/api/Routes/invites.d.ts +1 -1
  12. package/lib/api/Routes/stage-instances.d.ts +1 -1
  13. package/lib/api/Routes/stickers.d.ts +1 -1
  14. package/lib/api/Routes/users.d.ts +1 -1
  15. package/lib/api/Routes/voice.d.ts +1 -1
  16. package/lib/api/Routes/webhooks.d.ts +1 -1
  17. package/lib/api/api.d.ts +44 -0
  18. package/lib/api/api.js +354 -0
  19. package/lib/api/bucket.d.ts +19 -0
  20. package/lib/api/bucket.js +71 -0
  21. package/lib/api/index.d.ts +1 -1
  22. package/lib/api/index.js +1 -1
  23. package/lib/api/shared.d.ts +33 -5
  24. package/lib/api/shared.js +2 -7
  25. package/lib/api/utils/constants.d.ts +1 -30
  26. package/lib/api/utils/constants.js +2 -41
  27. package/lib/api/utils/types.d.ts +1 -320
  28. package/lib/api/utils/utils.d.ts +0 -38
  29. package/lib/api/utils/utils.js +1 -139
  30. package/lib/builders/ActionRow.js +1 -1
  31. package/lib/builders/Attachment.d.ts +14 -6
  32. package/lib/builders/Attachment.js +30 -7
  33. package/lib/builders/Button.d.ts +5 -14
  34. package/lib/builders/Button.js +0 -11
  35. package/lib/builders/{MessageEmbed.d.ts → Embed.d.ts} +15 -15
  36. package/lib/builders/{MessageEmbed.js → Embed.js} +16 -16
  37. package/lib/builders/Modal.js +1 -1
  38. package/lib/builders/SelectMenu.d.ts +14 -15
  39. package/lib/builders/SelectMenu.js +19 -18
  40. package/lib/builders/index.d.ts +1 -1
  41. package/lib/builders/index.js +1 -1
  42. package/lib/builders/types.d.ts +2 -2
  43. package/lib/cache/adapters/default.d.ts +1 -0
  44. package/lib/cache/adapters/default.js +3 -2
  45. package/lib/cache/adapters/redis.d.ts +3 -3
  46. package/lib/cache/adapters/redis.js +14 -5
  47. package/lib/cache/adapters/types.d.ts +1 -0
  48. package/lib/cache/adapters/workeradapter.d.ts +10 -1
  49. package/lib/cache/adapters/workeradapter.js +8 -3
  50. package/lib/cache/index.d.ts +18 -5
  51. package/lib/cache/index.js +23 -9
  52. package/lib/cache/resources/channels.d.ts +6 -2
  53. package/lib/cache/resources/channels.js +12 -6
  54. package/lib/cache/resources/default/base.d.ts +17 -16
  55. package/lib/cache/resources/default/base.js +25 -24
  56. package/lib/cache/resources/default/guild-based.d.ts +22 -19
  57. package/lib/cache/resources/default/guild-based.js +32 -31
  58. package/lib/cache/resources/default/guild-related.d.ts +22 -19
  59. package/lib/cache/resources/default/guild-related.js +37 -43
  60. package/lib/cache/resources/emojis.d.ts +4 -2
  61. package/lib/cache/resources/emojis.js +8 -6
  62. package/lib/cache/resources/guilds.d.ts +4 -2
  63. package/lib/cache/resources/guilds.js +15 -8
  64. package/lib/cache/resources/members.d.ts +4 -2
  65. package/lib/cache/resources/members.js +16 -13
  66. package/lib/cache/resources/overwrites.d.ts +25 -0
  67. package/lib/cache/resources/overwrites.js +39 -0
  68. package/lib/cache/resources/presence.js +3 -4
  69. package/lib/cache/resources/roles.d.ts +4 -2
  70. package/lib/cache/resources/roles.js +8 -6
  71. package/lib/cache/resources/stickers.d.ts +4 -2
  72. package/lib/cache/resources/stickers.js +8 -6
  73. package/lib/cache/resources/threads.d.ts +4 -2
  74. package/lib/cache/resources/threads.js +8 -6
  75. package/lib/cache/resources/users.d.ts +4 -2
  76. package/lib/cache/resources/users.js +8 -6
  77. package/lib/cache/resources/voice-states.d.ts +3 -3
  78. package/lib/cache/resources/voice-states.js +6 -7
  79. package/lib/client/base.d.ts +48 -16
  80. package/lib/client/base.js +19 -15
  81. package/lib/client/client.d.ts +15 -4
  82. package/lib/client/client.js +26 -28
  83. package/lib/client/httpclient.d.ts +3 -5
  84. package/lib/client/httpclient.js +29 -16
  85. package/lib/client/{oninteraction.d.ts → oninteractioncreate.d.ts} +1 -1
  86. package/lib/client/{oninteraction.js → oninteractioncreate.js} +34 -23
  87. package/lib/client/onmessagecreate.d.ts +3 -0
  88. package/lib/client/onmessagecreate.js +337 -0
  89. package/lib/client/workerclient.d.ts +19 -2
  90. package/lib/client/workerclient.js +156 -46
  91. package/lib/collection.d.ts +1 -1
  92. package/lib/collection.js +9 -6
  93. package/lib/commands/applications/chat.d.ts +32 -25
  94. package/lib/commands/applications/chat.js +51 -34
  95. package/lib/commands/applications/chatcontext.d.ts +34 -16
  96. package/lib/commands/applications/chatcontext.js +99 -20
  97. package/lib/commands/applications/menu.d.ts +9 -8
  98. package/lib/commands/applications/menu.js +14 -5
  99. package/lib/commands/applications/menucontext.d.ts +27 -10
  100. package/lib/commands/applications/menucontext.js +51 -7
  101. package/lib/commands/applications/options.d.ts +13 -13
  102. package/lib/commands/applications/shared.d.ts +7 -2
  103. package/lib/commands/decorators.d.ts +14 -14
  104. package/lib/commands/decorators.js +9 -5
  105. package/lib/commands/handler.d.ts +2 -1
  106. package/lib/commands/handler.js +60 -14
  107. package/lib/commands/index.d.ts +1 -1
  108. package/lib/commands/index.js +2 -1
  109. package/lib/commands/optionresolver.d.ts +6 -5
  110. package/lib/commands/optionresolver.js +10 -6
  111. package/lib/common/bot/watcher.d.ts +3 -3
  112. package/lib/common/bot/watcher.js +3 -1
  113. package/lib/common/index.d.ts +1 -1
  114. package/lib/common/index.js +2 -1
  115. package/lib/common/it/logger.d.ts +11 -0
  116. package/lib/common/it/logger.js +51 -2
  117. package/lib/common/it/utils.d.ts +3 -13
  118. package/lib/common/it/utils.js +9 -30
  119. package/lib/common/shorters/channels.d.ts +55 -5
  120. package/lib/common/shorters/channels.js +59 -0
  121. package/lib/common/shorters/guilds.d.ts +5 -2
  122. package/lib/common/shorters/guilds.js +18 -0
  123. package/lib/common/shorters/messages.js +0 -2
  124. package/lib/common/shorters/overwrites.d.ts +29 -0
  125. package/lib/common/shorters/overwrites.js +63 -0
  126. package/lib/common/shorters/roles.js +3 -3
  127. package/lib/common/shorters/webhook.d.ts +2 -2
  128. package/lib/common/types/util.d.ts +3 -2
  129. package/lib/common/types/write.d.ts +3 -7
  130. package/lib/components/handler.d.ts +11 -17
  131. package/lib/components/handler.js +45 -93
  132. package/lib/components/index.d.ts +0 -1
  133. package/lib/components/index.js +0 -1
  134. package/lib/components/listener.d.ts +2 -2
  135. package/lib/components/listener.js +2 -3
  136. package/lib/events/event.d.ts +2 -2
  137. package/lib/events/handler.d.ts +3 -2
  138. package/lib/events/handler.js +14 -6
  139. package/lib/events/hooks/dispatch.d.ts +2 -1
  140. package/lib/events/hooks/dispatch.js +5 -1
  141. package/lib/events/hooks/thread.d.ts +63 -63
  142. package/lib/index.d.ts +8 -5
  143. package/lib/index.js +20 -10
  144. package/lib/langs/handler.d.ts +6 -4
  145. package/lib/langs/handler.js +10 -8
  146. package/lib/langs/router.d.ts +8 -9
  147. package/lib/langs/router.js +5 -5
  148. package/lib/structures/ClientUser.d.ts +1 -16
  149. package/lib/structures/ClientUser.js +0 -31
  150. package/lib/structures/Guild.d.ts +1 -1
  151. package/lib/structures/GuildMember.d.ts +12 -0
  152. package/lib/structures/GuildMember.js +14 -0
  153. package/lib/structures/GuildRole.d.ts +4 -2
  154. package/lib/structures/GuildRole.js +4 -1
  155. package/lib/structures/GuildTemplate.js +1 -1
  156. package/lib/structures/Interaction.d.ts +2 -0
  157. package/lib/structures/Interaction.js +12 -13
  158. package/lib/structures/Message.d.ts +7 -2
  159. package/lib/structures/Message.js +6 -3
  160. package/lib/structures/Sticker.d.ts +1 -1
  161. package/lib/structures/Sticker.js +1 -1
  162. package/lib/structures/User.d.ts +5 -0
  163. package/lib/structures/User.js +3 -0
  164. package/lib/structures/Webhook.d.ts +1 -1
  165. package/lib/structures/Webhook.js +1 -1
  166. package/lib/structures/channels.d.ts +45 -6
  167. package/lib/structures/channels.js +23 -7
  168. package/lib/structures/extra/BitField.d.ts +9 -6
  169. package/lib/structures/extra/BitField.js +27 -3
  170. package/lib/structures/extra/Permissions.d.ts +6 -1
  171. package/lib/structures/extra/Permissions.js +7 -0
  172. package/lib/websocket/constants/index.js +1 -3
  173. package/lib/websocket/discord/basesocket.js +0 -1
  174. package/lib/websocket/discord/shared.d.ts +2 -0
  175. package/lib/websocket/discord/worker.d.ts +23 -7
  176. package/lib/websocket/discord/workermanager.d.ts +32 -5
  177. package/lib/websocket/discord/workermanager.js +98 -29
  178. package/package.json +23 -21
  179. package/lib/api/REST.d.ts +0 -127
  180. package/lib/api/REST.js +0 -424
  181. package/lib/api/errors/DiscordAPIError.d.ts +0 -51
  182. package/lib/api/errors/DiscordAPIError.js +0 -81
  183. package/lib/api/errors/HTTPError.d.ts +0 -20
  184. package/lib/api/errors/HTTPError.js +0 -28
  185. package/lib/api/errors/RateLimitError.d.ts +0 -19
  186. package/lib/api/errors/RateLimitError.js +0 -37
  187. package/lib/api/handlers/BurstHandler.d.ts +0 -51
  188. package/lib/api/handlers/BurstHandler.js +0 -124
  189. package/lib/api/handlers/SequentialHandler.d.ts +0 -81
  190. package/lib/api/handlers/SequentialHandler.js +0 -365
  191. package/lib/api/handlers/Shared.d.ts +0 -14
  192. package/lib/api/handlers/Shared.js +0 -125
  193. package/lib/api/interfaces/Handler.d.ts +0 -21
  194. package/lib/api/interfaces/Handler.js +0 -2
  195. package/lib/websocket/discord/handlemessage.d.ts +0 -0
  196. package/lib/websocket/discord/handlemessage.js +0 -1
  197. package/lib/websocket/discord/memberUpdate.d.ts +0 -16
  198. package/lib/websocket/discord/memberUpdate.js +0 -47
@@ -2,14 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Client = void 0;
4
4
  const node_worker_threads_1 = require("node:worker_threads");
5
+ const common_1 = require("../common");
5
6
  const events_1 = require("../events");
6
7
  const structures_1 = require("../structures");
7
8
  const websocket_1 = require("../websocket");
8
9
  const memberUpdate_1 = require("../websocket/discord/events/memberUpdate");
9
10
  const presenceUpdate_1 = require("../websocket/discord/events/presenceUpdate");
10
11
  const base_1 = require("./base");
11
- const oninteraction_1 = require("./oninteraction");
12
+ const oninteractioncreate_1 = require("./oninteractioncreate");
13
+ const onmessagecreate_1 = require("./onmessagecreate");
12
14
  class Client extends base_1.BaseClient {
15
+ __handleGuilds = new Set();
13
16
  gateway;
14
17
  events = new events_1.EventHandler(this.logger);
15
18
  me;
@@ -67,13 +70,14 @@ class Client extends base_1.BaseClient {
67
70
  token,
68
71
  info: await this.proxy.gateway.bot.get(),
69
72
  intents,
70
- handlePayload: (shardId, packet) => {
73
+ handlePayload: async (shardId, packet) => {
74
+ await this.options?.handlePayload?.(shardId, packet);
71
75
  return this.onPacket(shardId, packet);
72
76
  },
73
77
  presence: this.options?.presence,
74
78
  debug: debugRC,
75
- shardStart: this.options?.shardStart,
76
- shardEnd: this.options?.shardEnd,
79
+ shardStart: this.options?.shards?.start,
80
+ shardEnd: this.options?.shards?.end,
77
81
  });
78
82
  }
79
83
  this.cache.intents = this.gateway.options.intents;
@@ -85,6 +89,7 @@ class Client extends base_1.BaseClient {
85
89
  }
86
90
  }
87
91
  async onPacket(shardId, packet) {
92
+ await this.events.runEvent('RAW', this, packet, shardId);
88
93
  switch (packet.t) {
89
94
  //// Cases where we must obtain the old data before updating
90
95
  case 'GUILD_MEMBER_UPDATE':
@@ -101,47 +106,40 @@ class Client extends base_1.BaseClient {
101
106
  await this.events.execute(packet.t, packet, this, shardId);
102
107
  await this.cache.onPacket(packet);
103
108
  break;
104
- case 'GUILD_DELETE':
105
- case 'CHANNEL_UPDATE': {
106
- await this.events.execute(packet.t, packet, this, shardId);
107
- await this.cache.onPacket(packet);
108
- break;
109
- }
110
109
  //rest of the events
111
110
  default: {
112
111
  await this.cache.onPacket(packet);
113
112
  switch (packet.t) {
113
+ case 'INTERACTION_CREATE':
114
+ await (0, oninteractioncreate_1.onInteractionCreate)(this, packet.d, shardId);
115
+ break;
116
+ case 'MESSAGE_CREATE':
117
+ await (0, onmessagecreate_1.onMessageCreate)(this, packet.d, shardId);
118
+ break;
114
119
  case 'READY':
115
120
  for (const g of packet.d.guilds) {
116
- this.__handleGuilds.add(g.id);
121
+ this.__handleGuilds?.add(g.id);
117
122
  }
118
123
  this.botId = packet.d.user.id;
119
124
  this.applicationId = packet.d.application.id;
120
125
  this.me = new structures_1.ClientUser(this, packet.d.user, packet.d.application);
121
- if (!this.__handleGuilds.size) {
122
- if ([...this.gateway.values()].every(shard => shard.data.session_id) &&
123
- this.events.values.BOT_READY &&
124
- (this.events.values.BOT_READY.fired ? !this.events.values.BOT_READY.data.once : true)) {
125
- this.events.values.BOT_READY.fired = true;
126
- await this.events.values.BOT_READY.run(this.me, this, -1);
126
+ if (!this.__handleGuilds?.size ||
127
+ !((this.gateway.options.intents & common_1.GatewayIntentBits.Guilds) === common_1.GatewayIntentBits.Guilds)) {
128
+ if ([...this.gateway.values()].every(shard => shard.data.session_id)) {
129
+ await this.events.runEvent('BOT_READY', this, this.me, -1);
127
130
  }
131
+ delete this.__handleGuilds;
128
132
  }
129
133
  this.debugger?.debug(`#${shardId}[${packet.d.user.username}](${this.botId}) is online...`);
130
134
  break;
131
- case 'INTERACTION_CREATE': {
132
- await (0, oninteraction_1.onInteraction)(shardId, packet.d, this);
133
- break;
134
- }
135
135
  case 'GUILD_CREATE': {
136
- if (this.__handleGuilds.has(packet.d.id)) {
136
+ if (this.__handleGuilds?.has(packet.d.id)) {
137
137
  this.__handleGuilds.delete(packet.d.id);
138
- if (!this.__handleGuilds.size &&
139
- [...this.gateway.values()].every(shard => shard.data.session_id) &&
140
- this.events.values.BOT_READY &&
141
- (this.events.values.BOT_READY.fired ? !this.events.values.BOT_READY.data.once : true)) {
142
- this.events.values.BOT_READY.fired = true;
143
- await this.events.values.BOT_READY.run(this.me, this, -1);
138
+ if (!this.__handleGuilds.size && [...this.gateway.values()].every(shard => shard.data.session_id)) {
139
+ await this.events.runEvent('BOT_READY', this, this.me, -1);
144
140
  }
141
+ if (!this.__handleGuilds.size)
142
+ delete this.__handleGuilds;
145
143
  return;
146
144
  }
147
145
  break;
@@ -1,14 +1,13 @@
1
1
  /// <reference types="node" />
2
2
  import type { HttpRequest, HttpResponse } from 'uWebSockets.js';
3
3
  import type { APIInteraction, DeepPartial } from '../common';
4
- import type { StartOptions } from './base';
4
+ import type { BaseClientOptions, StartOptions } from './base';
5
5
  import { BaseClient } from './base';
6
- declare let UWS: typeof import('uWebSockets.js');
7
6
  export declare class HttpClient extends BaseClient {
8
- app: ReturnType<typeof UWS.App>;
7
+ app: ReturnType<typeof import('uWebSockets.js').App>;
9
8
  publicKey: string;
10
9
  publicKeyHex: Buffer;
11
- constructor();
10
+ constructor(options?: BaseClientOptions);
12
11
  protected static readJson<T extends Record<string, any>>(res: HttpResponse): Promise<T>;
13
12
  protected execute(options?: {
14
13
  publicKey?: string;
@@ -18,4 +17,3 @@ export declare class HttpClient extends BaseClient {
18
17
  protected verifySignature(res: HttpResponse, req: HttpRequest): Promise<APIInteraction | undefined>;
19
18
  onPacket(res: HttpResponse, req: HttpRequest): Promise<void>;
20
19
  }
21
- export {};
@@ -1,13 +1,12 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.HttpClient = void 0;
7
- const form_data_1 = __importDefault(require("form-data"));
4
+ const magic_bytes_js_1 = require("magic-bytes.js");
5
+ const api_1 = require("../api");
6
+ const utils_1 = require("../api/utils/utils");
8
7
  const common_1 = require("../common");
9
8
  const base_1 = require("./base");
10
- const oninteraction_1 = require("./oninteraction");
9
+ const oninteractioncreate_1 = require("./oninteractioncreate");
11
10
  let UWS;
12
11
  let nacl;
13
12
  try {
@@ -26,8 +25,8 @@ class HttpClient extends base_1.BaseClient {
26
25
  app;
27
26
  publicKey;
28
27
  publicKeyHex;
29
- constructor() {
30
- super();
28
+ constructor(options) {
29
+ super(options);
31
30
  if (!UWS) {
32
31
  throw new Error('No uws installed.');
33
32
  }
@@ -88,9 +87,9 @@ class HttpClient extends base_1.BaseClient {
88
87
  }
89
88
  // https://discord.com/developers/docs/interactions/receiving-and-responding#security-and-authorization
90
89
  async verifySignature(res, req) {
91
- const body = await HttpClient.readJson(res);
92
90
  const timestamp = req.getHeader('x-signature-timestamp');
93
91
  const ed25519 = req.getHeader('x-signature-ed25519');
92
+ const body = await HttpClient.readJson(res);
94
93
  if (nacl.sign.detached.verify(Buffer.from(timestamp + JSON.stringify(body)), Buffer.from(ed25519, 'hex'), this.publicKeyHex)) {
95
94
  return body;
96
95
  }
@@ -112,19 +111,33 @@ class HttpClient extends base_1.BaseClient {
112
111
  .end(JSON.stringify({ type: common_1.InteractionResponseType.Pong }));
113
112
  break;
114
113
  default:
115
- await (0, oninteraction_1.onInteraction)(-1, rawBody, this, async ({ body, files }) => {
114
+ await (0, oninteractioncreate_1.onInteractionCreate)(this, rawBody, -1, async ({ body, files }) => {
116
115
  let response;
117
- let headers = {};
118
- if (files?.length) {
119
- response = new form_data_1.default();
120
- for (const key in files) {
121
- const file = files[key];
122
- response.append(key, file.data, file);
116
+ const headers = {};
117
+ if (files) {
118
+ response = new FormData();
119
+ for (const [index, file] of files.entries()) {
120
+ const fileKey = file.key ?? `files[${index}]`;
121
+ if ((0, utils_1.isBufferLike)(file.data)) {
122
+ let contentType = file.contentType;
123
+ if (!contentType) {
124
+ const [parsedType] = (0, magic_bytes_js_1.filetypeinfo)(file.data);
125
+ if (parsedType) {
126
+ contentType =
127
+ api_1.OverwrittenMimeTypes[parsedType.mime] ??
128
+ parsedType.mime ??
129
+ 'application/octet-stream';
130
+ }
131
+ }
132
+ response.append(fileKey, new Blob([file.data], { type: contentType }), file.name);
133
+ }
134
+ else {
135
+ response.append(fileKey, new Blob([`${file.data}`], { type: file.contentType }), file.name);
136
+ }
123
137
  }
124
138
  if (body) {
125
139
  response.append('payload_json', JSON.stringify(body));
126
140
  }
127
- headers = Object.assign(headers, response.getHeaders());
128
141
  }
129
142
  else {
130
143
  response = body ?? {};
@@ -1,4 +1,4 @@
1
1
  import { type APIInteraction } from 'discord-api-types/v10';
2
2
  import type { __InternalReplyFunction } from '../structures';
3
3
  import type { BaseClient } from './base';
4
- export declare function onInteraction(shardId: number, body: APIInteraction, self: BaseClient, __reply?: __InternalReplyFunction): Promise<any>;
4
+ export declare function onInteractionCreate(self: BaseClient, body: APIInteraction, shardId: number, __reply?: __InternalReplyFunction): Promise<any>;
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.onInteraction = void 0;
3
+ exports.onInteractionCreate = void 0;
4
4
  const v10_1 = require("discord-api-types/v10");
5
5
  const commands_1 = require("../commands");
6
6
  const structures_1 = require("../structures");
7
- async function onInteraction(shardId, body, self, __reply) {
7
+ async function onInteractionCreate(self, body, shardId, __reply) {
8
8
  self.debugger?.debug(`[${v10_1.InteractionType[body.type] ?? body.type}] Interaction received.`);
9
9
  switch (body.type) {
10
10
  case v10_1.InteractionType.ApplicationCommandAutocomplete:
@@ -26,13 +26,14 @@ async function onInteraction(shardId, body, self, __reply) {
26
26
  await command.autocomplete(interaction);
27
27
  }
28
28
  catch (error) {
29
- self.logger.error(`${optionsResolver.fullCommandName} ${command.name} just threw an error, ${error ? (typeof error === 'object' && 'message' in error ? error.message : error) : 'Unknown'}`);
30
- await command.onAutocompleteError?.(interaction, error);
29
+ if (!command.onAutocompleteError)
30
+ return self.logger.error(`${optionsResolver.fullCommandName} ${command.name} just threw an error, ${error ? (typeof error === 'object' && 'message' in error ? error.message : error) : 'Unknown'}`);
31
+ await command.onAutocompleteError(interaction, error);
31
32
  }
32
33
  }
33
34
  catch (error) {
34
35
  try {
35
- await optionsResolver.getCommand()?.onInternalError(self, error);
36
+ await optionsResolver.getCommand()?.onInternalError?.(self, error);
36
37
  }
37
38
  catch {
38
39
  // supress error
@@ -60,26 +61,31 @@ async function onInteraction(shardId, body, self, __reply) {
60
61
  const extendContext = self.options?.context?.(interaction) ?? {};
61
62
  Object.assign(context, extendContext);
62
63
  try {
64
+ if (command.botPermissions && interaction.appPermissions) {
65
+ const permissions = interaction.appPermissions.missings(...interaction.appPermissions.values(command.botPermissions));
66
+ if (permissions.length) {
67
+ return command.onPermissionsFail?.(context, interaction.appPermissions.keys(permissions));
68
+ }
69
+ }
63
70
  const resultRunGlobalMiddlewares = await command.__runGlobalMiddlewares(context);
64
- if (resultRunGlobalMiddlewares === 'pass') {
71
+ if (resultRunGlobalMiddlewares.pass) {
65
72
  return;
66
73
  }
67
- if (resultRunGlobalMiddlewares) {
68
- return command.onMiddlewaresError?.(context, resultRunGlobalMiddlewares);
74
+ if ('error' in resultRunGlobalMiddlewares) {
75
+ return command.onMiddlewaresError(context, resultRunGlobalMiddlewares.error ?? 'Unknown error');
69
76
  }
70
77
  const resultRunMiddlewares = await command.__runMiddlewares(context);
71
- if (resultRunMiddlewares === 'pass') {
78
+ if (resultRunMiddlewares.pass) {
72
79
  return;
73
80
  }
74
- if (resultRunGlobalMiddlewares) {
75
- return command.onMiddlewaresError?.(context, resultRunGlobalMiddlewares);
81
+ if ('error' in resultRunMiddlewares) {
82
+ return command.onMiddlewaresError(context, resultRunMiddlewares.error ?? 'Unknown error');
76
83
  }
77
84
  try {
78
85
  await command.run(context);
79
86
  await command.onAfterRun?.(context, undefined);
80
87
  }
81
88
  catch (error) {
82
- self.logger.error(`${command.name} just threw an error, ${error ? (typeof error === 'object' && 'message' in error ? error.message : error) : 'Unknown'}`);
83
89
  await command.onRunError?.(context, error);
84
90
  await command.onAfterRun?.(context, error);
85
91
  }
@@ -112,37 +118,42 @@ async function onInteraction(shardId, body, self, __reply) {
112
118
  const extendContext = self.options?.context?.(interaction) ?? {};
113
119
  Object.assign(context, extendContext);
114
120
  try {
121
+ if (command.botPermissions && interaction.appPermissions) {
122
+ const permissions = interaction.appPermissions.missings(...interaction.appPermissions.values(command.botPermissions));
123
+ if (permissions.length) {
124
+ return command.onPermissionsFail?.(context, interaction.appPermissions.keys(permissions));
125
+ }
126
+ }
115
127
  const [erroredOptions, result] = await command.__runOptions(context, optionsResolver);
116
128
  if (erroredOptions) {
117
129
  return command.onOptionsError?.(context, result);
118
130
  }
119
131
  const resultRunGlobalMiddlewares = await command.__runGlobalMiddlewares(context);
120
- if (resultRunGlobalMiddlewares === 'pass') {
132
+ if (resultRunGlobalMiddlewares.pass) {
121
133
  return;
122
134
  }
123
- if (resultRunGlobalMiddlewares) {
124
- return command.onMiddlewaresError?.(context, resultRunGlobalMiddlewares);
135
+ if ('error' in resultRunGlobalMiddlewares) {
136
+ return command.onMiddlewaresError?.(context, resultRunGlobalMiddlewares.error ?? 'Unknown error');
125
137
  }
126
138
  const resultRunMiddlewares = await command.__runMiddlewares(context);
127
- if (resultRunMiddlewares === 'pass') {
139
+ if (resultRunMiddlewares.pass) {
128
140
  return;
129
141
  }
130
- if (resultRunMiddlewares) {
131
- return command.onMiddlewaresError?.(context, resultRunMiddlewares);
142
+ if ('error' in resultRunMiddlewares) {
143
+ return command.onMiddlewaresError?.(context, resultRunMiddlewares.error ?? 'Unknown error');
132
144
  }
133
145
  try {
134
146
  await command.run(context);
135
147
  await command.onAfterRun?.(context, undefined);
136
148
  }
137
149
  catch (error) {
138
- self.logger.error(`${optionsResolver.fullCommandName} just threw an error, ${error ? (typeof error === 'object' && 'message' in error ? error.message : error) : 'Unknown'}`);
139
150
  await command.onRunError?.(context, error);
140
151
  await command.onAfterRun?.(context, error);
141
152
  }
142
153
  }
143
154
  catch (error) {
144
155
  try {
145
- await command.onInternalError(self, error);
156
+ await command.onInternalError?.(self, error);
146
157
  }
147
158
  catch {
148
159
  // supress error
@@ -167,8 +178,8 @@ async function onInteraction(shardId, body, self, __reply) {
167
178
  case v10_1.InteractionType.MessageComponent:
168
179
  {
169
180
  const interaction = structures_1.BaseInteraction.from(self, body, __reply);
170
- if (self.components.hasComponent(body.message.interaction.id, interaction.customId)) {
171
- await self.components.onComponent(body.message.interaction.id, interaction);
181
+ if (self.components.hasComponent(body.message.id, interaction.customId)) {
182
+ await self.components.onComponent(body.message.id, interaction);
172
183
  }
173
184
  else {
174
185
  await self.components.executeComponent(interaction);
@@ -177,4 +188,4 @@ async function onInteraction(shardId, body, self, __reply) {
177
188
  break;
178
189
  }
179
190
  }
180
- exports.onInteraction = onInteraction;
191
+ exports.onInteractionCreate = onInteractionCreate;
@@ -0,0 +1,3 @@
1
+ import { type GatewayMessageCreateDispatchData } from 'discord-api-types/v10';
2
+ import { type Client, type WorkerClient } from '..';
3
+ export declare function onMessageCreate(self: Client | WorkerClient, rawMessage: GatewayMessageCreateDispatchData, shardId: number): Promise<any>;