seyfert 2.1.1-dev-11767975974.0 → 2.1.1-dev-11768778519.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/api.d.ts CHANGED
@@ -19,6 +19,7 @@ export declare class ApiHandler {
19
19
  }>;
20
20
  onRatelimit?: OnRatelimitCallback;
21
21
  constructor(options: ApiHandlerOptions);
22
+ set debug(active: boolean);
22
23
  get proxy(): APIRoutes;
23
24
  globalUnblock(): void;
24
25
  request<T = unknown>(method: HttpMethods, url: `/${string}`, { auth, ...request }?: ApiRequestOptions): Promise<T>;
package/lib/api/api.js CHANGED
@@ -20,16 +20,13 @@ class ApiHandler {
20
20
  constructor(options) {
21
21
  this.options = {
22
22
  baseUrl: 'api/v10',
23
- domain: 'https://discord.com',
23
+ domain: common_1.BASE_HOST,
24
24
  type: 'Bot',
25
25
  ...options,
26
26
  userAgent: shared_1.DefaultUserAgent,
27
27
  };
28
- if (options.debug) {
29
- this.debugger = new common_1.Logger({
30
- name: '[API]',
31
- });
32
- }
28
+ if (options.debug)
29
+ this.debug = true;
33
30
  const worker_threads = (0, common_1.lazyLoadPackage)('node:worker_threads');
34
31
  if (options.workerProxy && !worker_threads?.parentPort)
35
32
  throw new Error('Cannot use workerProxy without a parent.');
@@ -41,6 +38,13 @@ class ApiHandler {
41
38
  parentPort = worker_threads.parentPort;
42
39
  }
43
40
  }
41
+ set debug(active) {
42
+ this.debugger = active
43
+ ? new common_1.Logger({
44
+ name: '[API]',
45
+ })
46
+ : undefined;
47
+ }
44
48
  get proxy() {
45
49
  return (this._proxy_ ??= new Router_1.Router(this).createProxy());
46
50
  }
@@ -14,8 +14,8 @@ const voiceStates_1 = require("../common/shorters/voiceStates");
14
14
  const handler_2 = require("../components/handler");
15
15
  const handler_3 = require("../langs/handler");
16
16
  class BaseClient {
17
- rest;
18
- cache;
17
+ rest = new api_1.ApiHandler({ token: 'INVALID' });
18
+ cache = new cache_1.Cache(0, new cache_1.MemoryAdapter());
19
19
  applications = new common_1.ApplicationShorter(this);
20
20
  users = new common_1.UsersShorter(this);
21
21
  channels = new common_1.ChannelShorter(this);
@@ -122,6 +122,7 @@ class BaseClient {
122
122
  }
123
123
  setServices({ rest, cache, langs, middlewares, handleCommand }) {
124
124
  if (rest) {
125
+ rest.onRatelimit ??= this.rest.onRatelimit?.bind(rest);
125
126
  this.rest = rest;
126
127
  }
127
128
  if (cache) {
@@ -141,7 +142,7 @@ class BaseClient {
141
142
  'users',
142
143
  'voiceStates',
143
144
  ];
144
- let disabledCache = this.cache?.disabledCache ?? {};
145
+ let disabledCache = this.cache.disabledCache;
145
146
  if (typeof cache.disabledCache === 'boolean') {
146
147
  for (const i of caches) {
147
148
  disabledCache[i] = cache.disabledCache;
@@ -155,7 +156,7 @@ class BaseClient {
155
156
  else if (typeof cache.disabledCache === 'object') {
156
157
  disabledCache = cache.disabledCache;
157
158
  }
158
- this.cache = new cache_1.Cache(this.cache?.intents ?? 0, cache?.adapter ?? this.cache?.adapter ?? new cache_1.MemoryAdapter(), disabledCache, this);
159
+ this.cache = new cache_1.Cache(this.cache.intents, cache.adapter ?? this.cache.adapter, disabledCache, this);
159
160
  }
160
161
  if (middlewares) {
161
162
  this.middlewares = middlewares;
@@ -190,21 +191,11 @@ class BaseClient {
190
191
  await this.loadComponents(options.componentsDir);
191
192
  const { token: tokenRC, debug } = await this.getRC();
192
193
  const token = options?.token ?? tokenRC;
193
- if (!this.rest) {
194
- BaseClient.assertString(token, 'token is not a string');
195
- this.rest = new api_1.ApiHandler({
196
- token,
197
- baseUrl: 'api/v10',
198
- domain: 'https://discord.com',
199
- debug,
200
- });
201
- }
202
- if (this.cache) {
203
- this.cache.__setClient(this);
204
- }
205
- else {
206
- this.cache = new cache_1.Cache(0, new cache_1.MemoryAdapter(), {}, this);
207
- }
194
+ BaseClient.assertString(token, 'token is not a string');
195
+ if (this.rest.options.token === 'INVALID')
196
+ this.rest.options.token = token;
197
+ this.rest.debug = debug;
198
+ this.cache.__setClient(this);
208
199
  if (!this.handleCommand)
209
200
  this.handleCommand = new handle_1.HandleCommand(this);
210
201
  // The reason of this method is so for adapters that need to connect somewhere, have time to connect.
@@ -223,7 +214,6 @@ class BaseClient {
223
214
  });
224
215
  }
225
216
  syncCachePath(cachePath) {
226
- this.logger.debug('Syncing commands cache');
227
217
  return node_fs_1.promises.writeFile(cachePath, JSON.stringify(this.commands.values.filter(cmd => !('ignore' in cmd) || cmd.ignore !== shared_1.IgnoreCommand.Slash).map(x => x.toJSON())));
228
218
  }
229
219
  async uploadCommands({ applicationId, cachePath } = {}) {
@@ -68,6 +68,7 @@ class Client extends base_1.BaseClient {
68
68
  const { token: tokenRC, intents: intentsRC, debug: debugRC } = await this.getRC();
69
69
  const token = options?.token ?? tokenRC;
70
70
  const intents = options?.connection?.intents ?? intentsRC;
71
+ this.cache.intents = intents;
71
72
  if (!this.gateway) {
72
73
  base_1.BaseClient.assertString(token, 'token is not a string');
73
74
  this.gateway = new websocket_1.ShardManager({
@@ -95,7 +96,6 @@ class Client extends base_1.BaseClient {
95
96
  },
96
97
  });
97
98
  }
98
- this.cache.intents = this.gateway.options.intents;
99
99
  if (execute) {
100
100
  await this.execute(options.connection);
101
101
  }
@@ -109,7 +109,6 @@ class Client extends base_1.BaseClient {
109
109
  this.collectors.run('RAW', packet, this),
110
110
  ]); //ignore promise
111
111
  switch (packet.t) {
112
- // Cases where we must obtain the old data before updating
113
112
  case 'GUILD_MEMBER_UPDATE':
114
113
  {
115
114
  if (!this.memberUpdateHandler.check(packet.d)) {
@@ -1,14 +1,15 @@
1
- import { type DeepPartial, type When } from '../common';
1
+ import { type DeepPartial, type MakeRequired, type When } from '../common';
2
2
  import { EventHandler } from '../events';
3
3
  import type { GatewayDispatchPayload } from '../types';
4
4
  import { Shard, type ShardManagerOptions, type WorkerData } from '../websocket';
5
5
  import type { WorkerMessage, WorkerShardInfo } from '../websocket/discord/worker';
6
- import type { ManagerMessages } from '../websocket/discord/workermanager';
6
+ import type { ManagerMessages, ManagerSpawnShards } from '../websocket/discord/workermanager';
7
7
  import type { BaseClientOptions, ServicesOptions, StartOptions } from './base';
8
8
  import { BaseClient } from './base';
9
9
  import type { Client, ClientOptions } from './client';
10
10
  import { MemberUpdateHandler } from '../websocket/discord/events/memberUpdate';
11
11
  import { PresenceUpdateHandler } from '../websocket/discord/events/presenceUpdate';
12
+ import type { ShardData } from '../websocket/discord/shared';
12
13
  import { Collectors } from './collectors';
13
14
  import { type ClientUserStructure } from './transformers';
14
15
  export declare class WorkerClient<Ready extends boolean = boolean> extends BaseClient {
@@ -40,8 +41,10 @@ export declare class WorkerClient<Ready extends boolean = boolean> extends BaseC
40
41
  handleManagerMessages(data: ManagerMessages): Promise<any>;
41
42
  private generateNonce;
42
43
  private generateSendPromise;
43
- tellWorker<R>(workerId: number, func: (_: this) => R): Promise<R>;
44
- tellWorkers<R>(func: (_: this) => R): Promise<Awaited<R>[]>;
44
+ tellWorker<R, V extends Record<string, unknown>>(workerId: number, func: (_: this, vars: V) => R, vars: V): Promise<R>;
45
+ tellWorkers<R, V extends Record<string, unknown>>(func: (_: this, vars: V) => R, vars: V): Promise<Awaited<R>[]>;
46
+ createShard(id: number, data: Pick<ManagerSpawnShards, 'info' | 'compress'>): Shard;
47
+ resumeShard(shardId: number, shardData: MakeRequired<ShardData>): Promise<unknown>;
45
48
  protected onPacket(packet: GatewayDispatchPayload, shardId: number): Promise<void>;
46
49
  }
47
50
  export declare function generateShardInfo(shard: Shard): WorkerShardInfo;
@@ -20,7 +20,7 @@ try {
20
20
  debug: process.env.SEYFERT_WORKER_DEBUG === 'true',
21
21
  intents: Number(process.env.SEYFERT_WORKER_INTENTS),
22
22
  path: process.env.SEYFERT_WORKER_PATH,
23
- shards: process.env.SEYFERT_WORKER_SHARDS.split(',').map(id => Number(id)),
23
+ shards: JSON.parse(process.env.SEYFERT_WORKER_SHARDS),
24
24
  token: process.env.SEYFERT_WORKER_TOKEN,
25
25
  workerId: Number(process.env.SEYFERT_WORKER_WORKERID),
26
26
  workerProxy: process.env.SEYFERT_WORKER_WORKERPROXY === 'true',
@@ -28,6 +28,8 @@ try {
28
28
  mode: process.env.SEYFERT_WORKER_MODE,
29
29
  resharding: process.env.SEYFERT_WORKER_RESHARDING === 'true',
30
30
  totalWorkers: Number(process.env.SEYFERT_WORKER_TOTALWORKERS),
31
+ info: JSON.parse(process.env.SEYFERT_WORKER_INFO),
32
+ compress: process.env.SEYFERT_WORKER_COMPRESS === 'true',
31
33
  };
32
34
  }
33
35
  catch {
@@ -117,6 +119,7 @@ class WorkerClient extends base_1.BaseClient {
117
119
  }),
118
120
  });
119
121
  }
122
+ this.cache.intents = workerData.intents;
120
123
  this.postMessage({
121
124
  type: workerData.resharding ? 'WORKER_START_RESHARDING' : 'WORKER_START',
122
125
  workerId: workerData.workerId,
@@ -126,7 +129,6 @@ class WorkerClient extends base_1.BaseClient {
126
129
  }
127
130
  await super.start(options);
128
131
  await this.loadEvents(options.eventsDir);
129
- this.cache.intents = workerData.intents;
130
132
  }
131
133
  async loadEvents(dir) {
132
134
  dir ??= await this.getRC().then(x => ('events' in x.locations ? x.locations.events : undefined));
@@ -250,37 +252,13 @@ class WorkerClient extends base_1.BaseClient {
250
252
  break;
251
253
  case 'SPAWN_SHARDS':
252
254
  {
253
- const onPacket = this.onPacket.bind(this);
254
- const handlePayload = this.options?.handlePayload?.bind(this);
255
- const self = this;
256
255
  for (const id of workerData.shards) {
257
256
  const existsShard = this.shards.has(id);
258
257
  if (existsShard) {
259
258
  this.logger.warn(`Trying to spawn existing shard #${id}`);
260
259
  continue;
261
260
  }
262
- const shard = new websocket_1.Shard(id, {
263
- token: workerData.token,
264
- intents: workerData.intents,
265
- info: data.info,
266
- compress: data.compress,
267
- debugger: this.debugger,
268
- properties: {
269
- ...websocket_1.properties,
270
- ...this.options.gateway?.properties,
271
- },
272
- async handlePayload(shardId, payload) {
273
- await handlePayload?.(shardId, payload);
274
- await onPacket(payload, shardId);
275
- if (self.options.sendPayloadToParent)
276
- self.postMessage({
277
- workerId: workerData.workerId,
278
- shardId,
279
- type: 'RECEIVE_PAYLOAD',
280
- payload,
281
- });
282
- },
283
- });
261
+ const shard = this.createShard(id, data);
284
262
  this.shards.set(id, shard);
285
263
  this.postMessage({
286
264
  type: 'CONNECT_QUEUE',
@@ -335,7 +313,7 @@ class WorkerClient extends base_1.BaseClient {
335
313
  let result;
336
314
  try {
337
315
  result = await eval(`
338
- (${data.func})(this)
316
+ (${data.func})(this, ${data.vars})
339
317
  `);
340
318
  }
341
319
  catch (e) {
@@ -410,7 +388,7 @@ class WorkerClient extends base_1.BaseClient {
410
388
  this.promises.set(nonce, { resolve: res, timeout });
411
389
  });
412
390
  }
413
- tellWorker(workerId, func) {
391
+ tellWorker(workerId, func, vars) {
414
392
  const nonce = this.generateNonce();
415
393
  this.postMessage({
416
394
  type: 'EVAL_TO_WORKER',
@@ -418,23 +396,67 @@ class WorkerClient extends base_1.BaseClient {
418
396
  toWorkerId: workerId,
419
397
  workerId: workerData.workerId,
420
398
  nonce,
399
+ vars: JSON.stringify(vars),
421
400
  });
422
401
  return this.generateSendPromise(nonce);
423
402
  }
424
- tellWorkers(func) {
403
+ tellWorkers(func, vars) {
425
404
  const promises = [];
426
405
  for (let i = 0; i < workerData.totalWorkers; i++) {
427
- promises.push(this.tellWorker(i, func));
406
+ promises.push(this.tellWorker(i, func, vars));
428
407
  }
429
408
  return Promise.all(promises);
430
409
  }
410
+ createShard(id, data) {
411
+ const onPacket = this.onPacket.bind(this);
412
+ const handlePayload = this.options?.handlePayload?.bind(this);
413
+ const self = this;
414
+ const shard = new websocket_1.Shard(id, {
415
+ token: workerData.token,
416
+ intents: workerData.intents,
417
+ info: data.info,
418
+ compress: data.compress,
419
+ debugger: this.debugger,
420
+ properties: {
421
+ ...websocket_1.properties,
422
+ ...this.options.gateway?.properties,
423
+ },
424
+ async handlePayload(shardId, payload) {
425
+ await handlePayload?.(shardId, payload);
426
+ await onPacket(payload, shardId);
427
+ if (self.options.sendPayloadToParent)
428
+ self.postMessage({
429
+ workerId: workerData.workerId,
430
+ shardId,
431
+ type: 'RECEIVE_PAYLOAD',
432
+ payload,
433
+ });
434
+ },
435
+ });
436
+ return shard;
437
+ }
438
+ async resumeShard(shardId, shardData) {
439
+ const exists = (await this.tellWorkers((r, vars) => r.shards.has(vars.shardId), { shardId })).some(x => x);
440
+ if (exists)
441
+ throw new Error('Cannot override existing shard');
442
+ const shard = this.createShard(shardId, {
443
+ info: this.workerData.info,
444
+ compress: this.workerData.compress,
445
+ });
446
+ shard.data = shardData;
447
+ this.shards.set(shardId, shard);
448
+ return this.postMessage({
449
+ workerId: this.workerId,
450
+ shardId,
451
+ type: 'CONNECT_QUEUE',
452
+ });
453
+ }
431
454
  async onPacket(packet, shardId) {
432
455
  Promise.allSettled([
433
456
  this.events?.runEvent('RAW', this, packet, shardId, false),
434
457
  this.collectors.run('RAW', packet, this),
435
458
  ]); //ignore promise
436
459
  switch (packet.t) {
437
- //// Cases where we must obtain the old data before updating
438
460
  case 'GUILD_MEMBER_UPDATE':
439
461
  {
440
462
  if (!this.memberUpdateHandler.check(packet.d)) {
@@ -448,16 +448,14 @@ class CommandHandler extends common_1.BaseHandler {
448
448
  if (!(commandInstance instanceof menu_1.ContextMenuCommand))
449
449
  return false;
450
450
  commandInstance.onAfterRun ??= this.client.options.commands?.defaults?.onAfterRun;
451
- //@ts-expect-error magic.
452
- commandInstance.onBotPermissionsFail ??= this.client.options.commands?.defaults?.onBotPermissionsFail;
453
- //@ts-expect-error magic.
454
- commandInstance.onInternalError ??= this.client.options.commands?.defaults?.onInternalError;
455
- //@ts-expect-error magic.
456
- commandInstance.onMiddlewaresError ??= this.client.options.commands?.defaults?.onMiddlewaresError;
457
- //@ts-expect-error magic.
458
- commandInstance.onPermissionsFail ??= this.client.options.commands?.defaults?.onPermissionsFail;
459
- //@ts-expect-error magic.
460
- commandInstance.onRunError ??= this.client.options.commands?.defaults?.onRunError;
451
+ if (this.client.options.commands?.defaults?.onBotPermissionsFail)
452
+ commandInstance.onBotPermissionsFail ??= this.client.options.commands?.defaults?.onBotPermissionsFail;
453
+ if (this.client.options.commands?.defaults?.onInternalError)
454
+ commandInstance.onInternalError ??= this.client.options.commands.defaults.onInternalError;
455
+ if (this.client.options.commands?.defaults?.onMiddlewaresError)
456
+ commandInstance.onMiddlewaresError ??= this.client.options.commands.defaults.onMiddlewaresError;
457
+ if (this.client.options.commands?.defaults?.onRunError)
458
+ commandInstance.onRunError ??= this.client.options.commands.defaults.onRunError;
461
459
  return commandInstance;
462
460
  }
463
461
  stablishCommandDefaults(commandInstance) {
@@ -3,6 +3,7 @@ import type { GuildMemberStructure, GuildStructure } from '../client/transformer
3
3
  import type { CommandMetadata, ExtendContext, GlobalMetadata, RegisteredMiddlewares, UsingClient } from '../commands';
4
4
  import { BaseContext } from '../commands/basecontext';
5
5
  import type { InteractionCreateBodyRequest, InteractionMessageUpdateBodyRequest, MakeRequired, ModalCreateBodyRequest, UnionToTuple } from '../common';
6
+ import type { Interaction } from '../structures/Interaction';
6
7
  export interface ModalContext extends BaseContext, ExtendContext {
7
8
  }
8
9
  /**
@@ -67,7 +68,7 @@ export declare class ModalContext<M extends keyof RegisteredMiddlewares = never>
67
68
  * @returns A promise that resolves when the response is deleted.
68
69
  */
69
70
  deleteResponse(): Promise<void | undefined>;
70
- modal(body: ModalCreateBodyRequest): any;
71
+ modal(body: ModalCreateBodyRequest): ReturnType<Interaction['modal']>;
71
72
  /**
72
73
  * Gets the channel of the interaction.
73
74
  * @param mode - The mode to fetch the channel.
@@ -192,20 +192,20 @@ class EventHandler extends common_1.BaseHandler {
192
192
  async runCustom(name, ...args) {
193
193
  const Event = this.values[name];
194
194
  if (!Event) {
195
- // @ts-expect-error working with non-existent types is hard
195
+ // @ts-expect-error
196
196
  return this.client.collectors.run(name, args, this.client);
197
197
  }
198
198
  try {
199
199
  if (Event.data.once && Event.fired) {
200
- // @ts-expect-error working with non-existent types is hard
200
+ // @ts-expect-error
201
201
  return this.client.collectors.run(name, args, this.client);
202
202
  }
203
203
  Event.fired = true;
204
204
  this.logger.debug(`executed a custom event [${name}]`, Event.data.once ? 'once' : '');
205
205
  await Promise.all([
206
- // @ts-expect-error working with non-existent types is hard
206
+ // @ts-expect-error
207
207
  Event.run(...args, this.client),
208
- // @ts-expect-error working with non-existent types is hard
208
+ // @ts-expect-error
209
209
  this.client.collectors.run(name, args, this.client),
210
210
  ]);
211
211
  }
@@ -75,8 +75,8 @@ class Shard {
75
75
  }
76
76
  clearTimeout(this.heart.nodeInterval);
77
77
  this.debugger?.debug(`[Shard #${this.id}] Connecting to ${this.currentGatewayURL}`);
78
- // @ts-expect-error @types/bun cause erros in compile
79
- // biome-ignore lint/correctness/noUndeclaredVariables: /\ bun lol
78
+ // @ts-expect-error Use native websocket when using Bun
79
+ // biome-ignore lint/correctness/noUndeclaredVariables: /\
80
80
  this.websocket = new basesocket_1.BaseSocket(typeof Bun === 'undefined' ? 'ws' : 'bun', this.currentGatewayURL);
81
81
  this.websocket.onmessage = ({ data }) => {
82
82
  this.handleMessage(data);
@@ -117,6 +117,8 @@ export interface WorkerData {
117
117
  workerId: number;
118
118
  debug: boolean;
119
119
  workerProxy: boolean;
120
+ info: APIGatewayBotInfo;
121
+ compress: boolean;
120
122
  __USING_WATCHER__?: boolean;
121
123
  resharding: boolean;
122
124
  }
@@ -57,6 +57,7 @@ export type WorkerSendEvalResponse = CreateWorkerMessage<'EVAL_RESPONSE', {
57
57
  export type WorkerSendToWorkerEval = CreateWorkerMessage<'EVAL_TO_WORKER', {
58
58
  func: string;
59
59
  nonce: string;
60
+ vars: string;
60
61
  toWorkerId: number;
61
62
  }>;
62
63
  export type WorkerMessage = WorkerRequestConnect | WorkerReceivePayload | WorkerSendResultPayload | WorkerSendCacheRequest | WorkerSendShardInfo | WorkerSendInfo | WorkerReady | WorkerShardsConnected | WorkerSendApiRequest | WorkerSendEvalResponse | WorkerSendToWorkerEval | WorkerStart | WorkerStartResharding | WorkerRequestConnectResharding | WorkerReadyResharding | WorkerDisconnectedAllShardsResharding;
@@ -68,8 +68,8 @@ export declare class WorkerManager extends Map<number, (ClusterWorker | WorkerTh
68
68
  send(data: GatewaySendPayload, shardId: number): Promise<true>;
69
69
  getShardInfo(shardId: number): Promise<WorkerShardInfo>;
70
70
  getWorkerInfo(workerId: number): Promise<WorkerInfo>;
71
- tellWorker<R>(workerId: number, func: (_: WorkerClient & UsingClient) => R): Promise<R>;
72
- tellWorkers<R>(func: (_: WorkerClient & UsingClient) => R): Promise<Awaited<R>[]>;
71
+ tellWorker<R, V extends Record<string, unknown>>(workerId: number, func: (_: WorkerClient & UsingClient, vars: V) => R, vars: V): Promise<R>;
72
+ tellWorkers<R, V extends Record<string, unknown>>(func: (_: WorkerClient & UsingClient, vars: V) => R, vars: V): Promise<Awaited<R>[]>;
73
73
  start(): Promise<void>;
74
74
  startResharding(): Promise<void>;
75
75
  }
@@ -113,10 +113,12 @@ export type ManagerSendApiResponse = CreateManagerMessage<'API_RESPONSE', {
113
113
  export type ManagerExecuteEvalToWorker = CreateManagerMessage<'EXECUTE_EVAL_TO_WORKER', {
114
114
  func: string;
115
115
  nonce: string;
116
+ vars: string;
116
117
  toWorkerId: number;
117
118
  }>;
118
119
  export type ManagerExecuteEval = CreateManagerMessage<'EXECUTE_EVAL', {
119
120
  func: string;
121
+ vars: string;
120
122
  nonce: string;
121
123
  }>;
122
124
  export type ManagerSendEvalResponse = CreateManagerMessage<'EVAL_RESPONSE', {
@@ -124,6 +124,11 @@ class WorkerManager extends Map {
124
124
  mode: this.options.mode,
125
125
  resharding,
126
126
  totalWorkers: shards.length,
127
+ info: {
128
+ ...this.options.info,
129
+ shards: this.totalShards,
130
+ },
131
+ compress: this.options.compress,
127
132
  });
128
133
  this.set(i, worker);
129
134
  });
@@ -149,7 +154,8 @@ class WorkerManager extends Map {
149
154
  if (workerData.resharding)
150
155
  env.SEYFERT_WORKER_RESHARDING = 'true';
151
156
  for (const i in workerData) {
152
- env[`SEYFERT_WORKER_${i.toUpperCase()}`] = workerData[i];
157
+ const data = workerData[i];
158
+ env[`SEYFERT_WORKER_${i.toUpperCase()}`] = typeof data === 'object' && data ? JSON.stringify(data) : data;
153
159
  }
154
160
  switch (this.options.mode) {
155
161
  case 'threads': {
@@ -381,6 +387,7 @@ class WorkerManager extends Map {
381
387
  func: message.func,
382
388
  type: 'EXECUTE_EVAL_TO_WORKER',
383
389
  toWorkerId: message.toWorkerId,
390
+ vars: message.vars,
384
391
  });
385
392
  this.generateSendPromise(nonce, 'Eval timeout').then(val => this.postMessage(message.workerId, {
386
393
  nonce: message.nonce,
@@ -440,19 +447,20 @@ class WorkerManager extends Map {
440
447
  this.postMessage(workerId, { nonce, type: 'WORKER_INFO' });
441
448
  return this.generateSendPromise(nonce, 'Get worker info timeout');
442
449
  }
443
- tellWorker(workerId, func) {
450
+ tellWorker(workerId, func, vars) {
444
451
  const nonce = this.generateNonce();
445
452
  this.postMessage(workerId, {
446
453
  type: 'EXECUTE_EVAL',
447
454
  func: func.toString(),
448
455
  nonce,
456
+ vars: JSON.stringify(vars),
449
457
  });
450
458
  return this.generateSendPromise(nonce);
451
459
  }
452
- tellWorkers(func) {
460
+ tellWorkers(func, vars) {
453
461
  const promises = [];
454
462
  for (const i of this.keys()) {
455
- promises.push(this.tellWorker(i, func));
463
+ promises.push(this.tellWorker(i, func, vars));
456
464
  }
457
465
  return Promise.all(promises);
458
466
  }
@@ -464,7 +472,7 @@ class WorkerManager extends Map {
464
472
  this.rest ??= new __1.ApiHandler({
465
473
  token: this.options.token,
466
474
  baseUrl: 'api/v10',
467
- domain: 'https://discord.com',
475
+ domain: common_1.BASE_HOST,
468
476
  debug: this.options.debug,
469
477
  });
470
478
  this.options.info ??= await this.rest.proxy.gateway.bot.get();
@@ -487,7 +495,7 @@ class WorkerManager extends Map {
487
495
  shardEnd: this.shardEnd,
488
496
  shardsPerWorker: this.shardsPerWorker,
489
497
  }, this.debugger);
490
- await this.prepareWorkers(spaces);
498
+ this.prepareWorkers(spaces);
491
499
  // Start workers queue
492
500
  this.workerQueue.shift()();
493
501
  await this.startResharding();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "seyfert",
3
- "version": "2.1.1-dev-11767975974.0",
3
+ "version": "2.1.1-dev-11768778519.0",
4
4
  "description": "The most advanced framework for discord bots",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",