reload and restart ports

This commit is contained in:
Cynthia Foxwell 2021-06-01 12:59:59 -06:00
parent acd0e6e7ae
commit 872ec9e413

40
src/modules/bot.js Normal file
View file

@ -0,0 +1,40 @@
const Command = require("../lib/command.js");
const CATEGORY = "bot";
const logger = require("npmlog");
const reload = new Command("reload");
reload.ownerOnly = true;
reload.category = CATEGORY;
reload.helpText = "Reloads a module.";
reload.callback = function (msg, line) {
try {
require.resolve(`./${line}.js`);
} catch (err) {
if (err.code == "MODULE_NOT_FOUND") {
return "Module not found.";
} else {
return `:warning: An error occurred: \`\`\`\n${err}\`\`\``;
}
}
try {
logger.info("hf:modules", "Reloading module: '%s'", line);
delete require.cache[require.resolve(`./${line}.js`)];
require(`./${line}.js`);
return {reaction: "\uD83D\uDC4C"};
} catch (err) {
return `:warning: An error occurred: \`\`\`\n${err}\`\`\``;
}
};
hf.registerCommand(reload);
const restart = new Command("restart");
restart.ownerOnly = true;
restart.category = CATEGORY;
restart.helpText = "Restarts the bot.";
restart.callback = function () {
setTimeout(process.exit, 500);
return {reaction: "\uD83D\uDD04"};
};
hf.registerCommand(restart);