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.
- package/lib/api/Routes/cdn.d.ts +2 -2
- package/lib/api/Routes/guilds.d.ts +2 -2
- package/lib/api/Routes/invites.d.ts +2 -2
- package/lib/api/api.d.ts +20 -8
- package/lib/api/api.js +198 -44
- package/lib/api/shared.d.ts +30 -1
- package/lib/api/utils/constants.d.ts +1 -1
- package/lib/api/utils/constants.js +1 -1
- package/lib/api/utils/utils.d.ts +2 -1
- package/lib/api/utils/utils.js +1 -1
- package/lib/builders/Attachment.d.ts +1 -1
- package/lib/builders/Attachment.js +30 -8
- package/lib/builders/MediaGallery.d.ts +2 -2
- package/lib/builders/MediaGallery.js +10 -0
- package/lib/builders/Modal.d.ts +18 -8
- package/lib/builders/Modal.js +36 -7
- package/lib/builders/Poll.js +18 -0
- package/lib/builders/RadioGroup.d.ts +4 -3
- package/lib/builders/RadioGroup.js +24 -3
- package/lib/builders/SelectMenu.d.ts +8 -6
- package/lib/builders/SelectMenu.js +24 -3
- package/lib/builders/types.d.ts +3 -2
- package/lib/cache/adapters/default.d.ts +1 -1
- package/lib/cache/adapters/default.js +23 -26
- package/lib/cache/adapters/limited.d.ts +1 -0
- package/lib/cache/adapters/limited.js +47 -33
- package/lib/cache/index.d.ts +19 -25
- package/lib/cache/index.js +58 -6
- package/lib/cache/resources/bans.d.ts +1 -1
- package/lib/cache/resources/bans.js +4 -4
- package/lib/cache/resources/channels.d.ts +1 -1
- package/lib/cache/resources/channels.js +4 -4
- package/lib/cache/resources/default/base.d.ts +1 -1
- package/lib/cache/resources/default/base.js +8 -8
- package/lib/cache/resources/default/guild-based.d.ts +5 -5
- package/lib/cache/resources/default/guild-based.js +29 -16
- package/lib/cache/resources/default/guild-related.d.ts +5 -5
- package/lib/cache/resources/default/guild-related.js +14 -14
- package/lib/cache/resources/emojis.d.ts +1 -1
- package/lib/cache/resources/emojis.js +4 -4
- package/lib/cache/resources/guilds.js +28 -15
- package/lib/cache/resources/members.d.ts +1 -1
- package/lib/cache/resources/members.js +6 -6
- package/lib/cache/resources/messages.d.ts +7 -2
- package/lib/cache/resources/messages.js +43 -20
- package/lib/cache/resources/overwrites.d.ts +1 -1
- package/lib/cache/resources/overwrites.js +5 -8
- package/lib/cache/resources/roles.d.ts +1 -1
- package/lib/cache/resources/roles.js +4 -4
- package/lib/cache/resources/stickers.d.ts +1 -1
- package/lib/cache/resources/stickers.js +4 -4
- package/lib/cache/resources/users.js +4 -4
- package/lib/cache/resources/voice-states.d.ts +1 -1
- package/lib/cache/resources/voice-states.js +4 -4
- package/lib/client/base.d.ts +83 -24
- package/lib/client/base.js +594 -39
- package/lib/client/client.d.ts +28 -3
- package/lib/client/client.js +33 -9
- package/lib/client/collectors.d.ts +9 -8
- package/lib/client/collectors.js +19 -52
- package/lib/client/httpclient.d.ts +3 -0
- package/lib/client/index.d.ts +3 -1
- package/lib/client/index.js +4 -0
- package/lib/client/intents.d.ts +3 -0
- package/lib/client/intents.js +9 -0
- package/lib/client/plugins/api.d.ts +4 -0
- package/lib/client/plugins/api.js +550 -0
- package/lib/client/plugins/errors.d.ts +25 -0
- package/lib/client/plugins/errors.js +79 -0
- package/lib/client/plugins/order.d.ts +10 -0
- package/lib/client/plugins/order.js +32 -0
- package/lib/client/plugins/registry.d.ts +273 -0
- package/lib/client/plugins/registry.js +868 -0
- package/lib/client/plugins/shared.d.ts +23 -0
- package/lib/client/plugins/shared.js +193 -0
- package/lib/client/plugins/types.d.ts +398 -0
- package/lib/client/plugins/types.js +8 -0
- package/lib/client/plugins.d.ts +78 -0
- package/lib/client/plugins.js +558 -0
- package/lib/client/transformers.d.ts +33 -33
- package/lib/client/workerclient.d.ts +10 -1
- package/lib/client/workerclient.js +27 -17
- package/lib/collection.d.ts +10 -8
- package/lib/collection.js +19 -25
- package/lib/commands/applications/chat.d.ts +20 -18
- package/lib/commands/applications/chat.js +39 -14
- package/lib/commands/applications/chatcontext.d.ts +23 -15
- package/lib/commands/applications/chatcontext.js +23 -2
- package/lib/commands/applications/entryPoint.d.ts +4 -3
- package/lib/commands/applications/entryPoint.js +1 -1
- package/lib/commands/applications/entrycontext.d.ts +7 -9
- package/lib/commands/applications/entrycontext.js +3 -1
- package/lib/commands/applications/menu.d.ts +4 -3
- package/lib/commands/applications/menucontext.d.ts +7 -9
- package/lib/commands/applications/menucontext.js +3 -1
- package/lib/commands/applications/options.d.ts +23 -23
- package/lib/commands/applications/shared.d.ts +39 -17
- package/lib/commands/decorators.d.ts +50 -38
- package/lib/commands/decorators.js +15 -5
- package/lib/commands/handle.d.ts +19 -8
- package/lib/commands/handle.js +224 -143
- package/lib/commands/handler.d.ts +21 -8
- package/lib/commands/handler.js +157 -69
- package/lib/commands/index.d.ts +1 -0
- package/lib/commands/optionresolver.d.ts +2 -2
- package/lib/common/it/colors.js +12 -2
- package/lib/common/it/error.d.ts +9 -0
- package/lib/common/it/error.js +8 -0
- package/lib/common/it/fake-promise.d.ts +4 -0
- package/lib/common/it/fake-promise.js +10 -0
- package/lib/common/it/formatter.d.ts +14 -11
- package/lib/common/it/formatter.js +4 -3
- package/lib/common/it/logger.d.ts +7 -1
- package/lib/common/it/logger.js +24 -6
- package/lib/common/it/utils.d.ts +6 -8
- package/lib/common/it/utils.js +44 -42
- package/lib/common/shorters/application.d.ts +3 -3
- package/lib/common/shorters/application.js +3 -2
- package/lib/common/shorters/bans.d.ts +8 -4
- package/lib/common/shorters/bans.js +13 -5
- package/lib/common/shorters/channels.d.ts +4 -4
- package/lib/common/shorters/channels.js +4 -4
- package/lib/common/shorters/emojis.js +1 -0
- package/lib/common/shorters/guilds.d.ts +8 -8
- package/lib/common/shorters/guilds.js +14 -31
- package/lib/common/shorters/interaction.d.ts +1 -1
- package/lib/common/shorters/invites.d.ts +201 -201
- package/lib/common/shorters/members.d.ts +7 -7
- package/lib/common/shorters/members.js +13 -14
- package/lib/common/shorters/messages.d.ts +2 -2
- package/lib/common/shorters/soundboard.d.ts +5 -5
- package/lib/common/shorters/users.d.ts +1 -1
- package/lib/common/shorters/webhook.d.ts +3 -2
- package/lib/common/shorters/webhook.js +0 -7
- package/lib/common/types/options.d.ts +4 -0
- package/lib/common/types/util.d.ts +8 -0
- package/lib/common/types/write.d.ts +2 -1
- package/lib/components/BaseSelectMenuComponent.d.ts +1 -1
- package/lib/components/BaseSelectMenuComponent.js +1 -1
- package/lib/components/ButtonComponent.d.ts +3 -3
- package/lib/components/ChannelSelectMenuComponent.d.ts +2 -2
- package/lib/components/File.d.ts +1 -1
- package/lib/components/MediaGallery.d.ts +1 -1
- package/lib/components/MentionableSelectMenuComponent.d.ts +1 -1
- package/lib/components/RoleSelectMenuComponent.d.ts +1 -1
- package/lib/components/Separator.d.ts +1 -1
- package/lib/components/StringSelectMenuComponent.d.ts +1 -1
- package/lib/components/TextInputComponent.d.ts +1 -1
- package/lib/components/Thumbnail.d.ts +1 -1
- package/lib/components/UserSelectMenuComponent.d.ts +1 -1
- package/lib/components/componentcommand.d.ts +8 -7
- package/lib/components/componentcontext.d.ts +24 -36
- package/lib/components/componentcontext.js +7 -17
- package/lib/components/handler.d.ts +17 -7
- package/lib/components/handler.js +108 -49
- package/lib/components/index.d.ts +1 -0
- package/lib/components/index.js +1 -0
- package/lib/components/interactioncontext.d.ts +45 -0
- package/lib/components/interactioncontext.js +93 -0
- package/lib/components/modalcommand.d.ts +5 -4
- package/lib/components/modalcontext.d.ts +39 -20
- package/lib/components/modalcontext.js +59 -6
- package/lib/events/event.d.ts +9 -3
- package/lib/events/handler.d.ts +51 -6
- package/lib/events/handler.js +165 -36
- package/lib/events/hooks/application_command.d.ts +1 -1
- package/lib/events/hooks/auto_moderation.d.ts +2 -2
- package/lib/events/hooks/guild.d.ts +150 -150
- package/lib/events/hooks/interactions.d.ts +1 -1
- package/lib/events/hooks/invite.d.ts +20 -20
- package/lib/events/hooks/message.d.ts +27 -27
- package/lib/events/hooks/presence.d.ts +11 -11
- package/lib/events/hooks/soundboard.d.ts +6 -6
- package/lib/events/hooks/stage.d.ts +2 -2
- package/lib/events/hooks/subscriptions.d.ts +3 -3
- package/lib/events/hooks/thread.d.ts +30 -30
- package/lib/events/hooks/voice.d.ts +3 -4
- package/lib/events/hooks/voice.js +2 -1
- package/lib/events/utils.d.ts +4 -0
- package/lib/events/utils.js +59 -0
- package/lib/index.d.ts +9 -4
- package/lib/index.js +13 -8
- package/lib/langs/handler.d.ts +14 -11
- package/lib/langs/handler.js +46 -9
- package/lib/langs/router.d.ts +10 -3
- package/lib/structures/Application.d.ts +1 -1
- package/lib/structures/Emoji.d.ts +3 -3
- package/lib/structures/Emoji.js +2 -2
- package/lib/structures/Guild.d.ts +154 -154
- package/lib/structures/GuildBan.d.ts +4 -4
- package/lib/structures/GuildBan.js +3 -3
- package/lib/structures/GuildMember.d.ts +7 -7
- package/lib/structures/GuildMember.js +28 -7
- package/lib/structures/GuildRole.d.ts +1 -1
- package/lib/structures/GuildRole.js +2 -2
- package/lib/structures/Interaction.d.ts +11 -9
- package/lib/structures/Interaction.js +33 -12
- package/lib/structures/Message.d.ts +21 -14
- package/lib/structures/Message.js +29 -14
- package/lib/structures/User.d.ts +1 -1
- package/lib/structures/VoiceState.d.ts +4 -0
- package/lib/structures/VoiceState.js +13 -1
- package/lib/structures/Webhook.d.ts +9 -1
- package/lib/structures/Webhook.js +4 -1
- package/lib/structures/channels.d.ts +148 -134
- package/lib/structures/channels.js +27 -26
- package/lib/structures/extra/BitField.d.ts +4 -4
- package/lib/structures/extra/BitField.js +20 -4
- package/lib/structures/extra/DiscordBase.js +1 -1
- package/lib/structures/extra/Permissions.d.ts +2 -4
- package/lib/structures/extra/Permissions.js +1 -17
- package/lib/types/payloads/_interactions/responses.d.ts +2 -2
- package/lib/types/payloads/components.d.ts +4 -4
- package/lib/websocket/SharedTypes.d.ts +4 -4
- package/lib/websocket/constants/index.d.ts +1 -1
- package/lib/websocket/constants/index.js +3 -2
- package/lib/websocket/discord/events/memberUpdate.js +2 -2
- package/lib/websocket/discord/heartbeater.d.ts +1 -0
- package/lib/websocket/discord/heartbeater.js +7 -0
- package/lib/websocket/discord/shard.d.ts +2 -2
- package/lib/websocket/discord/shard.js +15 -13
- package/lib/websocket/discord/sharder.d.ts +8 -7
- package/lib/websocket/discord/sharder.js +25 -5
- package/lib/websocket/discord/shared.d.ts +19 -6
- package/lib/websocket/discord/socket/custom.js +5 -0
- package/lib/websocket/discord/worker.d.ts +1 -0
- package/lib/websocket/discord/worker.js +2 -0
- package/lib/websocket/discord/workermanager.d.ts +25 -11
- package/lib/websocket/discord/workermanager.js +41 -10
- package/package.json +12 -16
package/lib/client/client.d.ts
CHANGED
|
@@ -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
|
-
|
|
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<
|
|
38
|
+
protected onPacket(shardId: number, packet: GatewayDispatchPayload): Promise<GatewayDispatchPayload | null>;
|
|
39
|
+
private handleGatewaySendPayload;
|
|
38
40
|
}
|
|
39
|
-
|
|
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 {};
|
package/lib/client/client.js
CHANGED
|
@@ -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
|
|
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
|
|
98
|
-
|
|
104
|
+
const connectionIntents = options?.connection?.intents;
|
|
105
|
+
const intents = this.resolvePluginGatewayIntents(connectionIntents ?? intentsRC);
|
|
99
106
|
if (!this.gateway) {
|
|
100
|
-
(
|
|
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 =
|
|
221
|
+
exports.Client = ClientBase;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { CallbackEventHandler, CustomEventsKeys, GatewayEvents } from '../events';
|
|
3
|
-
export type AllClientEvents = CustomEventsKeys |
|
|
4
|
-
|
|
5
|
-
export type
|
|
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:
|
|
14
|
-
run: (arg:
|
|
15
|
-
onRunError?: (arg:
|
|
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;
|
package/lib/client/collectors.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
43
|
-
if (!collectors)
|
|
13
|
+
if (!this.values.has(name))
|
|
44
14
|
return '*';
|
|
45
|
-
|
|
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
|
|
53
|
-
|
|
54
|
-
|
|
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(
|
|
23
|
+
this.values.get(event).push({
|
|
57
24
|
options: {
|
|
58
25
|
...options,
|
|
59
|
-
|
|
26
|
+
event,
|
|
60
27
|
},
|
|
61
28
|
idle: options.idle && options.idle > 0
|
|
62
29
|
? setTimeout(() => {
|
|
63
|
-
return this.delete(
|
|
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(
|
|
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
|
|
65
|
+
const event = normalizeCollectorEventName(name);
|
|
66
|
+
const collectors = this.values.get(event);
|
|
99
67
|
if (!collectors)
|
|
100
68
|
return;
|
|
101
|
-
const data = (await
|
|
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
|
+
}
|
package/lib/client/index.d.ts
CHANGED
|
@@ -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';
|
package/lib/client/index.js
CHANGED
|
@@ -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,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;
|