@oebot/core
Version:
能跑就行的 QQ 机器人框架,基于 oicq v2,改自KiviBot(R.I.P.)
42 lines (41 loc) • 1.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.disablePlugin = void 0;
const getPluginNameByPath_1 = require("./getPluginNameByPath");
const killPlugin_1 = require("./killPlugin");
const pluginError_1 = require("./pluginError");
const logger_1 = require("../logger");
const utils_1 = require("../../utils");
/** 通过插件路径禁用单个插件 */
async function disablePlugin(bot, oeConf, plugin, pluginPath) {
const error = (msg, ...args) => {
bot.logger.error(msg, ...args);
logger_1.OELogger.error(msg, ...args);
};
const debug = (msg, ...args) => {
bot.logger.debug(msg, ...args);
logger_1.OELogger.debug(msg, ...args);
};
logger_1.OELogger.debug('disablePlugin: ' + pluginPath);
const pluginName = (0, getPluginNameByPath_1.getPluginNameByPath)(pluginPath);
const pn = utils_1.colors.green(pluginName);
try {
// 调用插件挂载的禁用函数
await plugin.unmountOEBotClient(bot, [...oeConf.admins]);
// 删除 require 缓存
(0, killPlugin_1.killPlugin)(pluginPath);
debug(`插件 ${pn} 禁用成功`);
return true;
}
catch (e) {
if (e instanceof pluginError_1.OEPluginError) {
return e.log();
}
else {
const msg = (0, utils_1.stringifyError)(e);
error(`插件 ${pn} 禁用过程中发生错误: \n${msg}`);
return msg;
}
}
}
exports.disablePlugin = disablePlugin;