Added extra pm2 and sigint handling

This commit is contained in:
TheEssem 2020-07-21 20:29:32 -05:00
parent bf19e24063
commit 950ce00a80
4 changed files with 23 additions and 5 deletions

View file

@ -30,6 +30,9 @@ OUTPUT=
# Put temporary image dir here (make sure it's accessible via a web server), leave blank to disable
TEMPDIR=
# Set this to true if you're using PM2 to manage the bot
PMTWO=false
# Enable/disable Twitter bot (true/false)
TWITTER=false
# Put Twitter username here

14
app.js
View file

@ -44,6 +44,20 @@ async function init() {
if (process.env.NODE_ENV === "production") {
require("./utils/dbl.js");
}
// handle ctrl+c and pm2 stop
process.on("SIGINT", () => {
logger.log("info", "SIGINT detected, shutting down...");
client.editStatus("dnd", {
name: "Restarting/shutting down..."
});
for (const command of commands) {
handler.unload(command);
}
client.disconnect();
require("./utils/database.js").end();
process.exit(0);
});
}
// launch the bot

View file

@ -6,7 +6,6 @@ exports.run = async (message) => {
const image = await require("../utils/imagedetect.js")(message);
if (image === undefined) return `${message.author.mention}, you need to provide an image to make a Super Smash Bros. leak meme!`;
const buffer = await promisify(magick.leak)(image.path, image.type.toUpperCase(), image.delay ? (100 / image.delay.split("/")[0]) * image.delay.split("/")[1] : 0);
//const buffer = await gm(template).out("-background").out("white").out("-gravity").out("Center").out("(").out("-clone").out("0").out("(").out(image.path).out("-virtual-pixel").out("white").out("-resize").out("640x360!").rotate("white", 15).out(")").out("-geometry").out("+450-200").out("-composite").out(")").out("+swap").out("-composite").out("-alpha").out("remove").out("-alpha").out("off").bufferPromise(image.type, image.delay);
return {
file: buffer,
name: `leak.${image.type}`

View file

@ -12,6 +12,7 @@ const helpGenerator =
process.env.OUTPUT !== "" ? require("../utils/help.js") : null;
const twitter =
process.env.TWITTER === "true" ? require("../utils/twitter.js") : null;
const first = process.env.PMTWO === "true" ? process.env.NODE_APP_INSTANCE === "0" : true;
let run = false;
// run when ready
@ -65,7 +66,7 @@ module.exports = async () => {
}
}
if (!run) {
if (!run && first) {
const job = new cron.CronJob("0 0 * * 0", async () => {
logger.log("Deleting stale guild entries in database...");
const guildDB = await database.query("SELECT * FROM guilds");
@ -100,7 +101,7 @@ module.exports = async () => {
}
// generate docs
if (helpGenerator) await helpGenerator(process.env.OUTPUT);
if (helpGenerator && first) await helpGenerator(process.env.OUTPUT);
// set activity (a.k.a. the gamer code)
(async function activityChanger() {
@ -111,7 +112,7 @@ module.exports = async () => {
})();
// tweet stuff
if (twitter !== null && twitter.active === false) {
if (twitter !== null && twitter.active === false && first) {
const blocks = await twitter.client.blocks.ids();
const tweet = async () => {
const tweetContent = await misc.getTweet(twitter.tweets);
@ -158,6 +159,7 @@ module.exports = async () => {
}
}
if (process.env.PMTWO === "true") process.send("ready");
logger.log(`Successfully started ${client.user.username}#${client.user.discriminator} with ${client.users.size} users in ${client.guilds.size} servers.`);
run = true;
};