Simp-O-Matic

Dumb Discord bot in TS.
git clone git://git.knutsen.co/Simp-O-Matic
Log | Files | Refs | README | LICENSE

commit 70601d4239e694b2b332ad01ca0b4e5af82f675a
parent 713328e6fc3ddab95b2afc3ab9397e062d98365f
Author: Demonstrandum <moi@knutsen.co>
Date:   Fri, 20 Nov 2020 20:07:05 +0000

Ensure child processes are killed after stdio streams are finished.

Diffstat:
Mlib/commands/tts.ts | 5++++-
Mlib/commands/vc.ts | 6++++++
2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/lib/commands/tts.ts b/lib/commands/tts.ts @@ -27,7 +27,10 @@ export default async (hs : HomeScope) => { const temp = GID.vc.play(stream); - temp.on('finish', () => { + child.on('close', () => child.kill()); + stream.on('end', () => { + stream.pause(); + child.kill(); temp.destroy(); if (GID.vc_current_stream) { // THIS DOES NOT WORK. I cannot seem to get the song to diff --git a/lib/commands/vc.ts b/lib/commands/vc.ts @@ -26,6 +26,11 @@ export default async (home_scope: HomeScope) => { const child = cp.spawn('youtube-dl', [...YTDL_OPTIONS, url], { stdio: ['ignore', 'pipe', 'pipe'] }); + child.stdout.on('end', () => { + child.stdout.pause(); + child.stderr.pause(); + child.kill(); + }); child.on('close', async (code) => { if (code && code !== 0) { console.log(`Exited with code ${code}:`); @@ -36,6 +41,7 @@ export default async (home_scope: HomeScope) => { CONFIG.vc_queue = CONFIG.vc_queue.filter(q => q !== url); message.answer("Error downloading media."); } + child.kill(); }); stream = child.stdout; } catch (e) { console.log(e); }