seyfert 2.0.0 → 2.1.1-dev-11310514874.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/Router.d.ts +2 -2
- package/lib/api/Router.js +2 -1
- package/lib/api/Routes/applications.d.ts +29 -30
- package/lib/api/Routes/cdn.d.ts +6 -1
- package/lib/api/Routes/channels.d.ts +44 -45
- package/lib/api/Routes/gateway.d.ts +3 -4
- package/lib/api/Routes/guilds.d.ts +81 -80
- package/lib/api/Routes/index.d.ts +3 -1
- package/lib/api/Routes/interactions.d.ts +9 -3
- package/lib/api/Routes/invites.d.ts +3 -4
- package/lib/api/Routes/skus.d.ts +10 -0
- package/lib/api/Routes/skus.js +2 -0
- package/lib/api/Routes/soundboard.d.ts +23 -0
- package/lib/api/Routes/soundboard.js +2 -0
- package/lib/api/Routes/stage-instances.d.ts +5 -6
- package/lib/api/Routes/stickers.d.ts +3 -4
- package/lib/api/Routes/users.d.ts +11 -12
- package/lib/api/Routes/voice.d.ts +2 -3
- package/lib/api/Routes/webhooks.d.ts +16 -15
- package/lib/api/api.d.ts +17 -11
- package/lib/api/api.js +26 -22
- package/lib/api/shared.d.ts +2 -2
- package/lib/api/utils/constants.d.ts +3 -1
- package/lib/api/utils/constants.js +3 -2
- package/lib/builders/ActionRow.d.ts +1 -1
- package/lib/builders/Attachment.d.ts +3 -3
- package/lib/builders/Attachment.js +13 -13
- package/lib/builders/Button.d.ts +1 -1
- package/lib/builders/Button.js +1 -1
- package/lib/builders/Embed.d.ts +1 -1
- package/lib/builders/Embed.js +2 -2
- package/lib/builders/Modal.d.ts +1 -1
- package/lib/builders/Poll.d.ts +1 -1
- package/lib/builders/Poll.js +1 -1
- package/lib/builders/SelectMenu.d.ts +1 -1
- package/lib/builders/SelectMenu.js +1 -1
- package/lib/builders/types.d.ts +2 -1
- package/lib/cache/adapters/default.js +5 -3
- package/lib/cache/adapters/limited.d.ts +1 -2
- package/lib/cache/adapters/limited.js +34 -30
- package/lib/cache/adapters/workeradapter.js +3 -1
- package/lib/cache/index.d.ts +12 -12
- package/lib/cache/index.js +48 -39
- package/lib/cache/resources/bans.d.ts +2 -2
- package/lib/cache/resources/bans.js +1 -1
- package/lib/cache/resources/channels.d.ts +1 -1
- package/lib/cache/resources/default/guild-related.d.ts +1 -2
- package/lib/cache/resources/emojis.d.ts +2 -2
- package/lib/cache/resources/emojis.js +1 -1
- package/lib/cache/resources/guilds.d.ts +2 -2
- package/lib/cache/resources/guilds.js +7 -11
- package/lib/cache/resources/members.d.ts +2 -2
- package/lib/cache/resources/members.js +1 -1
- package/lib/cache/resources/messages.d.ts +2 -2
- package/lib/cache/resources/messages.js +3 -3
- package/lib/cache/resources/overwrites.d.ts +1 -1
- package/lib/cache/resources/roles.d.ts +2 -2
- package/lib/cache/resources/roles.js +1 -1
- package/lib/cache/resources/stickers.d.ts +2 -2
- package/lib/cache/resources/stickers.js +1 -1
- package/lib/cache/resources/users.d.ts +2 -2
- package/lib/cache/resources/users.js +1 -1
- package/lib/cache/resources/voice-states.d.ts +2 -2
- package/lib/cache/resources/voice-states.js +1 -1
- package/lib/client/base.d.ts +10 -15
- package/lib/client/base.js +48 -44
- package/lib/client/client.d.ts +4 -4
- package/lib/client/client.js +37 -38
- package/lib/client/collectors.js +1 -1
- package/lib/client/httpclient.d.ts +1 -1
- package/lib/client/httpclient.js +2 -2
- package/lib/client/transformers.d.ts +37 -34
- package/lib/client/transformers.js +66 -63
- package/lib/client/workerclient.d.ts +13 -13
- package/lib/client/workerclient.js +182 -65
- package/lib/collection.d.ts +3 -3
- package/lib/commands/applications/chat.d.ts +3 -3
- package/lib/commands/applications/chat.js +5 -6
- package/lib/commands/applications/chatcontext.d.ts +6 -6
- package/lib/commands/applications/chatcontext.js +16 -8
- package/lib/commands/applications/entryPoint.d.ts +46 -0
- package/lib/commands/applications/entryPoint.js +56 -0
- package/lib/commands/applications/entrycontext.d.ts +40 -0
- package/lib/commands/applications/entrycontext.js +85 -0
- package/lib/commands/applications/menu.d.ts +1 -1
- package/lib/commands/applications/menucontext.d.ts +5 -5
- package/lib/commands/applications/menucontext.js +6 -6
- package/lib/commands/applications/options.d.ts +7 -6
- package/lib/commands/applications/shared.d.ts +5 -2
- package/lib/commands/basecontext.d.ts +1 -1
- package/lib/commands/decorators.d.ts +20 -26
- package/lib/commands/decorators.js +8 -4
- package/lib/commands/handle.d.ts +13 -12
- package/lib/commands/handle.js +133 -65
- package/lib/commands/handler.d.ts +9 -7
- package/lib/commands/handler.js +27 -18
- package/lib/commands/index.d.ts +2 -0
- package/lib/commands/index.js +2 -0
- package/lib/commands/optionresolver.d.ts +4 -4
- package/lib/commands/optionresolver.js +4 -4
- package/lib/common/bot/watcher.d.ts +1 -1
- package/lib/common/it/formatter.d.ts +21 -21
- package/lib/common/it/formatter.js +40 -41
- package/lib/common/it/logger.js +1 -1
- package/lib/common/it/utils.d.ts +14 -6
- package/lib/common/it/utils.js +62 -27
- package/lib/common/shorters/application.d.ts +2 -3
- package/lib/common/shorters/application.js +3 -3
- package/lib/common/shorters/bans.js +1 -1
- package/lib/common/shorters/channels.d.ts +3 -3
- package/lib/common/shorters/channels.js +3 -3
- package/lib/common/shorters/emojis.js +4 -4
- package/lib/common/shorters/guilds.d.ts +3 -3
- package/lib/common/shorters/guilds.js +5 -9
- package/lib/common/shorters/interaction.d.ts +3 -3
- package/lib/common/shorters/interaction.js +6 -5
- package/lib/common/shorters/members.d.ts +4 -5
- package/lib/common/shorters/members.js +6 -7
- package/lib/common/shorters/messages.d.ts +1 -1
- package/lib/common/shorters/messages.js +4 -4
- package/lib/common/shorters/reactions.d.ts +1 -1
- package/lib/common/shorters/reactions.js +1 -1
- package/lib/common/shorters/roles.js +1 -1
- package/lib/common/shorters/templates.js +2 -2
- package/lib/common/shorters/threads.d.ts +1 -1
- package/lib/common/shorters/threads.js +17 -11
- package/lib/common/shorters/webhook.d.ts +1 -1
- package/lib/common/shorters/webhook.js +4 -4
- package/lib/common/types/options.d.ts +2 -2
- package/lib/common/types/resolvables.d.ts +1 -1
- package/lib/common/types/util.d.ts +4 -1
- package/lib/common/types/write.d.ts +3 -3
- package/lib/components/BaseComponent.js +1 -1
- package/lib/components/ButtonComponent.d.ts +1 -1
- package/lib/components/componentcommand.d.ts +1 -1
- package/lib/components/componentcontext.d.ts +4 -4
- package/lib/components/componentcontext.js +1 -1
- package/lib/components/handler.d.ts +10 -8
- package/lib/components/handler.js +16 -13
- package/lib/components/index.js +2 -1
- package/lib/components/modalcontext.d.ts +2 -2
- package/lib/components/modalcontext.js +1 -1
- package/lib/deps/mixer.d.ts +1 -1
- package/lib/deps/mixer.js +6 -1
- package/lib/events/handler.d.ts +5 -5
- package/lib/events/handler.js +69 -19
- package/lib/events/hooks/application_command.d.ts +1 -1
- package/lib/events/hooks/auto_moderation.d.ts +1 -1
- package/lib/events/hooks/auto_moderation.js +1 -1
- package/lib/events/hooks/channel.d.ts +1 -1
- package/lib/events/hooks/custom.d.ts +1 -0
- package/lib/events/hooks/custom.js +5 -1
- package/lib/events/hooks/dispatch.d.ts +1 -1
- package/lib/events/hooks/entitlement.d.ts +4 -5
- package/lib/events/hooks/entitlement.js +4 -4
- package/lib/events/hooks/guild.d.ts +3 -3
- package/lib/events/hooks/guild.js +1 -1
- package/lib/events/hooks/index.d.ts +1 -0
- package/lib/events/hooks/index.js +1 -0
- package/lib/events/hooks/integration.d.ts +1 -1
- package/lib/events/hooks/integration.js +1 -1
- package/lib/events/hooks/interactions.d.ts +3 -3
- package/lib/events/hooks/invite.d.ts +1 -1
- package/lib/events/hooks/message.d.ts +3 -3
- package/lib/events/hooks/message.js +1 -1
- package/lib/events/hooks/presence.d.ts +2 -2
- package/lib/events/hooks/soundboard.d.ts +155 -0
- package/lib/events/hooks/soundboard.js +28 -0
- package/lib/events/hooks/stage.d.ts +2 -2
- package/lib/events/hooks/subscriptions.d.ts +35 -0
- package/lib/events/hooks/subscriptions.js +16 -0
- package/lib/events/hooks/thread.d.ts +2 -2
- package/lib/events/hooks/thread.js +2 -2
- package/lib/events/hooks/typing.d.ts +1 -1
- package/lib/events/hooks/typing.js +1 -1
- package/lib/events/hooks/user.d.ts +2 -2
- package/lib/events/hooks/voice.d.ts +2 -2
- package/lib/events/hooks/voice.js +1 -1
- package/lib/events/hooks/webhook.d.ts +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +3 -5
- package/lib/langs/handler.d.ts +2 -2
- package/lib/structures/Guild.d.ts +7 -4
- package/lib/structures/Guild.js +1 -1
- package/lib/structures/GuildBan.d.ts +1 -1
- package/lib/structures/GuildMember.d.ts +7 -5
- package/lib/structures/GuildMember.js +5 -3
- package/lib/structures/GuildRole.d.ts +1 -1
- package/lib/structures/GuildTemplate.d.ts +1 -1
- package/lib/structures/Interaction.d.ts +39 -16
- package/lib/structures/Interaction.js +82 -26
- package/lib/structures/Message.d.ts +4 -10
- package/lib/structures/Message.js +5 -8
- package/lib/structures/Poll.d.ts +3 -3
- package/lib/structures/Sticker.d.ts +2 -2
- package/lib/structures/Sticker.js +1 -1
- package/lib/structures/VoiceState.d.ts +2 -1
- package/lib/structures/VoiceState.js +1 -1
- package/lib/structures/Webhook.d.ts +3 -3
- package/lib/structures/Webhook.js +1 -1
- package/lib/structures/channels.d.ts +4 -4
- package/lib/structures/channels.js +8 -7
- package/lib/structures/extra/BaseGuild.d.ts +11 -1
- package/lib/structures/extra/BaseGuild.js +27 -0
- package/lib/structures/extra/BitField.d.ts +3 -3
- package/lib/structures/extra/BitField.js +34 -33
- package/lib/structures/extra/DiscordBase.js +1 -1
- package/lib/structures/extra/Permissions.d.ts +2 -0
- package/lib/structures/extra/Permissions.js +21 -0
- package/lib/types/gateway.d.ts +71 -6
- package/lib/types/payloads/_interactions/_applicationCommands/chatInput.d.ts +6 -1
- package/lib/types/payloads/_interactions/applicationCommands.d.ts +41 -6
- package/lib/types/payloads/_interactions/applicationCommands.js +28 -1
- package/lib/types/payloads/_interactions/base.d.ts +1 -1
- package/lib/types/payloads/_interactions/responses.d.ts +74 -2
- package/lib/types/payloads/_interactions/responses.js +4 -0
- package/lib/types/payloads/channel.d.ts +46 -6
- package/lib/types/payloads/channel.js +5 -1
- package/lib/types/payloads/guild.d.ts +9 -1
- package/lib/types/payloads/guild.js +8 -0
- package/lib/types/payloads/index.d.ts +1 -0
- package/lib/types/payloads/index.js +1 -0
- package/lib/types/payloads/monetization.d.ts +29 -1
- package/lib/types/payloads/monetization.js +10 -1
- package/lib/types/payloads/soundboard.d.ts +23 -0
- package/lib/types/payloads/soundboard.js +5 -0
- package/lib/types/payloads/user.js +0 -1
- package/lib/types/rest/application.d.ts +3 -3
- package/lib/types/rest/auditLog.d.ts +1 -1
- package/lib/types/rest/channel.d.ts +5 -18
- package/lib/types/rest/guild.d.ts +2 -2
- package/lib/types/rest/guildScheduledEvent.d.ts +1 -1
- package/lib/types/rest/index.d.ts +1 -0
- package/lib/types/rest/index.js +1 -0
- package/lib/types/rest/interactions.d.ts +30 -8
- package/lib/types/rest/monetization.d.ts +22 -1
- package/lib/types/rest/oauth2.d.ts +1 -1
- package/lib/types/rest/poll.d.ts +1 -1
- package/lib/types/rest/soundboard.d.ts +64 -0
- package/lib/types/rest/soundboard.js +2 -0
- package/lib/types/rest/stageInstance.d.ts +1 -1
- package/lib/types/rest/template.d.ts +1 -1
- package/lib/types/rest/user.d.ts +1 -1
- package/lib/types/rest/webhook.d.ts +3 -3
- package/lib/types/utils/index.d.ts +27 -7
- package/lib/types/utils/index.js +25 -6
- package/lib/websocket/SharedTypes.d.ts +18 -3
- package/lib/websocket/constants/index.d.ts +3 -2
- package/lib/websocket/constants/index.js +4 -4
- package/lib/websocket/discord/basesocket.d.ts +1 -1
- package/lib/websocket/discord/shard.d.ts +4 -3
- package/lib/websocket/discord/shard.js +47 -24
- package/lib/websocket/discord/sharder.d.ts +9 -6
- package/lib/websocket/discord/sharder.js +92 -17
- package/lib/websocket/discord/shared.d.ts +12 -3
- package/lib/websocket/discord/socket/custom.d.ts +1 -1
- package/lib/websocket/discord/socket/custom.js +70 -40
- package/lib/websocket/discord/worker.d.ts +9 -2
- package/lib/websocket/discord/workermanager.d.ts +42 -16
- package/lib/websocket/discord/workermanager.js +170 -46
- package/lib/websocket/structures/timeout.d.ts +4 -5
- package/lib/websocket/structures/timeout.js +23 -24
- package/package.json +72 -65
- package/lib/cache/resources/threads.d.ts +0 -14
- package/lib/cache/resources/threads.js +0 -32
|
@@ -14,12 +14,27 @@ const constants_1 = require("../constants");
|
|
|
14
14
|
const structures_1 = require("../structures");
|
|
15
15
|
const timeout_1 = require("../structures/timeout");
|
|
16
16
|
class WorkerManager extends Map {
|
|
17
|
+
static prepareSpaces(options, logger) {
|
|
18
|
+
logger?.info('Preparing buckets', options);
|
|
19
|
+
const chunks = structures_1.DynamicBucket.chunk(new Array(options.shardEnd - options.shardStart), options.shardsPerWorker);
|
|
20
|
+
chunks.forEach((shards, index) => {
|
|
21
|
+
for (let i = 0; i < shards.length; i++) {
|
|
22
|
+
const id = i + (index > 0 ? index * options.shardsPerWorker : 0) + options.shardStart;
|
|
23
|
+
chunks[index][i] = id;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
logger?.info(`${chunks.length} buckets created`);
|
|
27
|
+
return chunks;
|
|
28
|
+
}
|
|
17
29
|
options;
|
|
18
30
|
debugger;
|
|
19
31
|
connectQueue;
|
|
32
|
+
workerQueue = [];
|
|
20
33
|
cacheAdapter;
|
|
21
34
|
promises = new Map();
|
|
22
35
|
rest;
|
|
36
|
+
reshardingWorkerQueue = [];
|
|
37
|
+
_info;
|
|
23
38
|
constructor(options) {
|
|
24
39
|
super();
|
|
25
40
|
this.options = options;
|
|
@@ -52,12 +67,9 @@ class WorkerManager extends Map {
|
|
|
52
67
|
get shardsPerWorker() {
|
|
53
68
|
return this.options.shardsPerWorker;
|
|
54
69
|
}
|
|
55
|
-
|
|
56
|
-
return this.options.workers;
|
|
57
|
-
}
|
|
58
|
-
async syncLatency({ shardId, workerId }) {
|
|
70
|
+
async syncLatency({ shardId, workerId, }) {
|
|
59
71
|
if (typeof shardId !== 'number' && typeof workerId !== 'number') {
|
|
60
|
-
|
|
72
|
+
throw new Error('Undefined workerId and shardId');
|
|
61
73
|
}
|
|
62
74
|
const id = workerId ?? this.calculateWorkerId(shardId);
|
|
63
75
|
if (!this.has(id)) {
|
|
@@ -71,27 +83,15 @@ class WorkerManager extends Map {
|
|
|
71
83
|
}
|
|
72
84
|
calculateWorkerId(shardId) {
|
|
73
85
|
const workerId = Math.floor((shardId - this.shardStart) / this.shardsPerWorker);
|
|
74
|
-
if (workerId >= this.
|
|
86
|
+
if (workerId >= this.totalWorkers) {
|
|
75
87
|
throw new Error('Invalid shardId');
|
|
76
88
|
}
|
|
77
89
|
return workerId;
|
|
78
90
|
}
|
|
79
|
-
prepareSpaces() {
|
|
80
|
-
this.debugger?.info('Preparing buckets');
|
|
81
|
-
const chunks = structures_1.DynamicBucket.chunk(new Array(this.shardEnd - this.shardStart), this.options.shardsPerWorker);
|
|
82
|
-
chunks.forEach((shards, index) => {
|
|
83
|
-
for (let i = 0; i < shards.length; i++) {
|
|
84
|
-
const id = i + (index > 0 ? index * this.options.shardsPerWorker : 0) + this.shardStart;
|
|
85
|
-
chunks[index][i] = id;
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
this.debugger?.info(`${chunks.length} buckets created`);
|
|
89
|
-
return chunks;
|
|
90
|
-
}
|
|
91
91
|
postMessage(id, body) {
|
|
92
92
|
const worker = this.get(id);
|
|
93
93
|
if (!worker)
|
|
94
|
-
return this.debugger?.error(`Worker ${id}
|
|
94
|
+
return this.debugger?.error(`Worker ${id} does not exists.`);
|
|
95
95
|
switch (this.options.mode) {
|
|
96
96
|
case 'clusters':
|
|
97
97
|
worker.send(body);
|
|
@@ -104,35 +104,49 @@ class WorkerManager extends Map {
|
|
|
104
104
|
break;
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
|
-
async prepareWorkers(shards) {
|
|
107
|
+
async prepareWorkers(shards, resharding = false) {
|
|
108
108
|
const worker_threads = (0, common_1.lazyLoadPackage)('node:worker_threads');
|
|
109
109
|
if (!worker_threads)
|
|
110
110
|
throw new Error('Cannot prepare workers without worker_threads.');
|
|
111
111
|
for (let i = 0; i < shards.length; i++) {
|
|
112
|
-
|
|
113
|
-
if (!
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
112
|
+
const workerExists = this.has(i);
|
|
113
|
+
if (resharding || !workerExists) {
|
|
114
|
+
this[resharding ? 'reshardingWorkerQueue' : 'workerQueue'].push(() => {
|
|
115
|
+
const worker = this.createWorker({
|
|
116
|
+
path: this.options.path,
|
|
117
|
+
debug: this.options.debug,
|
|
118
|
+
token: this.options.token,
|
|
119
|
+
shards: shards[i],
|
|
120
|
+
intents: this.options.intents,
|
|
121
|
+
workerId: i,
|
|
122
|
+
workerProxy: this.options.workerProxy,
|
|
123
|
+
totalShards: resharding ? this._info.shards : this.totalShards,
|
|
124
|
+
mode: this.options.mode,
|
|
125
|
+
resharding,
|
|
126
|
+
});
|
|
127
|
+
this.set(i, worker);
|
|
124
128
|
});
|
|
125
|
-
this.set(i, worker);
|
|
126
129
|
}
|
|
127
130
|
}
|
|
128
131
|
}
|
|
129
132
|
createWorker(workerData) {
|
|
133
|
+
if (this.has(workerData.workerId)) {
|
|
134
|
+
if (workerData.resharding) {
|
|
135
|
+
this.postMessage(workerData.workerId, {
|
|
136
|
+
type: 'WORKER_ALREADY_EXISTS_RESHARDING',
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
const worker = this.get(workerData.workerId);
|
|
140
|
+
return worker;
|
|
141
|
+
}
|
|
130
142
|
const worker_threads = (0, common_1.lazyLoadPackage)('node:worker_threads');
|
|
131
143
|
if (!worker_threads)
|
|
132
144
|
throw new Error('Cannot create worker without worker_threads.');
|
|
133
145
|
const env = {
|
|
134
146
|
SEYFERT_SPAWNING: 'true',
|
|
135
147
|
};
|
|
148
|
+
if (workerData.resharding)
|
|
149
|
+
env.SEYFERT_WORKER_RESHARDING = 'true';
|
|
136
150
|
for (const i in workerData) {
|
|
137
151
|
env[`SEYFERT_WORKER_${i.toUpperCase()}`] = workerData[i];
|
|
138
152
|
}
|
|
@@ -152,22 +166,23 @@ class WorkerManager extends Map {
|
|
|
152
166
|
worker.on('message', data => this.handleWorkerMessage(data));
|
|
153
167
|
return worker;
|
|
154
168
|
}
|
|
155
|
-
case 'custom':
|
|
169
|
+
case 'custom': {
|
|
156
170
|
this.options.adapter.spawn(workerData, env);
|
|
157
171
|
return {
|
|
158
172
|
ready: false,
|
|
159
173
|
};
|
|
174
|
+
}
|
|
160
175
|
}
|
|
161
176
|
}
|
|
162
|
-
spawn(workerId, shardId) {
|
|
177
|
+
spawn(workerId, shardId, resharding = false) {
|
|
163
178
|
this.connectQueue.push(() => {
|
|
164
179
|
const worker = this.has(workerId);
|
|
165
180
|
if (!worker) {
|
|
166
|
-
this.debugger?.fatal(
|
|
181
|
+
this.debugger?.fatal(`Trying ${resharding ? 'reshard' : 'spawn'} with worker that doesn't exist`);
|
|
167
182
|
return;
|
|
168
183
|
}
|
|
169
184
|
this.postMessage(workerId, {
|
|
170
|
-
type: 'ALLOW_CONNECT',
|
|
185
|
+
type: resharding ? 'ALLOW_CONNECT_RESHARDING' : 'ALLOW_CONNECT',
|
|
171
186
|
shardId,
|
|
172
187
|
presence: this.options.presence?.(shardId, workerId),
|
|
173
188
|
});
|
|
@@ -175,6 +190,66 @@ class WorkerManager extends Map {
|
|
|
175
190
|
}
|
|
176
191
|
async handleWorkerMessage(message) {
|
|
177
192
|
switch (message.type) {
|
|
193
|
+
case 'WORKER_READY_RESHARDING':
|
|
194
|
+
{
|
|
195
|
+
this.get(message.workerId).resharded = true;
|
|
196
|
+
if (!this.reshardingWorkerQueue.length && [...this.values()].every(w => w.resharded)) {
|
|
197
|
+
for (const [id] of this.entries()) {
|
|
198
|
+
this.postMessage(id, {
|
|
199
|
+
type: 'DISCONNECT_ALL_SHARDS_RESHARDING',
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
this.forEach(w => {
|
|
203
|
+
delete w.resharded;
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
const nextWorker = this.reshardingWorkerQueue.shift();
|
|
208
|
+
if (nextWorker) {
|
|
209
|
+
this.debugger?.info('Spawning next worker to reshard');
|
|
210
|
+
nextWorker();
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
this.debugger?.info('No more workers to reshard left');
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
break;
|
|
218
|
+
case 'DISCONNECTED_ALL_SHARDS_RESHARDING':
|
|
219
|
+
{
|
|
220
|
+
this.get(message.workerId).disconnected = true;
|
|
221
|
+
if ([...this.values()].every(w => w.disconnected)) {
|
|
222
|
+
this.options.totalShards = this._info.shards;
|
|
223
|
+
this.options.shardEnd = this.options.totalShards = this._info.shards;
|
|
224
|
+
this.options.workers = this.size;
|
|
225
|
+
delete this._info;
|
|
226
|
+
for (const [id] of this.entries()) {
|
|
227
|
+
this.postMessage(id, {
|
|
228
|
+
type: 'CONNECT_ALL_SHARDS_RESHARDING',
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
this.forEach(w => {
|
|
232
|
+
delete w.disconnected;
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
break;
|
|
237
|
+
case 'WORKER_START_RESHARDING':
|
|
238
|
+
{
|
|
239
|
+
this.postMessage(message.workerId, {
|
|
240
|
+
type: 'SPAWN_SHARDS_RESHARDING',
|
|
241
|
+
compress: this.options.compress ?? false,
|
|
242
|
+
info: {
|
|
243
|
+
...this.options.info,
|
|
244
|
+
shards: this._info.shards,
|
|
245
|
+
},
|
|
246
|
+
properties: {
|
|
247
|
+
...constants_1.properties,
|
|
248
|
+
...this.options.properties,
|
|
249
|
+
},
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
break;
|
|
178
253
|
case 'WORKER_START':
|
|
179
254
|
{
|
|
180
255
|
this.postMessage(message.workerId, {
|
|
@@ -191,6 +266,9 @@ class WorkerManager extends Map {
|
|
|
191
266
|
});
|
|
192
267
|
}
|
|
193
268
|
break;
|
|
269
|
+
case 'CONNECT_QUEUE_RESHARDING':
|
|
270
|
+
this.spawn(message.workerId, message.shardId, true);
|
|
271
|
+
break;
|
|
194
272
|
case 'CONNECT_QUEUE':
|
|
195
273
|
this.spawn(message.workerId, message.shardId);
|
|
196
274
|
break;
|
|
@@ -260,6 +338,18 @@ class WorkerManager extends Map {
|
|
|
260
338
|
}
|
|
261
339
|
}
|
|
262
340
|
break;
|
|
341
|
+
case 'WORKER_SHARDS_CONNECTED':
|
|
342
|
+
{
|
|
343
|
+
const nextWorker = this.workerQueue.shift();
|
|
344
|
+
if (nextWorker) {
|
|
345
|
+
this.debugger?.info('Spawning next worker');
|
|
346
|
+
nextWorker();
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
this.debugger?.info('No more workers to spawn left');
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
break;
|
|
263
353
|
case 'WORKER_API_REQUEST':
|
|
264
354
|
{
|
|
265
355
|
const response = await this.rest.request(message.method, message.url, message.requestOptions);
|
|
@@ -300,12 +390,11 @@ class WorkerManager extends Map {
|
|
|
300
390
|
break;
|
|
301
391
|
}
|
|
302
392
|
}
|
|
303
|
-
generateNonce(
|
|
393
|
+
generateNonce() {
|
|
304
394
|
const uuid = (0, node_crypto_1.randomUUID)();
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
return nonce;
|
|
395
|
+
if (this.promises.has(uuid))
|
|
396
|
+
return this.generateNonce();
|
|
397
|
+
return uuid;
|
|
309
398
|
}
|
|
310
399
|
generateSendPromise(nonce, message = 'Timeout') {
|
|
311
400
|
return new Promise((res, rej) => {
|
|
@@ -337,7 +426,7 @@ class WorkerManager extends Map {
|
|
|
337
426
|
if (!worker) {
|
|
338
427
|
throw new Error(`Worker #${workerId} doesnt exist`);
|
|
339
428
|
}
|
|
340
|
-
const nonce = this.generateNonce(
|
|
429
|
+
const nonce = this.generateNonce();
|
|
341
430
|
this.postMessage(workerId, { shardId, nonce, type: 'SHARD_INFO' });
|
|
342
431
|
return this.generateSendPromise(nonce, 'Get shard info timeout');
|
|
343
432
|
}
|
|
@@ -361,10 +450,11 @@ class WorkerManager extends Map {
|
|
|
361
450
|
domain: 'https://discord.com',
|
|
362
451
|
debug: this.options.debug,
|
|
363
452
|
});
|
|
364
|
-
this.options.info ??= await
|
|
453
|
+
this.options.info ??= await this.rest.proxy.gateway.bot.get();
|
|
365
454
|
this.options.shardEnd ??= this.options.totalShards ?? this.options.info.shards;
|
|
366
455
|
this.options.totalShards ??= this.options.shardEnd;
|
|
367
456
|
this.options = (0, common_1.MergeOptions)(constants_1.WorkerManagerDefaults, this.options);
|
|
457
|
+
this.options.resharding.getInfo ??= () => this.rest.proxy.gateway.bot.get();
|
|
368
458
|
this.options.workers ??= Math.ceil(this.options.totalShards / this.options.shardsPerWorker);
|
|
369
459
|
this.connectQueue = new timeout_1.ConnectQueue(5.5e3, this.concurrency);
|
|
370
460
|
if (this.options.debug) {
|
|
@@ -372,11 +462,45 @@ class WorkerManager extends Map {
|
|
|
372
462
|
name: '[WorkerManager]',
|
|
373
463
|
});
|
|
374
464
|
}
|
|
375
|
-
if (this.totalShards / this.shardsPerWorker > this.
|
|
465
|
+
if (this.totalShards / this.shardsPerWorker > this.totalWorkers) {
|
|
376
466
|
throw new Error(`Cannot create enough shards in the specified workers, minimum: ${Math.ceil(this.totalShards / this.shardsPerWorker)}`);
|
|
377
467
|
}
|
|
378
|
-
const spaces =
|
|
468
|
+
const spaces = WorkerManager.prepareSpaces({
|
|
469
|
+
shardStart: this.shardStart,
|
|
470
|
+
shardEnd: this.shardEnd,
|
|
471
|
+
shardsPerWorker: this.shardsPerWorker,
|
|
472
|
+
}, this.debugger);
|
|
379
473
|
await this.prepareWorkers(spaces);
|
|
474
|
+
// Start workers queue
|
|
475
|
+
this.workerQueue.shift()();
|
|
476
|
+
await this.startResharding();
|
|
477
|
+
}
|
|
478
|
+
async startResharding() {
|
|
479
|
+
if (this.options.resharding.interval <= 0)
|
|
480
|
+
return;
|
|
481
|
+
if (this.shardStart !== 0 || this.shardEnd !== this.totalShards)
|
|
482
|
+
return this.debugger?.debug('Cannot start resharder');
|
|
483
|
+
setInterval(async () => {
|
|
484
|
+
this.debugger?.debug('Checking if reshard is needed');
|
|
485
|
+
const info = await this.options.resharding.getInfo();
|
|
486
|
+
if (info.shards <= this.totalShards)
|
|
487
|
+
return this.debugger?.debug('Resharding not needed');
|
|
488
|
+
//https://github.com/discordeno/discordeno/blob/6a5f446c0651b9fad9f1550ff1857fe7a026426b/packages/gateway/src/manager.ts#L106C8-L106C94
|
|
489
|
+
const percentage = (info.shards / ((this.totalShards * 2500) / 1000)) * 100;
|
|
490
|
+
if (percentage < this.options.resharding.percentage)
|
|
491
|
+
return this.debugger?.debug(`Percentage is not enough to reshard ${percentage}/${this.options.resharding.percentage}`);
|
|
492
|
+
this.debugger?.info('Starting resharding process');
|
|
493
|
+
this._info = info;
|
|
494
|
+
this.connectQueue.concurrency = info.session_start_limit.max_concurrency;
|
|
495
|
+
this.options.info.session_start_limit.max_concurrency = info.session_start_limit.max_concurrency;
|
|
496
|
+
const spaces = WorkerManager.prepareSpaces({
|
|
497
|
+
shardsPerWorker: this.shardsPerWorker,
|
|
498
|
+
shardEnd: info.shards,
|
|
499
|
+
shardStart: 0,
|
|
500
|
+
}, this.debugger);
|
|
501
|
+
await this.prepareWorkers(spaces, true);
|
|
502
|
+
return this.reshardingWorkerQueue.shift()();
|
|
503
|
+
}, this.options.resharding.interval);
|
|
380
504
|
}
|
|
381
505
|
}
|
|
382
506
|
exports.WorkerManager = WorkerManager;
|
|
@@ -9,11 +9,10 @@ export declare class ConnectTimeout {
|
|
|
9
9
|
export declare class ConnectQueue {
|
|
10
10
|
intervalTime: number;
|
|
11
11
|
concurrency: number;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}[];
|
|
12
|
+
private queue;
|
|
13
|
+
private remaining;
|
|
15
14
|
protected interval?: NodeJS.Timeout;
|
|
16
15
|
constructor(intervalTime?: number, concurrency?: number);
|
|
17
|
-
push(callback: () =>
|
|
18
|
-
|
|
16
|
+
push(callback: () => unknown): unknown;
|
|
17
|
+
startInterval(): void;
|
|
19
18
|
}
|
|
@@ -32,41 +32,40 @@ class ConnectQueue {
|
|
|
32
32
|
intervalTime;
|
|
33
33
|
concurrency;
|
|
34
34
|
queue = [];
|
|
35
|
+
remaining = 0;
|
|
35
36
|
interval = undefined;
|
|
36
37
|
constructor(intervalTime = 5000, concurrency = 1) {
|
|
37
38
|
this.intervalTime = intervalTime;
|
|
38
39
|
this.concurrency = concurrency;
|
|
40
|
+
this.remaining = concurrency;
|
|
39
41
|
}
|
|
40
|
-
|
|
41
|
-
this.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
this.interval = setInterval(() => {
|
|
48
|
-
for (let i = 0; i < this.concurrency; i++) {
|
|
49
|
-
this.shift();
|
|
50
|
-
}
|
|
51
|
-
}, this.intervalTime);
|
|
42
|
+
push(callback) {
|
|
43
|
+
if (this.remaining === 0)
|
|
44
|
+
return this.queue.push(callback);
|
|
45
|
+
this.remaining--;
|
|
46
|
+
if (!this.interval) {
|
|
47
|
+
this.startInterval();
|
|
52
48
|
}
|
|
49
|
+
if (this.queue.length < this.concurrency) {
|
|
50
|
+
return callback();
|
|
51
|
+
}
|
|
52
|
+
return this.queue.push(callback);
|
|
53
53
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
startInterval() {
|
|
55
|
+
this.interval = setInterval(() => {
|
|
56
|
+
let cb;
|
|
57
|
+
while (this.queue.length && !(cb = this.queue.shift())) {
|
|
58
|
+
//
|
|
59
|
+
}
|
|
60
|
+
if (cb)
|
|
61
|
+
return cb?.();
|
|
62
|
+
if (this.remaining < this.concurrency)
|
|
63
|
+
return this.remaining++;
|
|
57
64
|
if (!this.queue.length) {
|
|
58
65
|
clearInterval(this.interval);
|
|
59
66
|
this.interval = undefined;
|
|
60
67
|
}
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
if (!shift.cb)
|
|
64
|
-
return this.shift();
|
|
65
|
-
await shift.cb?.();
|
|
66
|
-
if (!this.queue.length) {
|
|
67
|
-
clearInterval(this.interval);
|
|
68
|
-
this.interval = undefined;
|
|
69
|
-
}
|
|
68
|
+
}, this.intervalTime / this.concurrency);
|
|
70
69
|
}
|
|
71
70
|
}
|
|
72
71
|
exports.ConnectQueue = ConnectQueue;
|
package/package.json
CHANGED
|
@@ -1,65 +1,72 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "seyfert",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "The most advanced framework for discord bots",
|
|
5
|
-
"main": "./lib/index.js",
|
|
6
|
-
"module": "./lib/index.js",
|
|
7
|
-
"types": "./lib/index.d.ts",
|
|
8
|
-
"files": [
|
|
9
|
-
"lib/**"
|
|
10
|
-
],
|
|
11
|
-
"scripts": {
|
|
12
|
-
"build": "tsc --outDir ./lib",
|
|
13
|
-
"prepublishOnly": "npm run build",
|
|
14
|
-
"prepare": "npm run build && husky",
|
|
15
|
-
"lint": "biome lint --write ./src",
|
|
16
|
-
"format": "biome format --write ./src",
|
|
17
|
-
"check-h": "biome check --write ./src",
|
|
18
|
-
"check": "biome check --write --no-errors-on-unmatched ./src"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
"@
|
|
25
|
-
"@commitlint/
|
|
26
|
-
"@
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "seyfert",
|
|
3
|
+
"version": "2.1.1-dev-11310514874.0",
|
|
4
|
+
"description": "The most advanced framework for discord bots",
|
|
5
|
+
"main": "./lib/index.js",
|
|
6
|
+
"module": "./lib/index.js",
|
|
7
|
+
"types": "./lib/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"lib/**"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc --outDir ./lib",
|
|
13
|
+
"prepublishOnly": "npm run build",
|
|
14
|
+
"prepare": "npm run build && husky",
|
|
15
|
+
"lint": "biome lint --write ./src",
|
|
16
|
+
"format": "biome format --write ./src",
|
|
17
|
+
"check-h": "biome check --write ./src",
|
|
18
|
+
"check": "biome check --write --no-errors-on-unmatched ./src",
|
|
19
|
+
"test": "vitest run --config ./tests/vitest.config.mts ./tests/"
|
|
20
|
+
},
|
|
21
|
+
"author": "MARCROCK22",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@biomejs/biome": "1.9.3",
|
|
25
|
+
"@commitlint/cli": "^19.5.0",
|
|
26
|
+
"@commitlint/config-conventional": "^19.5.0",
|
|
27
|
+
"@types/node": "^22.7.4",
|
|
28
|
+
"husky": "^9.1.6",
|
|
29
|
+
"lint-staged": "^15.2.10",
|
|
30
|
+
"typescript": "^5.6.2",
|
|
31
|
+
"vitest": "^2.1.2"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://seyfert.dev",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/tiramisulabs/seyfert.git"
|
|
37
|
+
},
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/tiramisulabs/seyfert"
|
|
40
|
+
},
|
|
41
|
+
"keywords": [
|
|
42
|
+
"api",
|
|
43
|
+
"discord",
|
|
44
|
+
"bots",
|
|
45
|
+
"typescript",
|
|
46
|
+
"botdev"
|
|
47
|
+
],
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
},
|
|
51
|
+
"maintainers": [
|
|
52
|
+
{
|
|
53
|
+
"name": "socram03",
|
|
54
|
+
"url": "https://github.com/socram03"
|
|
55
|
+
}
|
|
56
|
+
],
|
|
57
|
+
"contributors": [
|
|
58
|
+
{
|
|
59
|
+
"name": "Free 公園",
|
|
60
|
+
"url": "https://github.com/FreeAoi"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"name": "David",
|
|
64
|
+
"url": "https://github.com/Drylozu"
|
|
65
|
+
}
|
|
66
|
+
],
|
|
67
|
+
"lint-staged": {
|
|
68
|
+
"*.ts": [
|
|
69
|
+
"biome check --write"
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { APIThreadChannel } from '../../types';
|
|
2
|
-
import type { ReturnCache } from '../..';
|
|
3
|
-
import { GuildRelatedResource } from './default/guild-related';
|
|
4
|
-
import { type ThreadChannelStructure } from '../../client/transformers';
|
|
5
|
-
export declare class Threads extends GuildRelatedResource<any, APIThreadChannel> {
|
|
6
|
-
namespace: string;
|
|
7
|
-
filter(data: APIThreadChannel, id: string, guild_id?: string): boolean;
|
|
8
|
-
get(id: string): ReturnCache<ThreadChannelStructure | undefined>;
|
|
9
|
-
raw(id: string): ReturnCache<APIThreadChannel | undefined>;
|
|
10
|
-
bulk(ids: string[]): ReturnCache<ThreadChannelStructure[]>;
|
|
11
|
-
bulkRaw(ids: string[]): ReturnCache<APIThreadChannel[]>;
|
|
12
|
-
values(guild: string): ReturnCache<ThreadChannelStructure[]>;
|
|
13
|
-
valuesRaw(guild: string): ReturnCache<APIThreadChannel[]>;
|
|
14
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Threads = void 0;
|
|
4
|
-
const common_1 = require("../../common");
|
|
5
|
-
const guild_related_1 = require("./default/guild-related");
|
|
6
|
-
const transformers_1 = require("../../client/transformers");
|
|
7
|
-
class Threads extends guild_related_1.GuildRelatedResource {
|
|
8
|
-
namespace = 'thread';
|
|
9
|
-
//@ts-expect-error
|
|
10
|
-
filter(data, id, guild_id) {
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
get(id) {
|
|
14
|
-
return (0, common_1.fakePromise)(super.get(id)).then(rawThread => rawThread ? transformers_1.Transformers.ThreadChannel(this.client, rawThread) : undefined);
|
|
15
|
-
}
|
|
16
|
-
raw(id) {
|
|
17
|
-
return super.get(id);
|
|
18
|
-
}
|
|
19
|
-
bulk(ids) {
|
|
20
|
-
return (0, common_1.fakePromise)(super.bulk(ids)).then(threads => threads.map(rawThread => transformers_1.Transformers.ThreadChannel(this.client, rawThread)));
|
|
21
|
-
}
|
|
22
|
-
bulkRaw(ids) {
|
|
23
|
-
return super.bulk(ids);
|
|
24
|
-
}
|
|
25
|
-
values(guild) {
|
|
26
|
-
return (0, common_1.fakePromise)(super.values(guild)).then(threads => threads.map(rawThread => transformers_1.Transformers.ThreadChannel(this.client, rawThread)));
|
|
27
|
-
}
|
|
28
|
-
valuesRaw(guild) {
|
|
29
|
-
return super.values(guild);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
exports.Threads = Threads;
|