41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
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);
|