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
|
@@ -182,6 +182,10 @@ class SeyfertWebSocket {
|
|
|
182
182
|
this.socket?.removeAllListeners();
|
|
183
183
|
this.socket?.destroy();
|
|
184
184
|
this.socket = undefined;
|
|
185
|
+
for (const [, promise] of this.__promises) {
|
|
186
|
+
promise.reject(new Error('WebSocket closed'));
|
|
187
|
+
}
|
|
188
|
+
this.__promises.clear();
|
|
185
189
|
if (this.__closeCalled)
|
|
186
190
|
return;
|
|
187
191
|
this.#emitClose(this.__lastError ?? {
|
|
@@ -287,6 +291,7 @@ class SeyfertWebSocket {
|
|
|
287
291
|
})
|
|
288
292
|
.finally(() => {
|
|
289
293
|
clearTimeout(timeout);
|
|
294
|
+
this.__promises.delete(id);
|
|
290
295
|
});
|
|
291
296
|
}
|
|
292
297
|
#randomUUID() {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ApiRequestOptions, CustomWorkerClientEvents, HttpMethods } from '../..';
|
|
2
2
|
import type { Identify } from '../../common';
|
|
3
3
|
import type { GatewayDispatchPayload } from '../../types';
|
|
4
|
+
export declare const WORKER_TIMEOUT_MS = 60000;
|
|
4
5
|
export interface WorkerShardInfo {
|
|
5
6
|
open: boolean;
|
|
6
7
|
shardId: number;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Worker as ClusterWorker } from 'node:cluster';
|
|
1
|
+
import cluster, { type Worker as ClusterWorker } from 'node:cluster';
|
|
2
2
|
import type { Worker as WorkerThreadsWorker } from 'node:worker_threads';
|
|
3
3
|
import { ApiHandler, type CustomWorkerManagerEvents, Logger, type UsingClient, type WorkerClient } from '../..';
|
|
4
4
|
import { type Adapter } from '../../cache';
|
|
@@ -7,7 +7,22 @@ import type { GatewayPresenceUpdateData, GatewaySendPayload } from '../../types'
|
|
|
7
7
|
import { ConnectQueue } from '../structures/timeout';
|
|
8
8
|
import { Heartbeater, type WorkerHeartbeaterMessages } from './heartbeater';
|
|
9
9
|
import type { ShardOptions, WorkerData, WorkerManagerOptions } from './shared';
|
|
10
|
-
import type
|
|
10
|
+
import { type WorkerInfo, type WorkerMessages, type WorkerShardInfo } from './worker';
|
|
11
|
+
type WorkerManagerConstructorOptionalKeys = 'token' | 'intents' | 'info' | 'handlePayload' | 'handleWorkerMessage';
|
|
12
|
+
type WorkerManagerConstructorOptions = WorkerManagerOptions extends infer Options ? Options extends WorkerManagerOptions ? Omit<Options, WorkerManagerConstructorOptionalKeys | 'resharding'> & Partial<Pick<Options, WorkerManagerConstructorOptionalKeys>> & {
|
|
13
|
+
resharding?: PickPartial<NonNullable<WorkerManagerOptions['resharding']>, 'getInfo'>;
|
|
14
|
+
} : never : never;
|
|
15
|
+
type WorkerManagerNativeOptions = Exclude<WorkerManagerOptions, {
|
|
16
|
+
mode: 'custom';
|
|
17
|
+
}>;
|
|
18
|
+
type WorkerManagerCustomOptions = Extract<WorkerManagerOptions, {
|
|
19
|
+
mode: 'custom';
|
|
20
|
+
}>;
|
|
21
|
+
type WorkerManagerRuntimeOptionalKeys = 'adapter' | 'handleWorkerMessage' | 'handlePayload' | 'getRC';
|
|
22
|
+
type WorkerManagerCustomRuntimeOptionalKeys = 'handleWorkerMessage' | 'handlePayload' | 'getRC';
|
|
23
|
+
type WorkerManagerRuntimeOptions = PickPartial<Required<WorkerManagerNativeOptions>, WorkerManagerRuntimeOptionalKeys> | (PickPartial<Required<Omit<WorkerManagerCustomOptions, 'path'>>, WorkerManagerCustomRuntimeOptionalKeys> & {
|
|
24
|
+
path?: string;
|
|
25
|
+
});
|
|
11
26
|
export declare class WorkerManager extends Map<number, (ClusterWorker | WorkerThreadsWorker | {
|
|
12
27
|
ready?: boolean;
|
|
13
28
|
}) & {
|
|
@@ -20,7 +35,7 @@ export declare class WorkerManager extends Map<number, (ClusterWorker | WorkerTh
|
|
|
20
35
|
shardEnd: number;
|
|
21
36
|
shardsPerWorker: number;
|
|
22
37
|
}, logger?: Logger): number[][];
|
|
23
|
-
options:
|
|
38
|
+
options: WorkerManagerRuntimeOptions;
|
|
24
39
|
debugger?: Logger;
|
|
25
40
|
connectQueue: ConnectQueue;
|
|
26
41
|
workerQueue: (() => void)[];
|
|
@@ -33,9 +48,7 @@ export declare class WorkerManager extends Map<number, (ClusterWorker | WorkerTh
|
|
|
33
48
|
reshardingWorkerQueue: (() => void)[];
|
|
34
49
|
private _info?;
|
|
35
50
|
heartbeater: Heartbeater;
|
|
36
|
-
constructor(options:
|
|
37
|
-
resharding?: PickPartial<NonNullable<WorkerManagerOptions['resharding']>, 'getInfo'>;
|
|
38
|
-
});
|
|
51
|
+
constructor(options: WorkerManagerConstructorOptions);
|
|
39
52
|
setCache(adapter: Adapter): void;
|
|
40
53
|
setRest(rest: ApiHandler): void;
|
|
41
54
|
get remaining(): number;
|
|
@@ -56,18 +69,19 @@ export declare class WorkerManager extends Map<number, (ClusterWorker | WorkerTh
|
|
|
56
69
|
calculateWorkerId(shardId: number): number;
|
|
57
70
|
postMessage(id: number, body: ManagerMessages | WorkerHeartbeaterMessages): void;
|
|
58
71
|
prepareWorkers(shards: number[][], rawResharding?: boolean): void;
|
|
59
|
-
createWorker(workerData: WorkerData):
|
|
72
|
+
createWorker(workerData: WorkerData): WorkerThreadsWorker | ({
|
|
60
73
|
ready?: boolean;
|
|
61
74
|
} & {
|
|
62
75
|
ready?: boolean;
|
|
63
76
|
disconnected?: boolean;
|
|
64
77
|
resharded?: boolean;
|
|
65
|
-
});
|
|
78
|
+
}) | cluster.Worker;
|
|
66
79
|
spawn(workerId: number, shardId: number, resharding?: boolean): void;
|
|
67
80
|
handleWorkerMessage(message: WorkerMessages): Promise<void>;
|
|
68
81
|
private generateNonce;
|
|
69
82
|
private generateSendPromise;
|
|
70
|
-
send(data: GatewaySendPayload, shardId: number): Promise<
|
|
83
|
+
send(data: GatewaySendPayload, shardId: number): Promise<boolean>;
|
|
84
|
+
private resolveSendPayload;
|
|
71
85
|
getShardInfo(shardId: number): Promise<WorkerShardInfo>;
|
|
72
86
|
getWorkerInfo(workerId: number): Promise<WorkerInfo>;
|
|
73
87
|
tellWorker<R, V extends Record<string, unknown>>(workerId: number, func: (_: WorkerClient & UsingClient, vars: V) => R, vars: V): Promise<R>;
|
|
@@ -80,11 +94,11 @@ type CreateManagerMessage<T extends string, D extends object = object> = {
|
|
|
80
94
|
} & D;
|
|
81
95
|
export type ManagerAllowConnect = CreateManagerMessage<'ALLOW_CONNECT', {
|
|
82
96
|
shardId: number;
|
|
83
|
-
presence
|
|
97
|
+
presence?: GatewayPresenceUpdateData;
|
|
84
98
|
}>;
|
|
85
99
|
export type ManagerAllowConnectResharding = CreateManagerMessage<'ALLOW_CONNECT_RESHARDING', {
|
|
86
100
|
shardId: number;
|
|
87
|
-
presence
|
|
101
|
+
presence?: GatewayPresenceUpdateData;
|
|
88
102
|
}>;
|
|
89
103
|
export type ManagerWorkerAlreadyExistsResharding = CreateManagerMessage<'WORKER_ALREADY_EXISTS_RESHARDING'>;
|
|
90
104
|
export type ManagerSpawnShards = CreateManagerMessage<'SPAWN_SHARDS', Pick<ShardOptions, 'info' | 'properties' | 'compress'>>;
|
|
@@ -14,6 +14,7 @@ const constants_1 = require("../constants");
|
|
|
14
14
|
const structures_1 = require("../structures");
|
|
15
15
|
const timeout_1 = require("../structures/timeout");
|
|
16
16
|
const heartbeater_1 = require("./heartbeater");
|
|
17
|
+
const worker_1 = require("./worker");
|
|
17
18
|
class WorkerManager extends Map {
|
|
18
19
|
static prepareSpaces(options, logger) {
|
|
19
20
|
logger?.info('Preparing buckets');
|
|
@@ -39,7 +40,8 @@ class WorkerManager extends Map {
|
|
|
39
40
|
heartbeater;
|
|
40
41
|
constructor(options) {
|
|
41
42
|
super();
|
|
42
|
-
|
|
43
|
+
// The constructor permits runtime config values that start() fills before use.
|
|
44
|
+
this.options = { mode: 'threads', ...options };
|
|
43
45
|
this.cacheAdapter = new cache_1.MemoryAdapter();
|
|
44
46
|
if (this.options.handleWorkerMessage) {
|
|
45
47
|
const oldFn = this.handleWorkerMessage.bind(this);
|
|
@@ -90,12 +92,28 @@ class WorkerManager extends Map {
|
|
|
90
92
|
});
|
|
91
93
|
}
|
|
92
94
|
const data = await this.getWorkerInfo(id);
|
|
95
|
+
if (!data.shards.length)
|
|
96
|
+
return 0;
|
|
93
97
|
return data.shards.reduce((acc, prv) => acc + prv.latency, 0) / data.shards.length;
|
|
94
98
|
}
|
|
95
99
|
calculateShardId(guildId) {
|
|
96
100
|
return Number((BigInt(guildId) >> 22n) % BigInt(this.totalShards));
|
|
97
101
|
}
|
|
98
102
|
calculateWorkerId(shardId) {
|
|
103
|
+
if (shardId < this.shardStart || shardId >= this.shardEnd) {
|
|
104
|
+
throw new common_1.SeyfertError('INVALID_SHARD_ID', {
|
|
105
|
+
metadata: {
|
|
106
|
+
...{
|
|
107
|
+
shardId,
|
|
108
|
+
shardStart: this.shardStart,
|
|
109
|
+
shardEnd: this.shardEnd,
|
|
110
|
+
shardsPerWorker: this.shardsPerWorker,
|
|
111
|
+
totalWorkers: this.totalWorkers,
|
|
112
|
+
},
|
|
113
|
+
detail: 'Invalid shardId',
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
}
|
|
99
117
|
const workerId = Math.floor((shardId - this.shardStart) / this.shardsPerWorker);
|
|
100
118
|
if (workerId >= this.totalWorkers) {
|
|
101
119
|
throw new common_1.SeyfertError('INVALID_SHARD_ID', {
|
|
@@ -138,7 +156,7 @@ class WorkerManager extends Map {
|
|
|
138
156
|
for (let i = 0; i < shards.length; i++) {
|
|
139
157
|
const registerWorker = (resharding) => {
|
|
140
158
|
const worker = this.createWorker({
|
|
141
|
-
path: this.options.path,
|
|
159
|
+
path: this.options.path ?? '',
|
|
142
160
|
debug: this.options.debug,
|
|
143
161
|
token: this.options.token,
|
|
144
162
|
shards: shards[i],
|
|
@@ -156,15 +174,19 @@ class WorkerManager extends Map {
|
|
|
156
174
|
compress: this.options.compress,
|
|
157
175
|
});
|
|
158
176
|
this.set(i, worker);
|
|
177
|
+
return i;
|
|
178
|
+
};
|
|
179
|
+
const registerWorkerHeartbeat = (workerId, resharding) => {
|
|
180
|
+
this.heartbeater.register(workerId, deadWorkerId => {
|
|
181
|
+
this.heartbeater.unregister(deadWorkerId);
|
|
182
|
+
this.delete(deadWorkerId);
|
|
183
|
+
registerWorkerHeartbeat(registerWorker(resharding), resharding);
|
|
184
|
+
});
|
|
159
185
|
};
|
|
160
186
|
const workerExists = this.has(i);
|
|
161
187
|
if (rawResharding || !workerExists) {
|
|
162
188
|
this[rawResharding ? 'reshardingWorkerQueue' : 'workerQueue'].push(() => {
|
|
163
|
-
registerWorker(rawResharding);
|
|
164
|
-
this.heartbeater.register(i, () => {
|
|
165
|
-
this.delete(i);
|
|
166
|
-
registerWorker(false);
|
|
167
|
-
});
|
|
189
|
+
registerWorkerHeartbeat(registerWorker(rawResharding), rawResharding);
|
|
168
190
|
});
|
|
169
191
|
}
|
|
170
192
|
}
|
|
@@ -462,7 +484,7 @@ class WorkerManager extends Map {
|
|
|
462
484
|
const timeout = setTimeout(() => {
|
|
463
485
|
this.promises.delete(nonce);
|
|
464
486
|
rej(new common_1.SeyfertError('WORKER_TIMEOUT', { metadata: { ...{ nonce }, detail: message } }));
|
|
465
|
-
},
|
|
487
|
+
}, worker_1.WORKER_TIMEOUT_MS);
|
|
466
488
|
this.promises.set(nonce, { resolve: res, timeout });
|
|
467
489
|
});
|
|
468
490
|
}
|
|
@@ -472,15 +494,24 @@ class WorkerManager extends Map {
|
|
|
472
494
|
if (!worker) {
|
|
473
495
|
throw new common_1.SeyfertError('INTERNAL_ERROR', { metadata: { detail: `Worker #${workerId} doesn't exist` } });
|
|
474
496
|
}
|
|
497
|
+
const payload = await this.resolveSendPayload(shardId, data);
|
|
498
|
+
if (!payload)
|
|
499
|
+
return false;
|
|
475
500
|
const nonce = this.generateNonce();
|
|
476
501
|
this.postMessage(workerId, {
|
|
477
502
|
type: 'SEND_PAYLOAD',
|
|
478
503
|
shardId,
|
|
479
504
|
nonce,
|
|
480
|
-
...
|
|
505
|
+
...payload,
|
|
481
506
|
});
|
|
482
507
|
return this.generateSendPromise(nonce, 'Shard send payload timeout');
|
|
483
508
|
}
|
|
509
|
+
async resolveSendPayload(shardId, payload) {
|
|
510
|
+
const result = await this.options.handleSendPayload?.(shardId, payload);
|
|
511
|
+
if (result === null)
|
|
512
|
+
return null;
|
|
513
|
+
return result ?? payload;
|
|
514
|
+
}
|
|
484
515
|
async getShardInfo(shardId) {
|
|
485
516
|
const workerId = this.calculateWorkerId(shardId);
|
|
486
517
|
const worker = this.has(workerId);
|
|
@@ -521,7 +552,7 @@ class WorkerManager extends Map {
|
|
|
521
552
|
const rc = (await this.options.getRC?.()) ??
|
|
522
553
|
(await base_1.BaseClient.prototype.getRC());
|
|
523
554
|
this.options.debug ||= rc.debug ?? false;
|
|
524
|
-
this.options.intents
|
|
555
|
+
this.options.intents ??= rc.intents ?? 0;
|
|
525
556
|
this.options.token ??= rc.token;
|
|
526
557
|
this.rest ??= new __1.ApiHandler({
|
|
527
558
|
token: this.options.token,
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "seyfert",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "The most advanced framework for discord bots",
|
|
5
|
+
"packageManager": "pnpm@11.11.0",
|
|
5
6
|
"main": "./lib/index.js",
|
|
6
7
|
"module": "./lib/index.js",
|
|
7
8
|
"types": "./lib/index.d.ts",
|
|
@@ -16,19 +17,20 @@
|
|
|
16
17
|
"format": "biome format --write ./src",
|
|
17
18
|
"check-h": "biome check --write ./src",
|
|
18
19
|
"check": "biome check --verbose --write --no-errors-on-unmatched ./src",
|
|
19
|
-
"test": "
|
|
20
|
+
"test:types": "pnpm run build && tsc --noEmit --project tests/tsconfig.json",
|
|
21
|
+
"test": "pnpm run test:types && vitest run --config ./tests/vitest.config.mts ./tests/"
|
|
20
22
|
},
|
|
21
23
|
"author": "MARCROCK22",
|
|
22
24
|
"license": "MIT",
|
|
23
25
|
"devDependencies": {
|
|
24
|
-
"@biomejs/biome": "2.3
|
|
25
|
-
"@changesets/cli": "^2.
|
|
26
|
-
"@commitlint/cli": "^
|
|
27
|
-
"@commitlint/config-conventional": "^
|
|
28
|
-
"@types/node": "^
|
|
26
|
+
"@biomejs/biome": "2.5.3",
|
|
27
|
+
"@changesets/cli": "^2.31.0",
|
|
28
|
+
"@commitlint/cli": "^21.2.1",
|
|
29
|
+
"@commitlint/config-conventional": "^21.2.0",
|
|
30
|
+
"@types/node": "^26.1.1",
|
|
29
31
|
"husky": "^9.1.7",
|
|
30
|
-
"typescript": "^
|
|
31
|
-
"vitest": "^
|
|
32
|
+
"typescript": "^6.0.3",
|
|
33
|
+
"vitest": "^4.1.10"
|
|
32
34
|
},
|
|
33
35
|
"homepage": "https://seyfert.dev",
|
|
34
36
|
"repository": {
|
|
@@ -63,11 +65,5 @@
|
|
|
63
65
|
"name": "David",
|
|
64
66
|
"url": "https://github.com/Drylozu"
|
|
65
67
|
}
|
|
66
|
-
]
|
|
67
|
-
"pnpm": {
|
|
68
|
-
"onlyBuiltDependencies": [
|
|
69
|
-
"@biomejs/biome",
|
|
70
|
-
"esbuild"
|
|
71
|
-
]
|
|
72
|
-
}
|
|
68
|
+
]
|
|
73
69
|
}
|