From 01c647d675b771e815a545cbfa4267fe48d2fbef Mon Sep 17 00:00:00 2001 From: Jan <26145882+imverum@users.noreply.github.com> Date: Sun, 27 Dec 2020 14:31:47 +0100 Subject: [PATCH] Add SIGINT handler --- index.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 629e7e5..f8039cf 100644 --- a/index.js +++ b/index.js @@ -22,4 +22,22 @@ async function runModules() { await require(`./util/${file}`).run(); } } -runModules(); \ No newline at end of file +runModules(); + + +// Destroy client when SIGINT +process.on('SIGINT', async () => { + process.stdin.resume(); // Don't exit immediately + + console.log(''); + logger.info('SIGINT received.'); + + try { + await client.destroy(); + } catch(e) { + logger.warn('Failed to destroy client'); + } + + logger.done('Logged out client, exiting.'); + process.exit(); +}); \ No newline at end of file