seyfert 1.0.1 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/api/CDN.d.ts +1 -1
- package/lib/api/CDN.js +0 -2
- package/lib/api/Router.js +2 -2
- package/lib/api/Routes/applications.d.ts +29 -33
- package/lib/api/Routes/channels.d.ts +11 -17
- package/lib/api/Routes/interactions.d.ts +3 -7
- package/lib/api/Routes/webhooks.d.ts +4 -6
- package/lib/builders/Attachment.d.ts +2 -3
- package/lib/cache/adapters/redis.js +6 -0
- package/lib/cache/adapters/types.d.ts +23 -23
- package/lib/cache/adapters/workeradapter.d.ts +4 -4
- package/lib/cache/adapters/workeradapter.js +10 -5
- package/lib/cache/index.d.ts +4 -5
- package/lib/cache/index.js +4 -3
- package/lib/cache/resources/default/base.d.ts +11 -10
- package/lib/cache/resources/default/guild-based.d.ts +8 -7
- package/lib/cache/resources/default/guild-based.js +8 -7
- package/lib/cache/resources/default/guild-related.d.ts +10 -9
- package/lib/cache/resources/default/guild-related.js +3 -2
- package/lib/cache/resources/guilds.js +2 -1
- package/lib/cache/resources/overwrites.d.ts +1 -1
- package/lib/cache/resources/overwrites.js +7 -1
- package/lib/client/base.d.ts +33 -179
- package/lib/client/base.js +56 -21
- package/lib/client/client.d.ts +10 -3
- package/lib/client/client.js +23 -8
- package/lib/client/oninteractioncreate.js +9 -9
- package/lib/client/onmessagecreate.js +192 -153
- package/lib/client/workerclient.d.ts +9 -3
- package/lib/client/workerclient.js +50 -23
- package/lib/collection.js +2 -2
- package/lib/commands/applications/chat.d.ts +16 -8
- package/lib/commands/applications/chat.js +20 -13
- package/lib/commands/applications/chatcontext.d.ts +6 -4
- package/lib/commands/applications/chatcontext.js +6 -1
- package/lib/commands/applications/menu.d.ts +5 -1
- package/lib/commands/applications/menu.js +11 -5
- package/lib/commands/applications/menucontext.d.ts +5 -3
- package/lib/commands/applications/menucontext.js +7 -2
- package/lib/commands/applications/options.d.ts +1 -2
- package/lib/commands/applications/shared.d.ts +5 -4
- package/lib/commands/decorators.d.ts +18 -6
- package/lib/commands/decorators.js +18 -8
- package/lib/commands/handler.d.ts +11 -5
- package/lib/commands/handler.js +46 -37
- package/lib/commands/optionresolver.d.ts +11 -4
- package/lib/commands/optionresolver.js +6 -4
- package/lib/common/index.d.ts +7 -0
- package/lib/common/index.js +7 -0
- package/lib/common/it/utils.d.ts +1 -0
- package/lib/common/it/utils.js +4 -1
- package/lib/common/shorters/channels.d.ts +67 -129
- package/lib/common/shorters/channels.js +119 -135
- package/lib/common/shorters/emojis.d.ts +47 -0
- package/lib/common/shorters/emojis.js +80 -0
- package/lib/common/shorters/guilds.d.ts +22 -249
- package/lib/common/shorters/guilds.js +51 -140
- package/lib/common/shorters/members.d.ts +82 -108
- package/lib/common/shorters/members.js +151 -166
- package/lib/common/shorters/messages.d.ts +11 -23
- package/lib/common/shorters/messages.js +58 -104
- package/lib/common/shorters/reactions.d.ts +10 -0
- package/lib/common/shorters/reactions.js +45 -0
- package/lib/common/shorters/roles.d.ts +39 -7
- package/lib/common/shorters/roles.js +74 -42
- package/lib/common/shorters/templates.d.ts +6 -8
- package/lib/common/shorters/templates.js +17 -21
- package/lib/common/shorters/users.d.ts +4 -6
- package/lib/common/shorters/users.js +29 -33
- package/lib/common/shorters/webhook.d.ts +62 -26
- package/lib/common/shorters/webhook.js +113 -58
- package/lib/common/types/options.d.ts +2 -2
- package/lib/common/types/util.d.ts +3 -0
- package/lib/components/handler.d.ts +28 -9
- package/lib/components/handler.js +28 -11
- package/lib/events/handler.d.ts +10 -2
- package/lib/events/handler.js +6 -8
- package/lib/index.d.ts +4 -2
- package/lib/index.js +1 -1
- package/lib/langs/handler.d.ts +8 -0
- package/lib/langs/handler.js +8 -2
- package/lib/structures/AutoModerationRule.d.ts +2 -2
- package/lib/structures/ClientUser.d.ts +2 -2
- package/lib/structures/Guild.d.ts +2 -2
- package/lib/structures/GuildEmoji.d.ts +4 -4
- package/lib/structures/GuildEmoji.js +7 -7
- package/lib/structures/GuildMember.d.ts +7 -6
- package/lib/structures/GuildMember.js +5 -2
- package/lib/structures/GuildPreview.d.ts +2 -2
- package/lib/structures/GuildRole.d.ts +2 -2
- package/lib/structures/GuildTemplate.d.ts +2 -2
- package/lib/structures/Interaction.d.ts +9 -10
- package/lib/structures/Interaction.js +2 -2
- package/lib/structures/Message.d.ts +8 -7
- package/lib/structures/Message.js +7 -4
- package/lib/structures/Sticker.d.ts +2 -2
- package/lib/structures/User.d.ts +1 -0
- package/lib/structures/User.js +5 -0
- package/lib/structures/Webhook.d.ts +2 -2
- package/lib/structures/Webhook.js +3 -3
- package/lib/structures/channels.d.ts +21 -22
- package/lib/structures/channels.js +13 -25
- package/lib/structures/extra/Base.d.ts +1 -2
- package/lib/structures/extra/DiscordBase.d.ts +2 -2
- package/lib/websocket/constants/index.js +1 -0
- package/lib/websocket/discord/shard.js +4 -2
- package/lib/websocket/discord/sharder.d.ts +3 -0
- package/lib/websocket/discord/sharder.js +12 -5
- package/lib/websocket/discord/shared.d.ts +1 -0
- package/lib/websocket/discord/worker.d.ts +2 -1
- package/lib/websocket/discord/workermanager.d.ts +8 -3
- package/lib/websocket/discord/workermanager.js +78 -30
- package/package.json +8 -6
|
@@ -10,7 +10,6 @@ exports.DirectoryChannel = exports.NewsChannel = exports.CategoryChannel = expor
|
|
|
10
10
|
const v10_1 = require("discord-api-types/v10");
|
|
11
11
|
const ts_mixer_1 = require("ts-mixer");
|
|
12
12
|
const builders_1 = require("../builders");
|
|
13
|
-
const Webhook_1 = require("./Webhook");
|
|
14
13
|
const DiscordBase_1 = require("./extra/DiscordBase");
|
|
15
14
|
const functions_1 = require("./extra/functions");
|
|
16
15
|
class BaseChannel extends DiscordBase_1.DiscordBase {
|
|
@@ -103,13 +102,13 @@ class BaseGuildChannel extends BaseChannel {
|
|
|
103
102
|
values: () => (this.guildId ? this.client.cache.overwrites?.values(this.guildId) ?? [] : []),
|
|
104
103
|
};
|
|
105
104
|
memberPermissions(member, checkAdmin = true) {
|
|
106
|
-
return this.client.channels.
|
|
105
|
+
return this.client.channels.memberPermissions(this.id, member, checkAdmin);
|
|
107
106
|
}
|
|
108
107
|
rolePermissions(role, checkAdmin = true) {
|
|
109
|
-
return this.client.channels.
|
|
108
|
+
return this.client.channels.rolePermissions(this.id, role, checkAdmin);
|
|
110
109
|
}
|
|
111
110
|
overwritesFor(member) {
|
|
112
|
-
return this.client.channels.
|
|
111
|
+
return this.client.channels.overwritesFor(this.id, member);
|
|
113
112
|
}
|
|
114
113
|
guild(force = false) {
|
|
115
114
|
return this.client.guilds.fetch(this.guildId, force);
|
|
@@ -147,17 +146,17 @@ class MessagesMethods extends DiscordBase_1.DiscordBase {
|
|
|
147
146
|
}
|
|
148
147
|
static reactions(ctx) {
|
|
149
148
|
return {
|
|
150
|
-
add: (messageId, emoji) => ctx.client.
|
|
151
|
-
delete: (messageId, emoji, userId = '@me') => ctx.client.
|
|
152
|
-
fetch: (messageId, emoji, query) => ctx.client.
|
|
153
|
-
purge: (messageId, emoji) => ctx.client.
|
|
149
|
+
add: (messageId, emoji) => ctx.client.reactions.add(messageId, ctx.channelId, emoji),
|
|
150
|
+
delete: (messageId, emoji, userId = '@me') => ctx.client.reactions.delete(messageId, ctx.channelId, emoji, userId),
|
|
151
|
+
fetch: (messageId, emoji, query) => ctx.client.reactions.fetch(messageId, ctx.channelId, emoji, query),
|
|
152
|
+
purge: (messageId, emoji) => ctx.client.reactions.purge(messageId, ctx.channelId, emoji),
|
|
154
153
|
};
|
|
155
154
|
}
|
|
156
155
|
static pins(ctx) {
|
|
157
156
|
return {
|
|
158
|
-
fetch: () => ctx.client.channels.pins
|
|
159
|
-
set: (messageId, reason) => ctx.client.channels.
|
|
160
|
-
delete: (messageId, reason) => ctx.client.channels.
|
|
157
|
+
fetch: () => ctx.client.channels.pins(ctx.channelId),
|
|
158
|
+
set: (messageId, reason) => ctx.client.channels.setPin(messageId, ctx.channelId, reason),
|
|
159
|
+
delete: (messageId, reason) => ctx.client.channels.deletePin(messageId, ctx.channelId, reason),
|
|
161
160
|
};
|
|
162
161
|
}
|
|
163
162
|
static transformMessageBody(body) {
|
|
@@ -254,10 +253,7 @@ class WebhookGuildMethods extends DiscordBase_1.DiscordBase {
|
|
|
254
253
|
webhooks = WebhookGuildMethods.guild({ client: this.client, guildId: this.id });
|
|
255
254
|
static guild(ctx) {
|
|
256
255
|
return {
|
|
257
|
-
list:
|
|
258
|
-
const webhooks = await ctx.client.proxy.guilds(ctx.guildId).webhooks.get();
|
|
259
|
-
return webhooks.map(webhook => new Webhook_1.Webhook(ctx.client, webhook));
|
|
260
|
-
},
|
|
256
|
+
list: () => ctx.client.webhooks.listFromChannel(ctx.guildId),
|
|
261
257
|
};
|
|
262
258
|
}
|
|
263
259
|
}
|
|
@@ -266,16 +262,8 @@ class WebhookChannelMethods extends DiscordBase_1.DiscordBase {
|
|
|
266
262
|
webhooks = WebhookChannelMethods.channel({ client: this.client, channelId: this.id });
|
|
267
263
|
static channel(ctx) {
|
|
268
264
|
return {
|
|
269
|
-
list:
|
|
270
|
-
|
|
271
|
-
return webhooks.map(webhook => new Webhook_1.Webhook(ctx.client, webhook));
|
|
272
|
-
},
|
|
273
|
-
create: async (body) => {
|
|
274
|
-
const webhook = await ctx.client.proxy.channels(ctx.channelId).webhooks.post({
|
|
275
|
-
body,
|
|
276
|
-
});
|
|
277
|
-
return new Webhook_1.Webhook(ctx.client, webhook);
|
|
278
|
-
},
|
|
265
|
+
list: () => ctx.client.webhooks.listFromChannel(ctx.channelId),
|
|
266
|
+
create: async (body) => ctx.client.webhooks.create(ctx.channelId, body),
|
|
279
267
|
};
|
|
280
268
|
}
|
|
281
269
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { UsingClient } from '../../commands';
|
|
2
2
|
import { Base } from './Base';
|
|
3
3
|
export declare class DiscordBase<Data extends Record<string, any> = {
|
|
4
4
|
id: string;
|
|
5
5
|
}> extends Base {
|
|
6
6
|
id: string;
|
|
7
|
-
constructor(client:
|
|
7
|
+
constructor(client: UsingClient,
|
|
8
8
|
/** Unique ID of the object */
|
|
9
9
|
data: Data);
|
|
10
10
|
/**
|
|
@@ -42,7 +42,9 @@ class Shard {
|
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
44
|
get latency() {
|
|
45
|
-
return this.heart.lastAck && this.heart.lastBeat
|
|
45
|
+
return this.heart.lastAck && this.heart.lastBeat
|
|
46
|
+
? this.heart.lastAck - this.heart.lastBeat
|
|
47
|
+
: Number.POSITIVE_INFINITY;
|
|
46
48
|
}
|
|
47
49
|
get isOpen() {
|
|
48
50
|
return this.websocket?.readyState === ws_1.WebSocket.OPEN;
|
|
@@ -94,7 +96,7 @@ class Shard {
|
|
|
94
96
|
d: {
|
|
95
97
|
token: `Bot ${this.options.token}`,
|
|
96
98
|
compress: this.options.compress,
|
|
97
|
-
properties: constants_1.properties,
|
|
99
|
+
properties: this.options.properties ?? constants_1.properties,
|
|
98
100
|
shard: [this.id, this.options.info.shards],
|
|
99
101
|
intents: this.options.intents,
|
|
100
102
|
presence: this.options.presence,
|
|
@@ -7,6 +7,9 @@ export declare class ShardManager extends Map<number, Shard> {
|
|
|
7
7
|
options: ShardManagerOptions;
|
|
8
8
|
debugger?: Logger;
|
|
9
9
|
constructor(options: ShardManagerOptions);
|
|
10
|
+
get totalShards(): number;
|
|
11
|
+
get shardStart(): number;
|
|
12
|
+
get shardEnd(): number;
|
|
10
13
|
get remaining(): number;
|
|
11
14
|
get concurrency(): number;
|
|
12
15
|
get latency(): number;
|
|
@@ -23,6 +23,15 @@ class ShardManager extends Map {
|
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
+
get totalShards() {
|
|
27
|
+
return this.options.totalShards ?? this.options.info.shards;
|
|
28
|
+
}
|
|
29
|
+
get shardStart() {
|
|
30
|
+
return this.options.shardStart ?? 0;
|
|
31
|
+
}
|
|
32
|
+
get shardEnd() {
|
|
33
|
+
return this.options.shardEnd ?? this.totalShards;
|
|
34
|
+
}
|
|
26
35
|
get remaining() {
|
|
27
36
|
return this.options.info.session_start_limit.remaining;
|
|
28
37
|
}
|
|
@@ -43,7 +52,7 @@ class ShardManager extends Map {
|
|
|
43
52
|
shard ??= new shard_js_1.Shard(shardId, {
|
|
44
53
|
token: this.options.token,
|
|
45
54
|
intents: this.options.intents,
|
|
46
|
-
info: { ...this.options.info, shards:
|
|
55
|
+
info: { ...this.options.info, shards: this.totalShards },
|
|
47
56
|
handlePayload: this.options.handlePayload,
|
|
48
57
|
properties: this.options.properties,
|
|
49
58
|
debugger: this.debugger,
|
|
@@ -72,12 +81,10 @@ class ShardManager extends Map {
|
|
|
72
81
|
*/
|
|
73
82
|
spawnBuckets() {
|
|
74
83
|
this.debugger?.info('#0 Preparing buckets');
|
|
75
|
-
const chunks = structures_1.SequentialBucket.chunk(new Array(this.
|
|
76
|
-
? this.options.shardEnd - this.options.shardStart
|
|
77
|
-
: this.options.totalShards), this.concurrency);
|
|
84
|
+
const chunks = structures_1.SequentialBucket.chunk(new Array(this.shardEnd - this.shardStart), this.concurrency);
|
|
78
85
|
chunks.forEach((arr, index) => {
|
|
79
86
|
for (let i = 0; i < arr.length; i++) {
|
|
80
|
-
const id = i + (index > 0 ? index * this.concurrency : 0) +
|
|
87
|
+
const id = i + (index > 0 ? index * this.concurrency : 0) + this.shardStart;
|
|
81
88
|
chunks[index][i] = this.spawn(id);
|
|
82
89
|
}
|
|
83
90
|
});
|
|
@@ -35,6 +35,7 @@ export type WorkerSendInfo = CreateWorkerMessage<'WORKER_INFO', WorkerInfo & {
|
|
|
35
35
|
nonce: string;
|
|
36
36
|
}>;
|
|
37
37
|
export type WorkerReady = CreateWorkerMessage<'WORKER_READY'>;
|
|
38
|
+
export type WorkerStart = CreateWorkerMessage<'WORKER_START'>;
|
|
38
39
|
export type WorkerSendApiRequest = CreateWorkerMessage<'WORKER_API_REQUEST', {
|
|
39
40
|
method: HttpMethods;
|
|
40
41
|
url: `/${string}`;
|
|
@@ -55,5 +56,5 @@ export type WorkerSendEval = CreateWorkerMessage<'EVAL', {
|
|
|
55
56
|
nonce: string;
|
|
56
57
|
toWorkerId: number;
|
|
57
58
|
}>;
|
|
58
|
-
export type WorkerMessage = WorkerRequestConnect | WorkerReceivePayload | WorkerSendResultPayload | WorkerSendCacheRequest | WorkerSendShardInfo | WorkerSendInfo | WorkerReady | WorkerSendApiRequest | WorkerExecuteEval | WorkerSendEvalResponse | WorkerSendEval;
|
|
59
|
+
export type WorkerMessage = WorkerRequestConnect | WorkerReceivePayload | WorkerSendResultPayload | WorkerSendCacheRequest | WorkerSendShardInfo | WorkerSendInfo | WorkerReady | WorkerSendApiRequest | WorkerExecuteEval | WorkerSendEvalResponse | WorkerSendEval | WorkerStart;
|
|
59
60
|
export {};
|
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
/// <reference types="node" />
|
|
5
5
|
/// <reference types="node" />
|
|
6
6
|
/// <reference types="node" />
|
|
7
|
-
|
|
7
|
+
/// <reference types="node" />
|
|
8
|
+
import { type Worker as ClusterWorker } from 'node:cluster';
|
|
9
|
+
import { Worker as ThreadWorker } from 'node:worker_threads';
|
|
8
10
|
import { ApiHandler } from '../..';
|
|
9
11
|
import { type Adapter } from '../../cache';
|
|
10
12
|
import { Logger, type GatewayPresenceUpdateData, type GatewaySendPayload, type MakePartial } from '../../common';
|
|
@@ -13,7 +15,7 @@ import { MemberUpdateHandler } from './events/memberUpdate';
|
|
|
13
15
|
import { PresenceUpdateHandler } from './events/presenceUpdate';
|
|
14
16
|
import type { ShardOptions, WorkerData, WorkerManagerOptions } from './shared';
|
|
15
17
|
import type { WorkerInfo, WorkerMessage, WorkerShardInfo } from './worker';
|
|
16
|
-
export declare class WorkerManager extends Map<number,
|
|
18
|
+
export declare class WorkerManager extends Map<number, (ClusterWorker | ThreadWorker) & {
|
|
17
19
|
ready?: boolean;
|
|
18
20
|
}> {
|
|
19
21
|
options: Required<WorkerManagerOptions>;
|
|
@@ -34,6 +36,8 @@ export declare class WorkerManager extends Map<number, Worker & {
|
|
|
34
36
|
get concurrency(): number;
|
|
35
37
|
get totalWorkers(): number;
|
|
36
38
|
get totalShards(): number;
|
|
39
|
+
get shardStart(): number;
|
|
40
|
+
get shardEnd(): number;
|
|
37
41
|
get shardsPerWorker(): number;
|
|
38
42
|
get workers(): number;
|
|
39
43
|
syncLatency({ shardId, workerId }: {
|
|
@@ -43,8 +47,9 @@ export declare class WorkerManager extends Map<number, Worker & {
|
|
|
43
47
|
calculateShardId(guildId: string): number;
|
|
44
48
|
calculateWorkerId(shardId: number): number;
|
|
45
49
|
prepareSpaces(): number[][];
|
|
50
|
+
postMessage(id: number, body: any): void;
|
|
46
51
|
prepareWorkers(shards: number[][]): Promise<void>;
|
|
47
|
-
createWorker(workerData: WorkerData):
|
|
52
|
+
createWorker(workerData: WorkerData): ClusterWorker | ThreadWorker;
|
|
48
53
|
spawn(workerId: number, shardId: number): void;
|
|
49
54
|
handleWorkerMessage(message: WorkerMessage): Promise<void>;
|
|
50
55
|
private generateNonce;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.WorkerManager = void 0;
|
|
7
|
+
const node_cluster_1 = __importDefault(require("node:cluster"));
|
|
4
8
|
const node_crypto_1 = require("node:crypto");
|
|
5
9
|
const node_worker_threads_1 = require("node:worker_threads");
|
|
6
10
|
const __1 = require("../..");
|
|
@@ -23,7 +27,7 @@ class WorkerManager extends Map {
|
|
|
23
27
|
rest;
|
|
24
28
|
constructor(options) {
|
|
25
29
|
super();
|
|
26
|
-
this.options =
|
|
30
|
+
this.options = options;
|
|
27
31
|
this.cacheAdapter = new cache_1.MemoryAdapter();
|
|
28
32
|
}
|
|
29
33
|
setCache(adapter) {
|
|
@@ -42,7 +46,13 @@ class WorkerManager extends Map {
|
|
|
42
46
|
return this.options.workers;
|
|
43
47
|
}
|
|
44
48
|
get totalShards() {
|
|
45
|
-
return this.options.totalShards;
|
|
49
|
+
return this.options.totalShards ?? this.options.info.shards;
|
|
50
|
+
}
|
|
51
|
+
get shardStart() {
|
|
52
|
+
return this.options.shardStart ?? 0;
|
|
53
|
+
}
|
|
54
|
+
get shardEnd() {
|
|
55
|
+
return this.options.shardEnd ?? this.totalShards;
|
|
46
56
|
}
|
|
47
57
|
get shardsPerWorker() {
|
|
48
58
|
return this.options.shardsPerWorker;
|
|
@@ -62,10 +72,10 @@ class WorkerManager extends Map {
|
|
|
62
72
|
return data.shards.reduce((acc, prv) => acc + prv.latency, 0) / data.shards.length;
|
|
63
73
|
}
|
|
64
74
|
calculateShardId(guildId) {
|
|
65
|
-
return Number((BigInt(guildId) >> 22n) % BigInt(this.
|
|
75
|
+
return Number((BigInt(guildId) >> 22n) % BigInt(this.totalShards));
|
|
66
76
|
}
|
|
67
77
|
calculateWorkerId(shardId) {
|
|
68
|
-
const workerId = Math.floor(shardId / this.shardsPerWorker);
|
|
78
|
+
const workerId = Math.floor((shardId - this.shardStart) / this.shardsPerWorker);
|
|
69
79
|
if (workerId >= this.workers) {
|
|
70
80
|
throw new Error('Invalid shardId');
|
|
71
81
|
}
|
|
@@ -73,18 +83,29 @@ class WorkerManager extends Map {
|
|
|
73
83
|
}
|
|
74
84
|
prepareSpaces() {
|
|
75
85
|
this.debugger?.info('Preparing buckets');
|
|
76
|
-
const chunks = structures_1.SequentialBucket.chunk(new Array(this.
|
|
77
|
-
? this.options.shardEnd - this.options.shardStart
|
|
78
|
-
: this.options.totalShards), this.options.shardsPerWorker);
|
|
86
|
+
const chunks = structures_1.SequentialBucket.chunk(new Array(this.shardEnd - this.shardStart), this.options.shardsPerWorker);
|
|
79
87
|
chunks.forEach((shards, index) => {
|
|
80
88
|
for (let i = 0; i < shards.length; i++) {
|
|
81
|
-
const id = i + (index > 0 ? index * this.options.shardsPerWorker : 0) +
|
|
89
|
+
const id = i + (index > 0 ? index * this.options.shardsPerWorker : 0) + this.shardStart;
|
|
82
90
|
chunks[index][i] = id;
|
|
83
91
|
}
|
|
84
92
|
});
|
|
85
93
|
this.debugger?.info(`${chunks.length} buckets created`);
|
|
86
94
|
return chunks;
|
|
87
95
|
}
|
|
96
|
+
postMessage(id, body) {
|
|
97
|
+
const worker = this.get(id);
|
|
98
|
+
if (!worker)
|
|
99
|
+
return this.debugger?.error(`Worker ${id} doesnt exists.`);
|
|
100
|
+
switch (this.options.mode) {
|
|
101
|
+
case 'clusters':
|
|
102
|
+
worker.send(body);
|
|
103
|
+
break;
|
|
104
|
+
case 'threads':
|
|
105
|
+
worker.postMessage(body);
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
88
109
|
async prepareWorkers(shards) {
|
|
89
110
|
for (let i = 0; i < shards.length; i++) {
|
|
90
111
|
let worker = this.get(i);
|
|
@@ -100,18 +121,47 @@ class WorkerManager extends Map {
|
|
|
100
121
|
});
|
|
101
122
|
this.set(i, worker);
|
|
102
123
|
}
|
|
103
|
-
|
|
104
|
-
type
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
124
|
+
const listener = (message) => {
|
|
125
|
+
if (message.type !== 'WORKER_START')
|
|
126
|
+
return;
|
|
127
|
+
worker.removeListener('message', listener);
|
|
128
|
+
this.postMessage(i, {
|
|
129
|
+
type: 'SPAWN_SHARDS',
|
|
130
|
+
compress: this.options.compress ?? false,
|
|
131
|
+
info: {
|
|
132
|
+
...this.options.info,
|
|
133
|
+
shards: this.totalShards,
|
|
134
|
+
},
|
|
135
|
+
properties: this.options.properties,
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
worker.on('message', listener);
|
|
109
139
|
}
|
|
110
140
|
}
|
|
111
141
|
createWorker(workerData) {
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
142
|
+
const env = {
|
|
143
|
+
SEYFERT_SPAWNING: 'true',
|
|
144
|
+
};
|
|
145
|
+
for (const i in workerData) {
|
|
146
|
+
env[`SEYFERT_WORKER_${i.toUpperCase()}`] = workerData[i];
|
|
147
|
+
}
|
|
148
|
+
switch (this.options.mode) {
|
|
149
|
+
case 'threads': {
|
|
150
|
+
const worker = new node_worker_threads_1.Worker(workerData.path, {
|
|
151
|
+
env,
|
|
152
|
+
});
|
|
153
|
+
worker.on('message', data => this.handleWorkerMessage(data));
|
|
154
|
+
return worker;
|
|
155
|
+
}
|
|
156
|
+
case 'clusters': {
|
|
157
|
+
node_cluster_1.default.setupPrimary({
|
|
158
|
+
exec: workerData.path,
|
|
159
|
+
});
|
|
160
|
+
const worker = node_cluster_1.default.fork(env);
|
|
161
|
+
worker.on('message', data => this.handleWorkerMessage(data));
|
|
162
|
+
return worker;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
115
165
|
}
|
|
116
166
|
spawn(workerId, shardId) {
|
|
117
167
|
this.connectQueue.push(() => {
|
|
@@ -120,7 +170,7 @@ class WorkerManager extends Map {
|
|
|
120
170
|
this.debugger?.fatal("Trying spawn with worker doesn't exist");
|
|
121
171
|
return;
|
|
122
172
|
}
|
|
123
|
-
|
|
173
|
+
this.postMessage(workerId, {
|
|
124
174
|
type: 'ALLOW_CONNECT',
|
|
125
175
|
shardId,
|
|
126
176
|
presence: this.options.presence?.(shardId, workerId),
|
|
@@ -140,7 +190,7 @@ class WorkerManager extends Map {
|
|
|
140
190
|
}
|
|
141
191
|
// @ts-expect-error
|
|
142
192
|
const result = await this.cacheAdapter[message.method](...message.args);
|
|
143
|
-
|
|
193
|
+
this.postMessage(message.workerId, {
|
|
144
194
|
type: 'CACHE_RESULT',
|
|
145
195
|
nonce: message.nonce,
|
|
146
196
|
result,
|
|
@@ -203,7 +253,7 @@ class WorkerManager extends Map {
|
|
|
203
253
|
{
|
|
204
254
|
this.get(message.workerId).ready = true;
|
|
205
255
|
if ([...this.values()].every(w => w.ready)) {
|
|
206
|
-
this.
|
|
256
|
+
this.postMessage(this.keys().next().value, {
|
|
207
257
|
type: 'BOT_READY',
|
|
208
258
|
});
|
|
209
259
|
this.forEach(w => {
|
|
@@ -215,7 +265,7 @@ class WorkerManager extends Map {
|
|
|
215
265
|
case 'WORKER_API_REQUEST':
|
|
216
266
|
{
|
|
217
267
|
const response = await this.rest.request(message.method, message.url, message.requestOptions);
|
|
218
|
-
this.
|
|
268
|
+
this.postMessage(message.workerId, {
|
|
219
269
|
nonce: message.nonce,
|
|
220
270
|
response,
|
|
221
271
|
type: 'API_RESPONSE',
|
|
@@ -237,13 +287,13 @@ class WorkerManager extends Map {
|
|
|
237
287
|
case 'EVAL':
|
|
238
288
|
{
|
|
239
289
|
const nonce = this.generateNonce();
|
|
240
|
-
this.
|
|
290
|
+
this.postMessage(message.toWorkerId, {
|
|
241
291
|
nonce,
|
|
242
292
|
func: message.func,
|
|
243
293
|
type: 'EXECUTE_EVAL',
|
|
244
294
|
toWorkerId: message.toWorkerId,
|
|
245
295
|
});
|
|
246
|
-
this.generateSendPromise(nonce, 'Eval timeout').then(val => this.
|
|
296
|
+
this.generateSendPromise(nonce, 'Eval timeout').then(val => this.postMessage(message.workerId, {
|
|
247
297
|
nonce: message.nonce,
|
|
248
298
|
response: val,
|
|
249
299
|
type: 'EVAL_RESPONSE',
|
|
@@ -281,7 +331,7 @@ class WorkerManager extends Map {
|
|
|
281
331
|
throw new Error(`Worker #${workerId} doesnt exist`);
|
|
282
332
|
}
|
|
283
333
|
const nonce = this.generateNonce();
|
|
284
|
-
|
|
334
|
+
this.postMessage(workerId, {
|
|
285
335
|
type: 'SEND_PAYLOAD',
|
|
286
336
|
shardId,
|
|
287
337
|
nonce,
|
|
@@ -296,7 +346,7 @@ class WorkerManager extends Map {
|
|
|
296
346
|
throw new Error(`Worker #${workerId} doesnt exist`);
|
|
297
347
|
}
|
|
298
348
|
const nonce = this.generateNonce(false);
|
|
299
|
-
|
|
349
|
+
this.postMessage(workerId, { shardId, nonce, type: 'SHARD_INFO' });
|
|
300
350
|
return this.generateSendPromise(nonce, 'Get shard info timeout');
|
|
301
351
|
}
|
|
302
352
|
async getWorkerInfo(workerId) {
|
|
@@ -305,7 +355,7 @@ class WorkerManager extends Map {
|
|
|
305
355
|
throw new Error(`Worker #${workerId} doesnt exist`);
|
|
306
356
|
}
|
|
307
357
|
const nonce = this.generateNonce();
|
|
308
|
-
|
|
358
|
+
this.postMessage(workerId, { nonce, type: 'WORKER_INFO' });
|
|
309
359
|
return this.generateSendPromise(nonce, 'Get worker info timeout');
|
|
310
360
|
}
|
|
311
361
|
async start() {
|
|
@@ -320,12 +370,10 @@ class WorkerManager extends Map {
|
|
|
320
370
|
debug: this.options.debug,
|
|
321
371
|
});
|
|
322
372
|
this.options.info ??= await new __1.Router(this.rest).createProxy().gateway.bot.get();
|
|
323
|
-
this.options.
|
|
373
|
+
this.options.shardEnd ??= this.options.totalShards ?? this.options.info.shards;
|
|
374
|
+
this.options.totalShards ??= this.options.shardEnd;
|
|
324
375
|
this.options = (0, common_1.MergeOptions)(constants_1.WorkerManagerDefaults, this.options);
|
|
325
376
|
this.options.workers ??= Math.ceil(this.options.totalShards / this.options.shardsPerWorker);
|
|
326
|
-
this.options.info.shards = this.options.totalShards;
|
|
327
|
-
this.options.shardEnd ??= this.options.totalShards;
|
|
328
|
-
this.options.shardStart ??= 0;
|
|
329
377
|
this.connectQueue = new timeout_1.ConnectQueue(5.5e3, this.concurrency);
|
|
330
378
|
if (this.options.debug) {
|
|
331
379
|
this.debugger = new common_1.Logger({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "seyfert",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "The most advanced framework for discord bots",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"module": "./lib/index.js",
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
"check": "biome check --apply --changed --no-errors-on-unmatched ./src"
|
|
19
19
|
},
|
|
20
20
|
"author": "MARCROCK22",
|
|
21
|
-
"license": "
|
|
21
|
+
"license": "Apache-2.0",
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"chokidar": "^3.6.0",
|
|
24
|
-
"discord-api-types": "^0.37.
|
|
24
|
+
"discord-api-types": "^0.37.76",
|
|
25
25
|
"magic-bytes.js": "^1.10.0",
|
|
26
26
|
"ts-mixer": "^6.0.4",
|
|
27
27
|
"ws": "^8.16.0"
|
|
@@ -34,11 +34,13 @@
|
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@biomejs/biome": "1.6.0",
|
|
37
|
-
"@
|
|
37
|
+
"@commitlint/cli": "^19.2.1",
|
|
38
|
+
"@commitlint/config-conventional": "^19.1.0",
|
|
39
|
+
"@types/node": "^20.11.30",
|
|
38
40
|
"@types/ws": "^8.5.10",
|
|
39
41
|
"husky": "^9.0.11",
|
|
40
42
|
"lint-staged": "^15.2.2",
|
|
41
|
-
"typescript": "^5.4.
|
|
43
|
+
"typescript": "^5.4.3"
|
|
42
44
|
},
|
|
43
45
|
"optionalDependencies": {
|
|
44
46
|
"ioredis": "^5.3.2",
|
|
@@ -69,4 +71,4 @@
|
|
|
69
71
|
"url": "https://github.com/socram03"
|
|
70
72
|
}
|
|
71
73
|
]
|
|
72
|
-
}
|
|
74
|
+
}
|