seyfert 4.4.1 → 5.0.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 (231) hide show
  1. package/README.md +7 -1
  2. package/lib/api/Routes/cdn.d.ts +2 -2
  3. package/lib/api/Routes/guilds.d.ts +2 -2
  4. package/lib/api/Routes/invites.d.ts +2 -2
  5. package/lib/api/api.d.ts +20 -8
  6. package/lib/api/api.js +198 -44
  7. package/lib/api/shared.d.ts +30 -1
  8. package/lib/api/utils/constants.d.ts +1 -1
  9. package/lib/api/utils/constants.js +1 -1
  10. package/lib/api/utils/utils.d.ts +2 -1
  11. package/lib/api/utils/utils.js +1 -1
  12. package/lib/builders/Attachment.d.ts +1 -1
  13. package/lib/builders/Attachment.js +30 -8
  14. package/lib/builders/MediaGallery.d.ts +2 -2
  15. package/lib/builders/MediaGallery.js +10 -0
  16. package/lib/builders/Modal.d.ts +18 -8
  17. package/lib/builders/Modal.js +36 -7
  18. package/lib/builders/Poll.js +18 -0
  19. package/lib/builders/RadioGroup.d.ts +4 -3
  20. package/lib/builders/RadioGroup.js +24 -3
  21. package/lib/builders/SelectMenu.d.ts +8 -6
  22. package/lib/builders/SelectMenu.js +24 -3
  23. package/lib/builders/types.d.ts +3 -2
  24. package/lib/cache/adapters/default.d.ts +1 -1
  25. package/lib/cache/adapters/default.js +23 -26
  26. package/lib/cache/adapters/limited.d.ts +1 -0
  27. package/lib/cache/adapters/limited.js +47 -33
  28. package/lib/cache/index.d.ts +19 -25
  29. package/lib/cache/index.js +58 -6
  30. package/lib/cache/resources/bans.d.ts +1 -1
  31. package/lib/cache/resources/bans.js +4 -4
  32. package/lib/cache/resources/channels.d.ts +1 -1
  33. package/lib/cache/resources/channels.js +4 -4
  34. package/lib/cache/resources/default/base.d.ts +1 -1
  35. package/lib/cache/resources/default/base.js +8 -8
  36. package/lib/cache/resources/default/guild-based.d.ts +5 -5
  37. package/lib/cache/resources/default/guild-based.js +29 -16
  38. package/lib/cache/resources/default/guild-related.d.ts +5 -5
  39. package/lib/cache/resources/default/guild-related.js +14 -14
  40. package/lib/cache/resources/emojis.d.ts +1 -1
  41. package/lib/cache/resources/emojis.js +4 -4
  42. package/lib/cache/resources/guilds.js +28 -15
  43. package/lib/cache/resources/members.d.ts +1 -1
  44. package/lib/cache/resources/members.js +6 -6
  45. package/lib/cache/resources/messages.d.ts +7 -2
  46. package/lib/cache/resources/messages.js +43 -20
  47. package/lib/cache/resources/overwrites.d.ts +1 -1
  48. package/lib/cache/resources/overwrites.js +5 -8
  49. package/lib/cache/resources/roles.d.ts +1 -1
  50. package/lib/cache/resources/roles.js +4 -4
  51. package/lib/cache/resources/stickers.d.ts +1 -1
  52. package/lib/cache/resources/stickers.js +4 -4
  53. package/lib/cache/resources/users.js +4 -4
  54. package/lib/cache/resources/voice-states.d.ts +1 -1
  55. package/lib/cache/resources/voice-states.js +4 -4
  56. package/lib/client/base.d.ts +83 -24
  57. package/lib/client/base.js +594 -39
  58. package/lib/client/client.d.ts +29 -4
  59. package/lib/client/client.js +38 -13
  60. package/lib/client/collectors.d.ts +9 -8
  61. package/lib/client/collectors.js +19 -52
  62. package/lib/client/httpclient.d.ts +3 -0
  63. package/lib/client/index.d.ts +3 -1
  64. package/lib/client/index.js +4 -0
  65. package/lib/client/intents.d.ts +3 -0
  66. package/lib/client/intents.js +9 -0
  67. package/lib/client/plugins/api.d.ts +4 -0
  68. package/lib/client/plugins/api.js +550 -0
  69. package/lib/client/plugins/errors.d.ts +25 -0
  70. package/lib/client/plugins/errors.js +79 -0
  71. package/lib/client/plugins/order.d.ts +10 -0
  72. package/lib/client/plugins/order.js +32 -0
  73. package/lib/client/plugins/registry.d.ts +273 -0
  74. package/lib/client/plugins/registry.js +868 -0
  75. package/lib/client/plugins/shared.d.ts +23 -0
  76. package/lib/client/plugins/shared.js +193 -0
  77. package/lib/client/plugins/types.d.ts +398 -0
  78. package/lib/client/plugins/types.js +8 -0
  79. package/lib/client/plugins.d.ts +78 -0
  80. package/lib/client/plugins.js +558 -0
  81. package/lib/client/transformers.d.ts +33 -33
  82. package/lib/client/workerclient.d.ts +11 -2
  83. package/lib/client/workerclient.js +33 -22
  84. package/lib/collection.d.ts +10 -8
  85. package/lib/collection.js +19 -25
  86. package/lib/commands/applications/chat.d.ts +20 -18
  87. package/lib/commands/applications/chat.js +39 -14
  88. package/lib/commands/applications/chatcontext.d.ts +23 -15
  89. package/lib/commands/applications/chatcontext.js +23 -2
  90. package/lib/commands/applications/entryPoint.d.ts +4 -3
  91. package/lib/commands/applications/entryPoint.js +1 -1
  92. package/lib/commands/applications/entrycontext.d.ts +7 -9
  93. package/lib/commands/applications/entrycontext.js +3 -1
  94. package/lib/commands/applications/menu.d.ts +4 -3
  95. package/lib/commands/applications/menucontext.d.ts +7 -9
  96. package/lib/commands/applications/menucontext.js +3 -1
  97. package/lib/commands/applications/options.d.ts +23 -23
  98. package/lib/commands/applications/shared.d.ts +39 -17
  99. package/lib/commands/decorators.d.ts +50 -38
  100. package/lib/commands/decorators.js +15 -5
  101. package/lib/commands/handle.d.ts +19 -8
  102. package/lib/commands/handle.js +224 -143
  103. package/lib/commands/handler.d.ts +21 -8
  104. package/lib/commands/handler.js +157 -69
  105. package/lib/commands/index.d.ts +1 -0
  106. package/lib/commands/optionresolver.d.ts +2 -2
  107. package/lib/common/it/colors.js +12 -2
  108. package/lib/common/it/error.d.ts +9 -0
  109. package/lib/common/it/error.js +8 -0
  110. package/lib/common/it/fake-promise.d.ts +4 -0
  111. package/lib/common/it/fake-promise.js +10 -0
  112. package/lib/common/it/formatter.d.ts +14 -11
  113. package/lib/common/it/formatter.js +4 -3
  114. package/lib/common/it/logger.d.ts +7 -1
  115. package/lib/common/it/logger.js +24 -6
  116. package/lib/common/it/utils.d.ts +6 -8
  117. package/lib/common/it/utils.js +44 -42
  118. package/lib/common/shorters/application.d.ts +3 -3
  119. package/lib/common/shorters/application.js +3 -2
  120. package/lib/common/shorters/bans.d.ts +8 -4
  121. package/lib/common/shorters/bans.js +13 -5
  122. package/lib/common/shorters/channels.d.ts +4 -4
  123. package/lib/common/shorters/channels.js +4 -4
  124. package/lib/common/shorters/emojis.js +1 -0
  125. package/lib/common/shorters/guilds.d.ts +8 -8
  126. package/lib/common/shorters/guilds.js +14 -31
  127. package/lib/common/shorters/interaction.d.ts +1 -1
  128. package/lib/common/shorters/invites.d.ts +201 -201
  129. package/lib/common/shorters/members.d.ts +7 -7
  130. package/lib/common/shorters/members.js +13 -14
  131. package/lib/common/shorters/messages.d.ts +2 -2
  132. package/lib/common/shorters/soundboard.d.ts +5 -5
  133. package/lib/common/shorters/users.d.ts +1 -1
  134. package/lib/common/shorters/webhook.d.ts +3 -2
  135. package/lib/common/shorters/webhook.js +0 -7
  136. package/lib/common/types/options.d.ts +4 -0
  137. package/lib/common/types/util.d.ts +8 -0
  138. package/lib/common/types/write.d.ts +2 -1
  139. package/lib/components/BaseSelectMenuComponent.d.ts +1 -1
  140. package/lib/components/BaseSelectMenuComponent.js +1 -1
  141. package/lib/components/ButtonComponent.d.ts +3 -3
  142. package/lib/components/ChannelSelectMenuComponent.d.ts +2 -2
  143. package/lib/components/File.d.ts +1 -1
  144. package/lib/components/MediaGallery.d.ts +1 -1
  145. package/lib/components/MentionableSelectMenuComponent.d.ts +1 -1
  146. package/lib/components/RoleSelectMenuComponent.d.ts +1 -1
  147. package/lib/components/Separator.d.ts +1 -1
  148. package/lib/components/StringSelectMenuComponent.d.ts +1 -1
  149. package/lib/components/TextInputComponent.d.ts +1 -1
  150. package/lib/components/Thumbnail.d.ts +1 -1
  151. package/lib/components/UserSelectMenuComponent.d.ts +1 -1
  152. package/lib/components/componentcommand.d.ts +8 -7
  153. package/lib/components/componentcontext.d.ts +24 -36
  154. package/lib/components/componentcontext.js +7 -17
  155. package/lib/components/handler.d.ts +17 -7
  156. package/lib/components/handler.js +108 -49
  157. package/lib/components/index.d.ts +1 -0
  158. package/lib/components/index.js +1 -0
  159. package/lib/components/interactioncontext.d.ts +45 -0
  160. package/lib/components/interactioncontext.js +93 -0
  161. package/lib/components/modalcommand.d.ts +5 -4
  162. package/lib/components/modalcontext.d.ts +39 -20
  163. package/lib/components/modalcontext.js +59 -6
  164. package/lib/events/event.d.ts +9 -3
  165. package/lib/events/handler.d.ts +51 -6
  166. package/lib/events/handler.js +165 -36
  167. package/lib/events/hooks/application_command.d.ts +1 -1
  168. package/lib/events/hooks/auto_moderation.d.ts +2 -2
  169. package/lib/events/hooks/guild.d.ts +150 -150
  170. package/lib/events/hooks/interactions.d.ts +1 -1
  171. package/lib/events/hooks/invite.d.ts +20 -20
  172. package/lib/events/hooks/message.d.ts +27 -27
  173. package/lib/events/hooks/presence.d.ts +11 -11
  174. package/lib/events/hooks/soundboard.d.ts +6 -6
  175. package/lib/events/hooks/stage.d.ts +2 -2
  176. package/lib/events/hooks/subscriptions.d.ts +3 -3
  177. package/lib/events/hooks/thread.d.ts +30 -30
  178. package/lib/events/hooks/voice.d.ts +3 -4
  179. package/lib/events/hooks/voice.js +2 -1
  180. package/lib/events/utils.d.ts +4 -0
  181. package/lib/events/utils.js +59 -0
  182. package/lib/index.d.ts +9 -4
  183. package/lib/index.js +14 -8
  184. package/lib/langs/handler.d.ts +14 -11
  185. package/lib/langs/handler.js +46 -9
  186. package/lib/langs/router.d.ts +10 -3
  187. package/lib/structures/Application.d.ts +1 -1
  188. package/lib/structures/Emoji.d.ts +3 -3
  189. package/lib/structures/Emoji.js +2 -2
  190. package/lib/structures/Guild.d.ts +154 -154
  191. package/lib/structures/GuildBan.d.ts +4 -4
  192. package/lib/structures/GuildBan.js +3 -3
  193. package/lib/structures/GuildMember.d.ts +7 -7
  194. package/lib/structures/GuildMember.js +28 -7
  195. package/lib/structures/GuildRole.d.ts +1 -1
  196. package/lib/structures/GuildRole.js +2 -2
  197. package/lib/structures/Interaction.d.ts +11 -9
  198. package/lib/structures/Interaction.js +33 -12
  199. package/lib/structures/Message.d.ts +21 -14
  200. package/lib/structures/Message.js +29 -14
  201. package/lib/structures/User.d.ts +1 -1
  202. package/lib/structures/VoiceState.d.ts +4 -0
  203. package/lib/structures/VoiceState.js +13 -1
  204. package/lib/structures/Webhook.d.ts +9 -1
  205. package/lib/structures/Webhook.js +4 -1
  206. package/lib/structures/channels.d.ts +148 -134
  207. package/lib/structures/channels.js +27 -26
  208. package/lib/structures/extra/BitField.d.ts +4 -4
  209. package/lib/structures/extra/BitField.js +20 -4
  210. package/lib/structures/extra/DiscordBase.js +1 -1
  211. package/lib/structures/extra/Permissions.d.ts +2 -4
  212. package/lib/structures/extra/Permissions.js +1 -17
  213. package/lib/types/payloads/_interactions/responses.d.ts +2 -2
  214. package/lib/types/payloads/components.d.ts +4 -4
  215. package/lib/websocket/SharedTypes.d.ts +4 -4
  216. package/lib/websocket/constants/index.d.ts +1 -1
  217. package/lib/websocket/constants/index.js +3 -2
  218. package/lib/websocket/discord/events/memberUpdate.js +2 -2
  219. package/lib/websocket/discord/heartbeater.d.ts +1 -0
  220. package/lib/websocket/discord/heartbeater.js +7 -0
  221. package/lib/websocket/discord/shard.d.ts +2 -2
  222. package/lib/websocket/discord/shard.js +16 -14
  223. package/lib/websocket/discord/sharder.d.ts +8 -7
  224. package/lib/websocket/discord/sharder.js +26 -6
  225. package/lib/websocket/discord/shared.d.ts +19 -6
  226. package/lib/websocket/discord/socket/custom.js +5 -0
  227. package/lib/websocket/discord/worker.d.ts +1 -0
  228. package/lib/websocket/discord/worker.js +2 -0
  229. package/lib/websocket/discord/workermanager.d.ts +25 -11
  230. package/lib/websocket/discord/workermanager.js +41 -10
  231. package/package.json +13 -17
@@ -1,15 +1,16 @@
1
1
  import type { CommandContext, Message } from '..';
2
2
  import { type Awaitable, type DeepPartial, type PickPartial, type When } from '../common';
3
3
  import { EventHandler } from '../events';
4
- import type { GatewayDispatchPayload, GatewayPresenceUpdateData } from '../types';
4
+ import { type GatewayDispatchPayload, type GatewayPresenceUpdateData } from '../types';
5
5
  import { ShardManager, type ShardManagerOptions } from '../websocket';
6
6
  import { MemberUpdateHandler } from '../websocket/discord/events/memberUpdate';
7
7
  import { PresenceUpdateHandler } from '../websocket/discord/events/presenceUpdate';
8
8
  import type { BaseClientOptions, ServicesOptions, StartOptions } from './base';
9
9
  import { BaseClient } from './base';
10
10
  import { Collectors } from './collectors';
11
+ import { type AnySeyfertPlugin, type ExtendOf, type RegisteredPluginExtension, type RegisteredPlugins } from './plugins';
11
12
  import { type ClientUserStructure, type MessageStructure } from './transformers';
12
- export declare class Client<Ready extends boolean = boolean> extends BaseClient {
13
+ declare class ClientBase<Ready extends boolean = boolean> extends BaseClient {
13
14
  gateway: ShardManager;
14
15
  me: When<Ready, ClientUserStructure>;
15
16
  options: Omit<ClientOptions, 'commands'> & {
@@ -34,9 +35,25 @@ export declare class Client<Ready extends boolean = boolean> extends BaseClient
34
35
  intents?: number;
35
36
  }): Promise<void>;
36
37
  start(options?: Omit<DeepPartial<StartOptions>, 'httpConnection'>, execute?: boolean): Promise<void>;
37
- protected onPacket(shardId: number, packet: GatewayDispatchPayload): Promise<void>;
38
+ protected onPacket(shardId: number, packet: GatewayDispatchPayload): Promise<GatewayDispatchPayload | null>;
39
+ private handleGatewaySendPayload;
38
40
  }
39
- export interface ClientOptions extends BaseClientOptions {
41
+ type ClientPluginsOf<TPluginsOrReady extends readonly AnySeyfertPlugin[] | boolean> = TPluginsOrReady extends readonly AnySeyfertPlugin[] ? TPluginsOrReady : RegisteredPlugins;
42
+ type ClientReadyOf<TPluginsOrReady extends readonly AnySeyfertPlugin[] | boolean, Ready extends boolean> = TPluginsOrReady extends boolean ? TPluginsOrReady : Ready;
43
+ type ClientAmbientExtensionOf<TPluginsOrReady extends readonly AnySeyfertPlugin[] | boolean> = TPluginsOrReady extends readonly AnySeyfertPlugin[] ? {} : RegisteredPluginExtension;
44
+ type ClientOptionsOf<TPluginsOrReady extends readonly AnySeyfertPlugin[] | boolean> = TPluginsOrReady extends readonly AnySeyfertPlugin[] ? ClientOptions<TPluginsOrReady> : ClientOptions<RegisteredPlugins>;
45
+ type Materialize<T> = {
46
+ [K in keyof T]: T[K];
47
+ };
48
+ export type Client<TPluginsOrReady extends readonly AnySeyfertPlugin[] | boolean = RegisteredPlugins, Ready extends boolean = boolean> = ClientBase<ClientReadyOf<TPluginsOrReady, Ready>> & ClientAmbientExtensionOf<TPluginsOrReady> & Materialize<ExtendOf<ClientPluginsOf<TPluginsOrReady>>>;
49
+ type ClientBaseStatics = Omit<typeof ClientBase, 'prototype'>;
50
+ export type ClientConstructor = ClientBaseStatics & {
51
+ new <TPluginsOrReady extends readonly AnySeyfertPlugin[] | boolean = RegisteredPlugins, Ready extends boolean = boolean>(options?: ClientOptionsOf<TPluginsOrReady>): Client<TPluginsOrReady, Ready>;
52
+ prototype: Client;
53
+ };
54
+ export declare const Client: ClientConstructor;
55
+ export interface ClientOptions<TPlugins extends readonly AnySeyfertPlugin[] = RegisteredPlugins> extends BaseClientOptions {
56
+ plugins?: TPlugins;
40
57
  presence?: (shardId: number) => GatewayPresenceUpdateData;
41
58
  shards?: {
42
59
  start: number;
@@ -53,7 +70,15 @@ export interface ClientOptions extends BaseClientOptions {
53
70
  reply?: (ctx: CommandContext) => Awaitable<boolean>;
54
71
  };
55
72
  handlePayload?: ShardManagerOptions['handlePayload'];
73
+ handleSendPayload?: ShardManagerOptions['handleSendPayload'];
74
+ /**
75
+ * @deprecated Use shard disconnect events instead. Injected ShardManager callbacks can double-fire.
76
+ */
56
77
  onShardDisconnect?: ShardManagerOptions['onShardDisconnect'];
78
+ /**
79
+ * @deprecated Use shard reconnect events instead. Injected ShardManager callbacks can double-fire.
80
+ */
57
81
  onShardReconnect?: ShardManagerOptions['onShardReconnect'];
58
82
  resharding?: PickPartial<NonNullable<ShardManagerOptions['resharding']>, 'getInfo'>;
59
83
  }
84
+ export {};
@@ -3,14 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Client = void 0;
4
4
  const common_1 = require("../common");
5
5
  const events_1 = require("../events");
6
+ const types_1 = require("../types");
6
7
  const websocket_1 = require("../websocket");
7
8
  const memberUpdate_1 = require("../websocket/discord/events/memberUpdate");
8
9
  const presenceUpdate_1 = require("../websocket/discord/events/presenceUpdate");
9
10
  const base_1 = require("./base");
10
11
  const collectors_1 = require("./collectors");
12
+ const plugins_1 = require("./plugins");
11
13
  const transformers_1 = require("./transformers");
12
14
  let parentPort;
13
- class Client extends base_1.BaseClient {
15
+ class ClientBase extends base_1.BaseClient {
14
16
  gateway;
15
17
  me;
16
18
  memberUpdateHandler = new memberUpdate_1.MemberUpdateHandler();
@@ -45,6 +47,8 @@ class Client extends base_1.BaseClient {
45
47
  await oldOnShardReconnect?.(data);
46
48
  await this.onShardReconnect(data);
47
49
  };
50
+ const oldHandleSendPayload = gateway.options.handleSendPayload;
51
+ gateway.options.handleSendPayload = (shardId, payload) => this.handleGatewaySendPayload(shardId, payload, oldHandleSendPayload);
48
52
  this.gateway = gateway;
49
53
  }
50
54
  }
@@ -61,10 +65,12 @@ class Client extends base_1.BaseClient {
61
65
  }
62
66
  async loadEvents(dir) {
63
67
  dir ??= await this.getRC().then(x => x.locations.events);
68
+ await (0, plugins_1.runPluginHooks)(this, 'events:beforeLoad', this, dir);
64
69
  if (dir) {
65
70
  await this.events.load(dir);
66
71
  this.logger.info('EventHandler loaded');
67
72
  }
73
+ await (0, plugins_1.runPluginHooks)(this, 'events:afterLoad', this, dir);
68
74
  }
69
75
  async execute(options = {}) {
70
76
  await super.execute(options);
@@ -79,7 +85,9 @@ class Client extends base_1.BaseClient {
79
85
  this.gateway.options.handlePayload(data.shardId, data.payload);
80
86
  break;
81
87
  case 'SEND_TO_SHARD':
82
- this.gateway.send(data.shardId, data.payload);
88
+ void this.gateway.send(data.shardId, data.payload).catch(error => {
89
+ this.logger.fatal('Watcher failed to send payload to shard', error);
90
+ });
83
91
  break;
84
92
  }
85
93
  });
@@ -93,10 +101,12 @@ class Client extends base_1.BaseClient {
93
101
  await this.loadEvents(options.eventsDir);
94
102
  const { token: tokenRC, intents: intentsRC, debug: debugRC } = await this.getRC();
95
103
  const token = options?.token ?? tokenRC;
96
- const intents = options?.connection?.intents ?? intentsRC;
97
- this.cache.intents = intents;
104
+ const connectionIntents = options?.connection?.intents;
105
+ const intents = this.resolvePluginGatewayIntents(connectionIntents ?? intentsRC);
98
106
  if (!this.gateway) {
99
- (0, common_1.assertString)(token, 'token is not a string');
107
+ if (typeof token !== 'string' || token.length === 0) {
108
+ throw new common_1.SeyfertError('INVALID_TOKEN', { metadata: { detail: 'token is not a string' } });
109
+ }
100
110
  this.gateway = new websocket_1.ShardManager({
101
111
  token,
102
112
  info: await this.proxy.gateway.bot.get(),
@@ -105,6 +115,7 @@ class Client extends base_1.BaseClient {
105
115
  await this.options?.handlePayload?.(shardId, packet);
106
116
  return this.onPacket(shardId, packet);
107
117
  },
118
+ handleSendPayload: (shardId, payload) => this.handleGatewaySendPayload(shardId, payload, this.options?.handleSendPayload),
108
119
  onShardDisconnect: this.onShardDisconnect.bind(this),
109
120
  onShardReconnect: this.onShardReconnect.bind(this),
110
121
  presence: this.options?.presence,
@@ -125,13 +136,17 @@ class Client extends base_1.BaseClient {
125
136
  });
126
137
  }
127
138
  if (execute) {
128
- await this.execute(options.connection);
139
+ await this.execute({ ...(options.connection ?? {}), intents });
129
140
  }
130
141
  else {
131
142
  await super.execute(options);
132
143
  }
133
144
  }
134
145
  async onPacket(shardId, packet) {
146
+ const pluginPacket = await (0, plugins_1.applyPluginGatewayDispatchInterceptors)(this, shardId, packet);
147
+ if (pluginPacket === null)
148
+ return null;
149
+ packet = pluginPacket;
135
150
  Promise.allSettled([
136
151
  this.events.runEvent('RAW', this, packet, shardId, false),
137
152
  this.collectors.run('RAW', packet, this),
@@ -140,7 +155,7 @@ class Client extends base_1.BaseClient {
140
155
  case 'GUILD_MEMBER_UPDATE':
141
156
  {
142
157
  if (!this.memberUpdateHandler.check(packet.d)) {
143
- return;
158
+ return packet;
144
159
  }
145
160
  await this.events.execute(packet, this, shardId);
146
161
  }
@@ -148,7 +163,7 @@ class Client extends base_1.BaseClient {
148
163
  case 'PRESENCE_UPDATE':
149
164
  {
150
165
  if (!this.presenceUpdateHandler.check(packet.d)) {
151
- return;
166
+ return packet;
152
167
  }
153
168
  await this.events.execute(packet, this, shardId);
154
169
  }
@@ -156,19 +171,19 @@ class Client extends base_1.BaseClient {
156
171
  //rest of the events
157
172
  default: {
158
173
  switch (packet.t) {
159
- case 'INTERACTION_CREATE':
174
+ case types_1.GatewayDispatchEvents.InteractionCreate:
160
175
  {
161
176
  await this.events.execute(packet, this, shardId);
162
177
  await this.handleCommand.interaction(packet.d, shardId);
163
178
  }
164
179
  break;
165
- case 'MESSAGE_CREATE':
180
+ case types_1.GatewayDispatchEvents.MessageCreate:
166
181
  {
167
182
  await this.events.execute(packet, this, shardId);
168
183
  await this.handleCommand.message(packet.d, shardId);
169
184
  }
170
185
  break;
171
- case 'READY': {
186
+ case types_1.GatewayDispatchEvents.Ready: {
172
187
  this.botId = packet.d.user.id;
173
188
  this.applicationId = packet.d.application.id;
174
189
  this.me = transformers_1.Transformers.ClientUser(this, packet.d.user, packet.d.application);
@@ -176,7 +191,7 @@ class Client extends base_1.BaseClient {
176
191
  await this.events.execute(packet, this, shardId);
177
192
  break;
178
193
  }
179
- case 'GUILDS_READY':
194
+ case types_1.GatewayDispatchEvents.GuildsReady:
180
195
  {
181
196
  await this.events.execute(packet, this, shardId);
182
197
  if ([...this.gateway.values()].every(shard => shard.isReady)) {
@@ -191,6 +206,16 @@ class Client extends base_1.BaseClient {
191
206
  break;
192
207
  }
193
208
  }
209
+ return packet;
210
+ }
211
+ async handleGatewaySendPayload(shardId, payload, handleSendPayload) {
212
+ const pluginPayload = await (0, plugins_1.applyPluginGatewaySendPayloadWrappers)(this, shardId, payload);
213
+ if (pluginPayload === null)
214
+ return null;
215
+ const result = await handleSendPayload?.(shardId, pluginPayload);
216
+ if (result === null)
217
+ return null;
218
+ return result ?? pluginPayload;
194
219
  }
195
220
  }
196
- exports.Client = Client;
221
+ exports.Client = ClientBase;
@@ -1,8 +1,9 @@
1
- import type { Awaitable, CamelCase } from '../common';
2
- import type { CallbackEventHandler, CustomEventsKeys, GatewayEvents } from '../events';
3
- export type AllClientEvents = CustomEventsKeys | GatewayEvents;
4
- export type ParseClientEventName<T extends AllClientEvents> = T extends CustomEventsKeys ? T : CamelCase<T>;
5
- export type CollectorRunPameters<T extends AllClientEvents> = Awaited<Parameters<CallbackEventHandler[ParseClientEventName<T>]>[0]>;
1
+ import { type Awaitable, type CamelCase } from '../common';
2
+ import type { CallbackEventHandler, ClientNameEvents, CustomEventsKeys, GatewayEvents } from '../events';
3
+ export type AllClientEvents = CustomEventsKeys | ClientNameEvents;
4
+ type ClientDispatchEvent = AllClientEvents | GatewayEvents;
5
+ export type ParseClientEventName<T extends ClientDispatchEvent> = T extends GatewayEvents ? CamelCase<T> : T;
6
+ export type CollectorRunParameters<T extends AllClientEvents> = Awaited<Parameters<CallbackEventHandler[ParseClientEventName<T>]>[0]>;
6
7
  type RunData<T extends AllClientEvents> = {
7
8
  options: {
8
9
  event: T;
@@ -10,9 +11,9 @@ type RunData<T extends AllClientEvents> = {
10
11
  timeout?: number;
11
12
  onStop?: (reason: string) => unknown;
12
13
  onStopError?: (reason: string, error: unknown) => unknown;
13
- filter: (arg: CollectorRunPameters<T>) => Awaitable<boolean>;
14
- run: (arg: CollectorRunPameters<T>, stop: (reason?: string) => void) => unknown;
15
- onRunError?: (arg: CollectorRunPameters<T>, error: unknown, stop: (reason?: string) => void) => unknown;
14
+ filter: (arg: CollectorRunParameters<T>) => Awaitable<boolean>;
15
+ run: (arg: CollectorRunParameters<T>, stop: (reason?: string) => void) => unknown;
16
+ onRunError?: (arg: CollectorRunParameters<T>, error: unknown, stop: (reason?: string) => void) => unknown;
16
17
  };
17
18
  idle?: NodeJS.Timeout;
18
19
  timeout?: NodeJS.Timeout;
@@ -1,71 +1,38 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  Object.defineProperty(exports, "__esModule", { value: true });
36
3
  exports.Collectors = void 0;
37
4
  const node_crypto_1 = require("node:crypto");
38
- const RawEvents = __importStar(require("../events/hooks"));
5
+ const common_1 = require("../common");
6
+ const utils_1 = require("../events/utils");
7
+ function normalizeCollectorEventName(name) {
8
+ return (name === name.toUpperCase() ? common_1.ReplaceRegex.camel(name.toLowerCase()) : name);
9
+ }
39
10
  class Collectors {
40
11
  values = new Map();
41
12
  generateRandomUUID(name) {
42
- const collectors = this.values.get(name);
43
- if (!collectors)
13
+ if (!this.values.has(name))
44
14
  return '*';
45
- let nonce = (0, node_crypto_1.randomUUID)();
46
- while (collectors.find(x => x.nonce === nonce)) {
47
- nonce = (0, node_crypto_1.randomUUID)();
48
- }
49
- return nonce;
15
+ return (0, node_crypto_1.randomUUID)();
50
16
  }
51
17
  create(options) {
52
- const nonce = this.generateRandomUUID(options.event);
53
- if (!this.values.has(options.event)) {
54
- this.values.set(options.event, []);
18
+ const event = options.event;
19
+ const nonce = this.generateRandomUUID(event);
20
+ if (!this.values.has(event)) {
21
+ this.values.set(event, []);
55
22
  }
56
- this.values.get(options.event).push({
23
+ this.values.get(event).push({
57
24
  options: {
58
25
  ...options,
59
- name: options.event,
26
+ event,
60
27
  },
61
28
  idle: options.idle && options.idle > 0
62
29
  ? setTimeout(() => {
63
- return this.delete(options.event, nonce, 'idle');
30
+ return this.delete(event, nonce, 'idle');
64
31
  }, options.idle)
65
32
  : undefined,
66
33
  timeout: options.timeout && options.timeout > 0
67
34
  ? setTimeout(() => {
68
- return this.delete(options.event, nonce, 'timeout');
35
+ return this.delete(event, nonce, 'timeout');
69
36
  }, options.timeout)
70
37
  : undefined,
71
38
  nonce,
@@ -95,11 +62,12 @@ class Collectors {
95
62
  }
96
63
  /**@internal */
97
64
  async run(name, raw, client) {
98
- const collectors = this.values.get(name);
65
+ const event = normalizeCollectorEventName(name);
66
+ const collectors = this.values.get(event);
99
67
  if (!collectors)
100
68
  return;
101
- const data = (await RawEvents[name]?.(client, raw)) ?? raw;
102
- for (const i of collectors) {
69
+ const data = (await (0, utils_1.resolveRawEventData)(name, client, raw)) ?? raw;
70
+ for (const i of [...collectors]) {
103
71
  if (await i.options.filter(data)) {
104
72
  i.idle?.refresh();
105
73
  const stop = (reason = 'unknown') => {
@@ -111,7 +79,6 @@ class Collectors {
111
79
  catch (e) {
112
80
  await i.options.onRunError?.(data, e, stop);
113
81
  }
114
- break;
115
82
  }
116
83
  }
117
84
  }
@@ -1,7 +1,10 @@
1
1
  import type { DeepPartial } from '../common';
2
2
  import type { BaseClientOptions, StartOptions } from './base';
3
3
  import { BaseClient } from './base';
4
+ import type { RegisteredPluginExtension } from './plugins';
4
5
  export declare class HttpClient extends BaseClient {
5
6
  constructor(options?: BaseClientOptions);
6
7
  start(options?: DeepPartial<Omit<StartOptions, 'connection' | 'eventsDir'>>): Promise<void>;
7
8
  }
9
+ export interface HttpClient extends RegisteredPluginExtension {
10
+ }
@@ -1,5 +1,7 @@
1
- export type { RuntimeConfig, RuntimeConfigHTTP } from './base';
1
+ export type { BotConfig, ClientMiddlewares, ContextScope, ContextScopeContext, HttpConfig, RuntimeConfig, RuntimeConfigHTTP, } from './base';
2
2
  export * from './client';
3
+ export { type AllClientEvents, type CollectorRunParameters, Collectors, type ParseClientEventName } from './collectors';
3
4
  export * from './httpclient';
5
+ export * from './plugins';
4
6
  export * from './transformers';
5
7
  export * from './workerclient';
@@ -14,7 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.Collectors = void 0;
17
18
  __exportStar(require("./client"), exports);
19
+ var collectors_1 = require("./collectors");
20
+ Object.defineProperty(exports, "Collectors", { enumerable: true, get: function () { return collectors_1.Collectors; } });
18
21
  __exportStar(require("./httpclient"), exports);
22
+ __exportStar(require("./plugins"), exports);
19
23
  __exportStar(require("./transformers"), exports);
20
24
  __exportStar(require("./workerclient"), exports);
@@ -0,0 +1,3 @@
1
+ import type { IntentStrings } from '../common/types/util';
2
+ export type GatewayIntentInput = number | IntentStrings | number[];
3
+ export declare function resolveGatewayIntents(intents?: GatewayIntentInput): number;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveGatewayIntents = resolveGatewayIntents;
4
+ const types_1 = require("../types");
5
+ function resolveGatewayIntents(intents) {
6
+ if (typeof intents === 'number')
7
+ return intents;
8
+ return (intents?.reduce((current, intent) => current | (typeof intent === 'number' ? intent : types_1.GatewayIntentBits[intent]), 0) ?? 0);
9
+ }
@@ -0,0 +1,4 @@
1
+ import { type PluginEventContributionScope, type PluginRuntimeRecord, type PluginRuntimeRegistry } from './registry';
2
+ import type { SeyfertPluginApi, SeyfertPluginTeardownApi } from './types';
3
+ export declare function createPluginApi(record: PluginRuntimeRecord, registry: PluginRuntimeRegistry, scope: 'teardown'): SeyfertPluginTeardownApi;
4
+ export declare function createPluginApi(record: PluginRuntimeRecord, registry: PluginRuntimeRegistry, scope?: Exclude<PluginEventContributionScope, 'teardown'>): SeyfertPluginApi;