mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-01 20:46:08 +00:00
chore: move Watcher to extra monorepo
This commit is contained in:
parent
c5935a1ad3
commit
b30b6dde24
@ -28,13 +28,11 @@
|
||||
"@biomejs/biome": "1.8.3",
|
||||
"@commitlint/cli": "^19.4.0",
|
||||
"@commitlint/config-conventional": "^19.2.2",
|
||||
"@types/node": "^22.4.0",
|
||||
"husky": "^9.1.4",
|
||||
"lint-staged": "^15.2.9",
|
||||
"typescript": "^5.5.4"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"chokidar": "^3.6.0"
|
||||
},
|
||||
"homepage": "https://seyfert.dev",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
99
pnpm-lock.yaml
generated
99
pnpm-lock.yaml
generated
@ -7,10 +7,6 @@ settings:
|
||||
importers:
|
||||
|
||||
.:
|
||||
optionalDependencies:
|
||||
chokidar:
|
||||
specifier: ^3.6.0
|
||||
version: 3.6.0
|
||||
devDependencies:
|
||||
'@biomejs/biome':
|
||||
specifier: 1.8.3
|
||||
@ -21,6 +17,9 @@ importers:
|
||||
'@commitlint/config-conventional':
|
||||
specifier: ^19.2.2
|
||||
version: 19.2.2
|
||||
'@types/node':
|
||||
specifier: ^22.4.0
|
||||
version: 22.4.0
|
||||
husky:
|
||||
specifier: ^9.1.4
|
||||
version: 9.1.4
|
||||
@ -204,20 +203,12 @@ packages:
|
||||
resolution: {integrity: sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==}
|
||||
engines: {node: '>=12'}
|
||||
|
||||
anymatch@3.1.3:
|
||||
resolution: {integrity: sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==}
|
||||
engines: {node: '>= 8'}
|
||||
|
||||
argparse@2.0.1:
|
||||
resolution: {integrity: sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==}
|
||||
|
||||
array-ify@1.0.0:
|
||||
resolution: {integrity: sha512-c5AMf34bKdvPhQ7tBGhqkgKNUzMr4WUs+WDtC2ZUGOUncbxKMTvqxYctiseW3+L4bA8ec+GcZ6/A/FW4m8ukng==}
|
||||
|
||||
binary-extensions@2.3.0:
|
||||
resolution: {integrity: sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
braces@3.0.3:
|
||||
resolution: {integrity: sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==}
|
||||
engines: {node: '>=8'}
|
||||
@ -234,10 +225,6 @@ packages:
|
||||
resolution: {integrity: sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==}
|
||||
engines: {node: ^12.17.0 || ^14.13 || >=16.0.0}
|
||||
|
||||
chokidar@3.6.0:
|
||||
resolution: {integrity: sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==}
|
||||
engines: {node: '>= 8.10.0'}
|
||||
|
||||
cli-cursor@5.0.0:
|
||||
resolution: {integrity: sha512-aCj4O5wKyszjMmDT4tZj93kxyydN/K5zPWSCe6/0AV/AA1pqe5ZBIw0a2ZfPQV7lL5/yb5HsUreJ6UFAF1tEQw==}
|
||||
engines: {node: '>=18'}
|
||||
@ -370,11 +357,6 @@ packages:
|
||||
resolution: {integrity: sha512-YyZM99iHrqLKjmt4LJDj58KI+fYyufRLBSYcqycxf//KpBk9FoewoGX0450m9nB44qrZnovzC2oeP5hUibxc/g==}
|
||||
engines: {node: '>=18'}
|
||||
|
||||
fsevents@2.3.3:
|
||||
resolution: {integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==}
|
||||
engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0}
|
||||
os: [darwin]
|
||||
|
||||
get-caller-file@2.0.5:
|
||||
resolution: {integrity: sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==}
|
||||
engines: {node: 6.* || 8.* || >= 10.*}
|
||||
@ -392,10 +374,6 @@ packages:
|
||||
engines: {node: '>=16'}
|
||||
hasBin: true
|
||||
|
||||
glob-parent@5.1.2:
|
||||
resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==}
|
||||
engines: {node: '>= 6'}
|
||||
|
||||
global-directory@4.0.1:
|
||||
resolution: {integrity: sha512-wHTUcDUoZ1H5/0iVqEudYW4/kAlN5cZ3j/bXn0Dpbizl9iaUVeWSHqiOjsgk6OW2bkLclbBjzewBz6weQ1zA2Q==}
|
||||
engines: {node: '>=18'}
|
||||
@ -427,14 +405,6 @@ packages:
|
||||
is-arrayish@0.2.1:
|
||||
resolution: {integrity: sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg==}
|
||||
|
||||
is-binary-path@2.1.0:
|
||||
resolution: {integrity: sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
is-extglob@2.1.1:
|
||||
resolution: {integrity: sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
|
||||
is-fullwidth-code-point@3.0.0:
|
||||
resolution: {integrity: sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==}
|
||||
engines: {node: '>=8'}
|
||||
@ -447,10 +417,6 @@ packages:
|
||||
resolution: {integrity: sha512-OVa3u9kkBbw7b8Xw5F9P+D/T9X+Z4+JruYVNapTjPYZYUznQ5YfWeFkOj606XYYW8yugTfC8Pj0hYqvi4ryAhA==}
|
||||
engines: {node: '>=18'}
|
||||
|
||||
is-glob@4.0.3:
|
||||
resolution: {integrity: sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
|
||||
is-number@7.0.0:
|
||||
resolution: {integrity: sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==}
|
||||
engines: {node: '>=0.12.0'}
|
||||
@ -567,10 +533,6 @@ packages:
|
||||
ms@2.1.2:
|
||||
resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==}
|
||||
|
||||
normalize-path@3.0.0:
|
||||
resolution: {integrity: sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
|
||||
npm-run-path@5.3.0:
|
||||
resolution: {integrity: sha512-ppwTtiJZq0O/ai0z7yfudtBpWIoxM8yE6nHi1X47eFR2EWORqfbu6CnPlNsjeN683eT0qG6H/Pyf9fCcvjnnnQ==}
|
||||
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
|
||||
@ -623,10 +585,6 @@ packages:
|
||||
engines: {node: '>=0.10'}
|
||||
hasBin: true
|
||||
|
||||
readdirp@3.6.0:
|
||||
resolution: {integrity: sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==}
|
||||
engines: {node: '>=8.10.0'}
|
||||
|
||||
require-directory@2.1.1:
|
||||
resolution: {integrity: sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
@ -964,19 +922,10 @@ snapshots:
|
||||
|
||||
ansi-styles@6.2.1: {}
|
||||
|
||||
anymatch@3.1.3:
|
||||
dependencies:
|
||||
normalize-path: 3.0.0
|
||||
picomatch: 2.3.1
|
||||
optional: true
|
||||
|
||||
argparse@2.0.1: {}
|
||||
|
||||
array-ify@1.0.0: {}
|
||||
|
||||
binary-extensions@2.3.0:
|
||||
optional: true
|
||||
|
||||
braces@3.0.3:
|
||||
dependencies:
|
||||
fill-range: 7.1.1
|
||||
@ -991,19 +940,6 @@ snapshots:
|
||||
|
||||
chalk@5.3.0: {}
|
||||
|
||||
chokidar@3.6.0:
|
||||
dependencies:
|
||||
anymatch: 3.1.3
|
||||
braces: 3.0.3
|
||||
glob-parent: 5.1.2
|
||||
is-binary-path: 2.1.0
|
||||
is-glob: 4.0.3
|
||||
normalize-path: 3.0.0
|
||||
readdirp: 3.6.0
|
||||
optionalDependencies:
|
||||
fsevents: 2.3.3
|
||||
optional: true
|
||||
|
||||
cli-cursor@5.0.0:
|
||||
dependencies:
|
||||
restore-cursor: 5.1.0
|
||||
@ -1131,9 +1067,6 @@ snapshots:
|
||||
path-exists: 5.0.0
|
||||
unicorn-magic: 0.1.0
|
||||
|
||||
fsevents@2.3.3:
|
||||
optional: true
|
||||
|
||||
get-caller-file@2.0.5: {}
|
||||
|
||||
get-east-asian-width@1.2.0: {}
|
||||
@ -1146,11 +1079,6 @@ snapshots:
|
||||
meow: 12.1.1
|
||||
split2: 4.2.0
|
||||
|
||||
glob-parent@5.1.2:
|
||||
dependencies:
|
||||
is-glob: 4.0.3
|
||||
optional: true
|
||||
|
||||
global-directory@4.0.1:
|
||||
dependencies:
|
||||
ini: 4.1.1
|
||||
@ -1172,14 +1100,6 @@ snapshots:
|
||||
|
||||
is-arrayish@0.2.1: {}
|
||||
|
||||
is-binary-path@2.1.0:
|
||||
dependencies:
|
||||
binary-extensions: 2.3.0
|
||||
optional: true
|
||||
|
||||
is-extglob@2.1.1:
|
||||
optional: true
|
||||
|
||||
is-fullwidth-code-point@3.0.0: {}
|
||||
|
||||
is-fullwidth-code-point@4.0.0: {}
|
||||
@ -1188,11 +1108,6 @@ snapshots:
|
||||
dependencies:
|
||||
get-east-asian-width: 1.2.0
|
||||
|
||||
is-glob@4.0.3:
|
||||
dependencies:
|
||||
is-extglob: 2.1.1
|
||||
optional: true
|
||||
|
||||
is-number@7.0.0: {}
|
||||
|
||||
is-obj@2.0.0: {}
|
||||
@ -1294,9 +1209,6 @@ snapshots:
|
||||
|
||||
ms@2.1.2: {}
|
||||
|
||||
normalize-path@3.0.0:
|
||||
optional: true
|
||||
|
||||
npm-run-path@5.3.0:
|
||||
dependencies:
|
||||
path-key: 4.0.0
|
||||
@ -1340,11 +1252,6 @@ snapshots:
|
||||
|
||||
pidtree@0.6.0: {}
|
||||
|
||||
readdirp@3.6.0:
|
||||
dependencies:
|
||||
picomatch: 2.3.1
|
||||
optional: true
|
||||
|
||||
require-directory@2.1.1: {}
|
||||
|
||||
require-from-string@2.0.2: {}
|
||||
|
@ -1,123 +1,6 @@
|
||||
import type { GatewayDispatchPayload, GatewaySendPayload } from '../../types';
|
||||
import { execSync } from 'node:child_process';
|
||||
import { ApiHandler, Router } from '../../api';
|
||||
import { BaseClient, type InternalRuntimeConfig } from '../../client/base';
|
||||
import { ShardManager, type ShardManagerDefaults, type ShardManagerOptions } from '../../websocket';
|
||||
import { Logger } from '../it/logger';
|
||||
import type { MakePartial, MakeRequired } from '../types/util';
|
||||
import { lazyLoadPackage } from '../it/utils';
|
||||
|
||||
/**
|
||||
* Represents a watcher class that extends the ShardManager.
|
||||
*/
|
||||
export class Watcher extends ShardManager {
|
||||
worker?: import('node:worker_threads').Worker;
|
||||
logger = new Logger({
|
||||
name: '[Watcher]',
|
||||
});
|
||||
rest?: ApiHandler;
|
||||
|
||||
declare options: MakeRequired<WatcherOptions, 'token' | 'info' | keyof typeof ShardManagerDefaults>;
|
||||
|
||||
/**
|
||||
* Initializes a new instance of the Watcher class.
|
||||
* @param options The options for the watcher.
|
||||
*/
|
||||
constructor(options: WatcherOptions) {
|
||||
super({
|
||||
handlePayload() {},
|
||||
token: '',
|
||||
intents: 0,
|
||||
info: {
|
||||
url: 'wss://gateway.discord.gg',
|
||||
session_start_limit: {
|
||||
max_concurrency: -1,
|
||||
remaining: -1,
|
||||
reset_after: -1,
|
||||
total: -1,
|
||||
},
|
||||
shards: -1,
|
||||
},
|
||||
...options,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the worker instance.
|
||||
*/
|
||||
resetWorker() {
|
||||
const worker_threads = lazyLoadPackage<typeof import('node:worker_threads')>('node:worker_threads');
|
||||
if (!worker_threads) throw new Error('Cannot use worker_threads');
|
||||
if (this.worker) {
|
||||
this.worker.terminate();
|
||||
}
|
||||
this.build();
|
||||
this.worker = new worker_threads.Worker(this.options.filePath, {
|
||||
argv: this.options.argv,
|
||||
workerData: {
|
||||
__USING_WATCHER__: true,
|
||||
},
|
||||
});
|
||||
this.worker!.on('message', (data: WatcherSendToShard) => {
|
||||
switch (data.type) {
|
||||
case 'SEND_TO_SHARD':
|
||||
this.send(data.shardId, data.payload);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawns shards for the watcher.
|
||||
*/
|
||||
async spawnShards() {
|
||||
const RC = await BaseClient.prototype.getRC<InternalRuntimeConfig>();
|
||||
this.options.token = RC.token;
|
||||
this.rest ??= new ApiHandler({
|
||||
baseUrl: 'api/v10',
|
||||
domain: 'https://discord.com',
|
||||
token: this.options.token,
|
||||
});
|
||||
this.options.intents = RC.intents;
|
||||
this.options.info = await new Router(this.rest!).createProxy().gateway.bot.get();
|
||||
this.options.totalShards = this.options.info.shards;
|
||||
|
||||
this.resetWorker();
|
||||
|
||||
const oldFn = this.options.handlePayload;
|
||||
this.options.handlePayload = (shardId, payload) => {
|
||||
this.worker?.postMessage({
|
||||
type: 'PAYLOAD',
|
||||
shardId,
|
||||
payload,
|
||||
} satisfies WatcherPayload);
|
||||
return oldFn?.(shardId, payload);
|
||||
};
|
||||
this.connectQueue.concurrency = this.options.info.session_start_limit.max_concurrency;
|
||||
|
||||
await super.spawnShards();
|
||||
|
||||
const chokidar = lazyLoadPackage<typeof import('chokidar')>('chokidar');
|
||||
|
||||
if (!chokidar?.watch) return this.logger.warn('No chokidar installed.');
|
||||
|
||||
const watcher = chokidar.watch(this.options.srcPath).on('ready', () => {
|
||||
this.logger.debug(`Watching ${this.options.srcPath}`);
|
||||
watcher.on('all', event => {
|
||||
this.logger.debug(`${event} event detected, building`);
|
||||
this.resetWorker();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the watcher.
|
||||
*/
|
||||
protected build() {
|
||||
execSync(`cd ${process.cwd()} && ${this.options.transpileCommand}`);
|
||||
this.logger.info('Builded');
|
||||
}
|
||||
}
|
||||
import type { ShardManager, ShardManagerOptions } from '../../websocket';
|
||||
import type { MakePartial } from '../types/util';
|
||||
|
||||
export interface WatcherOptions
|
||||
extends MakePartial<
|
||||
|
@ -9,7 +9,7 @@ import {
|
||||
} from './client/base';
|
||||
import type { CustomEventsKeys, ClientNameEvents, EventContext } from './events';
|
||||
import { isCloudfareWorker } from './common';
|
||||
export { Logger, PermissionStrings, Watcher, Formatter } from './common';
|
||||
export { Logger, PermissionStrings, Formatter } from './common';
|
||||
//
|
||||
export { Collection, LimitedCollection } from './collection';
|
||||
//
|
||||
|
Loading…
x
Reference in New Issue
Block a user