Simp-O-Matic

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

commit 254a59bb90b07e47272b62786a4cce7e3ced5b2f
parent 7ad9c948e6a76d3f2c662433514481e3f23c8191
Author: Demonstrandum <moi@knutsen.co>
Date:   Sun, 22 Mar 2020 22:44:47 +0000

Exit gracefully...

Diffstat:
Mlib/commands/uptime.ts | 2+-
Mlib/main.ts | 23+++++++++++++----------
2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/lib/commands/uptime.ts b/lib/commands/uptime.ts @@ -6,7 +6,7 @@ export default (home_scope : HomeScope) => { const { uptime } = message.client; let seconds = uptime / 1000; - const [days, hours] = [ + const [days, hours] = [ Math.floor(seconds / 86400), Math.floor(seconds / 3600) ]; diff --git a/lib/main.ts b/lib/main.ts @@ -599,18 +599,25 @@ export class SimpOMatic { } } -const on_termination = () => { +function on_termination() { // Back-up the resultant CONFIG to an external file. console.log('Cleaning up...'); write_file(`${process.cwd()}/export-exit.json`, export_config(GLOBAL_CONFIG, {})); pastebin_update(export_config(GLOBAL_CONFIG, {})); // Make sure we saved ok. - return new Promise(res => setTimeout(() => { - res(null); + setTimeout(() => { console.log('Clean finished.'); process.exit(0); - }, 6000)); -}; + }, 6000).unref(); +} + +// Handle exits. +process.on('exit', on_termination); +process.on('SIGINT', on_termination); +process.on('SIGTERM', on_termination); +process.on('SIGUSR1', on_termination); +process.on('SIGUSR2', on_termination); +process.on('uncaughtException', on_termination); // CONFIG will eventually update to the online version. pastebin_latest().then(res => { @@ -631,8 +638,4 @@ pastebin_latest().then(res => { }).catch(console.warn); -// Handle exits. -process.on('exit', on_termination); -process.on('SIGINT', on_termination); -process.on('SIGUSR1', on_termination); -process.on('SIGUSR2', on_termination); +