seyfert 4.5.0 → 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 (230) hide show
  1. package/lib/api/Routes/cdn.d.ts +2 -2
  2. package/lib/api/Routes/guilds.d.ts +2 -2
  3. package/lib/api/Routes/invites.d.ts +2 -2
  4. package/lib/api/api.d.ts +20 -8
  5. package/lib/api/api.js +198 -44
  6. package/lib/api/shared.d.ts +30 -1
  7. package/lib/api/utils/constants.d.ts +1 -1
  8. package/lib/api/utils/constants.js +1 -1
  9. package/lib/api/utils/utils.d.ts +2 -1
  10. package/lib/api/utils/utils.js +1 -1
  11. package/lib/builders/Attachment.d.ts +1 -1
  12. package/lib/builders/Attachment.js +30 -8
  13. package/lib/builders/MediaGallery.d.ts +2 -2
  14. package/lib/builders/MediaGallery.js +10 -0
  15. package/lib/builders/Modal.d.ts +18 -8
  16. package/lib/builders/Modal.js +36 -7
  17. package/lib/builders/Poll.js +18 -0
  18. package/lib/builders/RadioGroup.d.ts +4 -3
  19. package/lib/builders/RadioGroup.js +24 -3
  20. package/lib/builders/SelectMenu.d.ts +8 -6
  21. package/lib/builders/SelectMenu.js +24 -3
  22. package/lib/builders/types.d.ts +3 -2
  23. package/lib/cache/adapters/default.d.ts +1 -1
  24. package/lib/cache/adapters/default.js +23 -26
  25. package/lib/cache/adapters/limited.d.ts +1 -0
  26. package/lib/cache/adapters/limited.js +47 -33
  27. package/lib/cache/index.d.ts +19 -25
  28. package/lib/cache/index.js +58 -6
  29. package/lib/cache/resources/bans.d.ts +1 -1
  30. package/lib/cache/resources/bans.js +4 -4
  31. package/lib/cache/resources/channels.d.ts +1 -1
  32. package/lib/cache/resources/channels.js +4 -4
  33. package/lib/cache/resources/default/base.d.ts +1 -1
  34. package/lib/cache/resources/default/base.js +8 -8
  35. package/lib/cache/resources/default/guild-based.d.ts +5 -5
  36. package/lib/cache/resources/default/guild-based.js +29 -16
  37. package/lib/cache/resources/default/guild-related.d.ts +5 -5
  38. package/lib/cache/resources/default/guild-related.js +14 -14
  39. package/lib/cache/resources/emojis.d.ts +1 -1
  40. package/lib/cache/resources/emojis.js +4 -4
  41. package/lib/cache/resources/guilds.js +28 -15
  42. package/lib/cache/resources/members.d.ts +1 -1
  43. package/lib/cache/resources/members.js +6 -6
  44. package/lib/cache/resources/messages.d.ts +7 -2
  45. package/lib/cache/resources/messages.js +43 -20
  46. package/lib/cache/resources/overwrites.d.ts +1 -1
  47. package/lib/cache/resources/overwrites.js +5 -8
  48. package/lib/cache/resources/roles.d.ts +1 -1
  49. package/lib/cache/resources/roles.js +4 -4
  50. package/lib/cache/resources/stickers.d.ts +1 -1
  51. package/lib/cache/resources/stickers.js +4 -4
  52. package/lib/cache/resources/users.js +4 -4
  53. package/lib/cache/resources/voice-states.d.ts +1 -1
  54. package/lib/cache/resources/voice-states.js +4 -4
  55. package/lib/client/base.d.ts +83 -24
  56. package/lib/client/base.js +594 -39
  57. package/lib/client/client.d.ts +28 -3
  58. package/lib/client/client.js +33 -9
  59. package/lib/client/collectors.d.ts +9 -8
  60. package/lib/client/collectors.js +19 -52
  61. package/lib/client/httpclient.d.ts +3 -0
  62. package/lib/client/index.d.ts +3 -1
  63. package/lib/client/index.js +4 -0
  64. package/lib/client/intents.d.ts +3 -0
  65. package/lib/client/intents.js +9 -0
  66. package/lib/client/plugins/api.d.ts +4 -0
  67. package/lib/client/plugins/api.js +550 -0
  68. package/lib/client/plugins/errors.d.ts +25 -0
  69. package/lib/client/plugins/errors.js +79 -0
  70. package/lib/client/plugins/order.d.ts +10 -0
  71. package/lib/client/plugins/order.js +32 -0
  72. package/lib/client/plugins/registry.d.ts +273 -0
  73. package/lib/client/plugins/registry.js +868 -0
  74. package/lib/client/plugins/shared.d.ts +23 -0
  75. package/lib/client/plugins/shared.js +193 -0
  76. package/lib/client/plugins/types.d.ts +398 -0
  77. package/lib/client/plugins/types.js +8 -0
  78. package/lib/client/plugins.d.ts +78 -0
  79. package/lib/client/plugins.js +558 -0
  80. package/lib/client/transformers.d.ts +33 -33
  81. package/lib/client/workerclient.d.ts +10 -1
  82. package/lib/client/workerclient.js +27 -17
  83. package/lib/collection.d.ts +10 -8
  84. package/lib/collection.js +19 -25
  85. package/lib/commands/applications/chat.d.ts +20 -18
  86. package/lib/commands/applications/chat.js +39 -14
  87. package/lib/commands/applications/chatcontext.d.ts +23 -15
  88. package/lib/commands/applications/chatcontext.js +23 -2
  89. package/lib/commands/applications/entryPoint.d.ts +4 -3
  90. package/lib/commands/applications/entryPoint.js +1 -1
  91. package/lib/commands/applications/entrycontext.d.ts +7 -9
  92. package/lib/commands/applications/entrycontext.js +3 -1
  93. package/lib/commands/applications/menu.d.ts +4 -3
  94. package/lib/commands/applications/menucontext.d.ts +7 -9
  95. package/lib/commands/applications/menucontext.js +3 -1
  96. package/lib/commands/applications/options.d.ts +23 -23
  97. package/lib/commands/applications/shared.d.ts +39 -17
  98. package/lib/commands/decorators.d.ts +50 -38
  99. package/lib/commands/decorators.js +15 -5
  100. package/lib/commands/handle.d.ts +19 -8
  101. package/lib/commands/handle.js +224 -143
  102. package/lib/commands/handler.d.ts +21 -8
  103. package/lib/commands/handler.js +157 -69
  104. package/lib/commands/index.d.ts +1 -0
  105. package/lib/commands/optionresolver.d.ts +2 -2
  106. package/lib/common/it/colors.js +12 -2
  107. package/lib/common/it/error.d.ts +9 -0
  108. package/lib/common/it/error.js +8 -0
  109. package/lib/common/it/fake-promise.d.ts +4 -0
  110. package/lib/common/it/fake-promise.js +10 -0
  111. package/lib/common/it/formatter.d.ts +14 -11
  112. package/lib/common/it/formatter.js +4 -3
  113. package/lib/common/it/logger.d.ts +7 -1
  114. package/lib/common/it/logger.js +24 -6
  115. package/lib/common/it/utils.d.ts +6 -8
  116. package/lib/common/it/utils.js +44 -42
  117. package/lib/common/shorters/application.d.ts +3 -3
  118. package/lib/common/shorters/application.js +3 -2
  119. package/lib/common/shorters/bans.d.ts +8 -4
  120. package/lib/common/shorters/bans.js +13 -5
  121. package/lib/common/shorters/channels.d.ts +4 -4
  122. package/lib/common/shorters/channels.js +4 -4
  123. package/lib/common/shorters/emojis.js +1 -0
  124. package/lib/common/shorters/guilds.d.ts +8 -8
  125. package/lib/common/shorters/guilds.js +14 -31
  126. package/lib/common/shorters/interaction.d.ts +1 -1
  127. package/lib/common/shorters/invites.d.ts +201 -201
  128. package/lib/common/shorters/members.d.ts +7 -7
  129. package/lib/common/shorters/members.js +13 -14
  130. package/lib/common/shorters/messages.d.ts +2 -2
  131. package/lib/common/shorters/soundboard.d.ts +5 -5
  132. package/lib/common/shorters/users.d.ts +1 -1
  133. package/lib/common/shorters/webhook.d.ts +3 -2
  134. package/lib/common/shorters/webhook.js +0 -7
  135. package/lib/common/types/options.d.ts +4 -0
  136. package/lib/common/types/util.d.ts +8 -0
  137. package/lib/common/types/write.d.ts +2 -1
  138. package/lib/components/BaseSelectMenuComponent.d.ts +1 -1
  139. package/lib/components/BaseSelectMenuComponent.js +1 -1
  140. package/lib/components/ButtonComponent.d.ts +3 -3
  141. package/lib/components/ChannelSelectMenuComponent.d.ts +2 -2
  142. package/lib/components/File.d.ts +1 -1
  143. package/lib/components/MediaGallery.d.ts +1 -1
  144. package/lib/components/MentionableSelectMenuComponent.d.ts +1 -1
  145. package/lib/components/RoleSelectMenuComponent.d.ts +1 -1
  146. package/lib/components/Separator.d.ts +1 -1
  147. package/lib/components/StringSelectMenuComponent.d.ts +1 -1
  148. package/lib/components/TextInputComponent.d.ts +1 -1
  149. package/lib/components/Thumbnail.d.ts +1 -1
  150. package/lib/components/UserSelectMenuComponent.d.ts +1 -1
  151. package/lib/components/componentcommand.d.ts +8 -7
  152. package/lib/components/componentcontext.d.ts +24 -36
  153. package/lib/components/componentcontext.js +7 -17
  154. package/lib/components/handler.d.ts +17 -7
  155. package/lib/components/handler.js +108 -49
  156. package/lib/components/index.d.ts +1 -0
  157. package/lib/components/index.js +1 -0
  158. package/lib/components/interactioncontext.d.ts +45 -0
  159. package/lib/components/interactioncontext.js +93 -0
  160. package/lib/components/modalcommand.d.ts +5 -4
  161. package/lib/components/modalcontext.d.ts +39 -20
  162. package/lib/components/modalcontext.js +59 -6
  163. package/lib/events/event.d.ts +9 -3
  164. package/lib/events/handler.d.ts +51 -6
  165. package/lib/events/handler.js +165 -36
  166. package/lib/events/hooks/application_command.d.ts +1 -1
  167. package/lib/events/hooks/auto_moderation.d.ts +2 -2
  168. package/lib/events/hooks/guild.d.ts +150 -150
  169. package/lib/events/hooks/interactions.d.ts +1 -1
  170. package/lib/events/hooks/invite.d.ts +20 -20
  171. package/lib/events/hooks/message.d.ts +27 -27
  172. package/lib/events/hooks/presence.d.ts +11 -11
  173. package/lib/events/hooks/soundboard.d.ts +6 -6
  174. package/lib/events/hooks/stage.d.ts +2 -2
  175. package/lib/events/hooks/subscriptions.d.ts +3 -3
  176. package/lib/events/hooks/thread.d.ts +30 -30
  177. package/lib/events/hooks/voice.d.ts +3 -4
  178. package/lib/events/hooks/voice.js +2 -1
  179. package/lib/events/utils.d.ts +4 -0
  180. package/lib/events/utils.js +59 -0
  181. package/lib/index.d.ts +9 -4
  182. package/lib/index.js +13 -8
  183. package/lib/langs/handler.d.ts +14 -11
  184. package/lib/langs/handler.js +46 -9
  185. package/lib/langs/router.d.ts +10 -3
  186. package/lib/structures/Application.d.ts +1 -1
  187. package/lib/structures/Emoji.d.ts +3 -3
  188. package/lib/structures/Emoji.js +2 -2
  189. package/lib/structures/Guild.d.ts +154 -154
  190. package/lib/structures/GuildBan.d.ts +4 -4
  191. package/lib/structures/GuildBan.js +3 -3
  192. package/lib/structures/GuildMember.d.ts +7 -7
  193. package/lib/structures/GuildMember.js +28 -7
  194. package/lib/structures/GuildRole.d.ts +1 -1
  195. package/lib/structures/GuildRole.js +2 -2
  196. package/lib/structures/Interaction.d.ts +11 -9
  197. package/lib/structures/Interaction.js +33 -12
  198. package/lib/structures/Message.d.ts +21 -14
  199. package/lib/structures/Message.js +29 -14
  200. package/lib/structures/User.d.ts +1 -1
  201. package/lib/structures/VoiceState.d.ts +4 -0
  202. package/lib/structures/VoiceState.js +13 -1
  203. package/lib/structures/Webhook.d.ts +9 -1
  204. package/lib/structures/Webhook.js +4 -1
  205. package/lib/structures/channels.d.ts +148 -134
  206. package/lib/structures/channels.js +27 -26
  207. package/lib/structures/extra/BitField.d.ts +4 -4
  208. package/lib/structures/extra/BitField.js +20 -4
  209. package/lib/structures/extra/DiscordBase.js +1 -1
  210. package/lib/structures/extra/Permissions.d.ts +2 -4
  211. package/lib/structures/extra/Permissions.js +1 -17
  212. package/lib/types/payloads/_interactions/responses.d.ts +2 -2
  213. package/lib/types/payloads/components.d.ts +4 -4
  214. package/lib/websocket/SharedTypes.d.ts +4 -4
  215. package/lib/websocket/constants/index.d.ts +1 -1
  216. package/lib/websocket/constants/index.js +3 -2
  217. package/lib/websocket/discord/events/memberUpdate.js +2 -2
  218. package/lib/websocket/discord/heartbeater.d.ts +1 -0
  219. package/lib/websocket/discord/heartbeater.js +7 -0
  220. package/lib/websocket/discord/shard.d.ts +2 -2
  221. package/lib/websocket/discord/shard.js +15 -13
  222. package/lib/websocket/discord/sharder.d.ts +8 -7
  223. package/lib/websocket/discord/sharder.js +25 -5
  224. package/lib/websocket/discord/shared.d.ts +19 -6
  225. package/lib/websocket/discord/socket/custom.js +5 -0
  226. package/lib/websocket/discord/worker.d.ts +1 -0
  227. package/lib/websocket/discord/worker.js +2 -0
  228. package/lib/websocket/discord/workermanager.d.ts +25 -11
  229. package/lib/websocket/discord/workermanager.js +41 -10
  230. package/package.json +12 -16
@@ -8,8 +8,9 @@ import { PresenceUpdateHandler } from '../websocket/discord/events/presenceUpdat
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 {};
@@ -9,9 +9,10 @@ const memberUpdate_1 = require("../websocket/discord/events/memberUpdate");
9
9
  const presenceUpdate_1 = require("../websocket/discord/events/presenceUpdate");
10
10
  const base_1 = require("./base");
11
11
  const collectors_1 = require("./collectors");
12
+ const plugins_1 = require("./plugins");
12
13
  const transformers_1 = require("./transformers");
13
14
  let parentPort;
14
- class Client extends base_1.BaseClient {
15
+ class ClientBase extends base_1.BaseClient {
15
16
  gateway;
16
17
  me;
17
18
  memberUpdateHandler = new memberUpdate_1.MemberUpdateHandler();
@@ -46,6 +47,8 @@ class Client extends base_1.BaseClient {
46
47
  await oldOnShardReconnect?.(data);
47
48
  await this.onShardReconnect(data);
48
49
  };
50
+ const oldHandleSendPayload = gateway.options.handleSendPayload;
51
+ gateway.options.handleSendPayload = (shardId, payload) => this.handleGatewaySendPayload(shardId, payload, oldHandleSendPayload);
49
52
  this.gateway = gateway;
50
53
  }
51
54
  }
@@ -62,10 +65,12 @@ class Client extends base_1.BaseClient {
62
65
  }
63
66
  async loadEvents(dir) {
64
67
  dir ??= await this.getRC().then(x => x.locations.events);
68
+ await (0, plugins_1.runPluginHooks)(this, 'events:beforeLoad', this, dir);
65
69
  if (dir) {
66
70
  await this.events.load(dir);
67
71
  this.logger.info('EventHandler loaded');
68
72
  }
73
+ await (0, plugins_1.runPluginHooks)(this, 'events:afterLoad', this, dir);
69
74
  }
70
75
  async execute(options = {}) {
71
76
  await super.execute(options);
@@ -80,7 +85,9 @@ class Client extends base_1.BaseClient {
80
85
  this.gateway.options.handlePayload(data.shardId, data.payload);
81
86
  break;
82
87
  case 'SEND_TO_SHARD':
83
- 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
+ });
84
91
  break;
85
92
  }
86
93
  });
@@ -94,10 +101,12 @@ class Client extends base_1.BaseClient {
94
101
  await this.loadEvents(options.eventsDir);
95
102
  const { token: tokenRC, intents: intentsRC, debug: debugRC } = await this.getRC();
96
103
  const token = options?.token ?? tokenRC;
97
- const intents = options?.connection?.intents ?? intentsRC;
98
- this.cache.intents = intents;
104
+ const connectionIntents = options?.connection?.intents;
105
+ const intents = this.resolvePluginGatewayIntents(connectionIntents ?? intentsRC);
99
106
  if (!this.gateway) {
100
- (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
+ }
101
110
  this.gateway = new websocket_1.ShardManager({
102
111
  token,
103
112
  info: await this.proxy.gateway.bot.get(),
@@ -106,6 +115,7 @@ class Client extends base_1.BaseClient {
106
115
  await this.options?.handlePayload?.(shardId, packet);
107
116
  return this.onPacket(shardId, packet);
108
117
  },
118
+ handleSendPayload: (shardId, payload) => this.handleGatewaySendPayload(shardId, payload, this.options?.handleSendPayload),
109
119
  onShardDisconnect: this.onShardDisconnect.bind(this),
110
120
  onShardReconnect: this.onShardReconnect.bind(this),
111
121
  presence: this.options?.presence,
@@ -126,13 +136,17 @@ class Client extends base_1.BaseClient {
126
136
  });
127
137
  }
128
138
  if (execute) {
129
- await this.execute(options.connection);
139
+ await this.execute({ ...(options.connection ?? {}), intents });
130
140
  }
131
141
  else {
132
142
  await super.execute(options);
133
143
  }
134
144
  }
135
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;
136
150
  Promise.allSettled([
137
151
  this.events.runEvent('RAW', this, packet, shardId, false),
138
152
  this.collectors.run('RAW', packet, this),
@@ -141,7 +155,7 @@ class Client extends base_1.BaseClient {
141
155
  case 'GUILD_MEMBER_UPDATE':
142
156
  {
143
157
  if (!this.memberUpdateHandler.check(packet.d)) {
144
- return;
158
+ return packet;
145
159
  }
146
160
  await this.events.execute(packet, this, shardId);
147
161
  }
@@ -149,7 +163,7 @@ class Client extends base_1.BaseClient {
149
163
  case 'PRESENCE_UPDATE':
150
164
  {
151
165
  if (!this.presenceUpdateHandler.check(packet.d)) {
152
- return;
166
+ return packet;
153
167
  }
154
168
  await this.events.execute(packet, this, shardId);
155
169
  }
@@ -192,6 +206,16 @@ class Client extends base_1.BaseClient {
192
206
  break;
193
207
  }
194
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;
195
219
  }
196
220
  }
197
- 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;