seyfert 1.0.1 → 1.1.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/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/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 +2 -1
- package/lib/cache/resources/default/guild-based.d.ts +2 -1
- package/lib/cache/resources/default/guild-based.js +6 -6
- package/lib/cache/resources/default/guild-related.d.ts +2 -1
- package/lib/cache/resources/default/guild-related.js +1 -1
- 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 +18 -170
- package/lib/client/base.js +11 -14
- package/lib/client/client.d.ts +5 -0
- package/lib/client/client.js +4 -1
- package/lib/client/oninteractioncreate.js +2 -2
- package/lib/client/onmessagecreate.js +188 -152
- package/lib/client/workerclient.d.ts +1 -0
- package/lib/client/workerclient.js +36 -15
- package/lib/collection.js +2 -2
- package/lib/commands/applications/chat.d.ts +15 -7
- package/lib/commands/applications/chat.js +7 -7
- package/lib/commands/applications/chatcontext.d.ts +5 -3
- package/lib/commands/applications/chatcontext.js +6 -1
- package/lib/commands/applications/menu.d.ts +5 -1
- package/lib/commands/applications/menu.js +4 -0
- package/lib/commands/applications/menucontext.d.ts +4 -2
- package/lib/commands/applications/menucontext.js +6 -1
- package/lib/commands/applications/options.d.ts +1 -2
- package/lib/commands/decorators.d.ts +17 -5
- package/lib/commands/decorators.js +17 -7
- package/lib/commands/handler.d.ts +5 -5
- package/lib/commands/handler.js +40 -36
- 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.js +2 -0
- 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 -0
- package/lib/common/shorters/users.js +30 -0
- 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/components/handler.d.ts +10 -7
- package/lib/components/handler.js +20 -5
- package/lib/index.d.ts +4 -2
- package/lib/langs/handler.js +7 -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 +6 -6
- package/lib/structures/GuildMember.js +2 -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 +7 -8
- package/lib/structures/Interaction.js +1 -1
- package/lib/structures/Message.d.ts +7 -6
- package/lib/structures/Message.js +7 -4
- package/lib/structures/Sticker.d.ts +2 -2
- package/lib/structures/Webhook.d.ts +2 -2
- package/lib/structures/Webhook.js +3 -3
- package/lib/structures/channels.d.ts +19 -20
- 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
|
@@ -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.0
|
|
3
|
+
"version": "1.1.0",
|
|
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
|
+
}
|