添加退出时杀死插件的功能
This commit is contained in:
parent
e70174f4a4
commit
f39c3b628f
13
src/Main.ts
13
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', () => {
|
||||
|
28
src/Plugins.ts
Normal file
28
src/Plugins.ts
Normal file
@ -0,0 +1,28 @@
|
||||
const pluginSet: Set<Deno.Process> = 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()
|
||||
})
|
Loading…
x
Reference in New Issue
Block a user