diff --git a/src/Main.ts b/src/Main.ts index 266d157..117a259 100644 --- a/src/Main.ts +++ b/src/Main.ts @@ -2,18 +2,7 @@ import config from './Config.ts' import { DanmakuReceiver } from './DanmakuReceiver.ts' import { onGraud, onLiveEnd, onLiveStart, onSuperChat, onTotalGift, receiveDanmaku, receiveGift } from './DanmakuCallbacks.ts' import { printLog } from './utils/mod.ts' - -async function launchAllPlugins() { - const pluginsList = await Deno.readDir('./plugins') - for await (const plugin of pluginsList) { - if (plugin.name === '.gitkeep') { - continue - } - Deno.run({ - cmd: [`./plugins/${plugin.name}/${plugin.name}`, `./plugins/${plugin.name}/config.json`] - }) - } -} +import { launchAllPlugins } from './Plugins.ts' const danmakuReceiver = new DanmakuReceiver(config.room_id) danmakuReceiver.on('connected', () => { diff --git a/src/Plugins.ts b/src/Plugins.ts new file mode 100644 index 0000000..2e1fccc --- /dev/null +++ b/src/Plugins.ts @@ -0,0 +1,28 @@ +const pluginSet: Set = new Set() + +export async function launchAllPlugins() { + const pluginsList = await Deno.readDir('./plugins') + for await (const plugin of pluginsList) { + if (plugin.name === '.gitkeep') { + continue + } + const pluginProcess = Deno.run({ + cmd: [`./plugins/${plugin.name}/${plugin.name}`, `./plugins/${plugin.name}/config.json`] + }) + pluginSet.add(pluginProcess) + } +} + +Deno.addSignalListener("SIGTERM", () => { + for (const pluginProcess of pluginSet) { + pluginProcess.kill() + } + Deno.exit() +}) + +Deno.addSignalListener("SIGINT", () => { + for (const pluginProcess of pluginSet) { + pluginProcess.kill() + } + Deno.exit() +}) \ No newline at end of file