Harden bot, storage and web API
This commit is contained in:
parent
e974bc6660
commit
20624a5c9c
43 changed files with 1265 additions and 1012 deletions
33
index.js
33
index.js
|
|
@ -56,9 +56,36 @@ for (const file of eventFiles) {
|
|||
}
|
||||
}
|
||||
|
||||
client.login(config.token);
|
||||
|
||||
const musicQueue = new MusicQueue(client);
|
||||
startWebServer({ queue: musicQueue });
|
||||
await client.login(config.token);
|
||||
|
||||
const { server } = startWebServer({ queue: musicQueue });
|
||||
|
||||
server.on("error", (error) => {
|
||||
console.error("HTTP server error", error);
|
||||
});
|
||||
|
||||
let shuttingDown = false;
|
||||
async function shutdown(signal) {
|
||||
if (shuttingDown) return;
|
||||
shuttingDown = true;
|
||||
console.log(`[${new Date().toLocaleString()}] Shutting down (${signal})`);
|
||||
|
||||
musicQueue.shutdown();
|
||||
client.destroy();
|
||||
|
||||
const forceExit = setTimeout(() => process.exit(1), 10_000);
|
||||
forceExit.unref();
|
||||
|
||||
server.close(() => {
|
||||
clearTimeout(forceExit);
|
||||
});
|
||||
}
|
||||
|
||||
process.once("SIGTERM", () => void shutdown("SIGTERM"));
|
||||
process.once("SIGINT", () => void shutdown("SIGINT"));
|
||||
process.on("unhandledRejection", (error) => {
|
||||
console.error("Unhandled promise rejection", error);
|
||||
});
|
||||
|
||||
export { client, musicQueue };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue