mirror of
https://github.com/Jerryplusy/crystelf-plugin.git
synced 2025-12-05 15:41:56 +00:00
📝 chore(index): implement handling for enabled/disabled plugins and log status during loading process (#12)
This commit is contained in:
parent
875ca65ed9
commit
f25440698a
@ -76,7 +76,6 @@ Bot.on('message.group', async (e) => {
|
||||
|
||||
async function index(e) {
|
||||
try {
|
||||
//logger.info('111')
|
||||
const config = await ConfigControl.get();
|
||||
const aiConfig = config?.ai;
|
||||
if (!config?.config?.ai) {
|
||||
|
||||
@ -13,7 +13,6 @@ export class FaceReply extends plugin {
|
||||
}
|
||||
|
||||
async accept(e) {
|
||||
if (!ConfigControl.get('config')?.faceReply) return;
|
||||
if (!e.message_id || e.message.length === 0) return;
|
||||
let face = [];
|
||||
e.message.forEach((m) => {
|
||||
|
||||
@ -117,9 +117,6 @@ export default class FanqiePlugin extends plugin {
|
||||
* 解析网页链接中的 book_id
|
||||
*/
|
||||
async handleFanqieLink(e) {
|
||||
if (!ConfigControl.get()?.config?.fanqie) {
|
||||
return;
|
||||
}
|
||||
const message = e.msg.trim();
|
||||
let bookId = null;
|
||||
|
||||
@ -140,9 +137,6 @@ export default class FanqiePlugin extends plugin {
|
||||
* 使用 #fq下载 命令下载
|
||||
*/
|
||||
async downloadByBookId(e) {
|
||||
if (!ConfigControl.get()?.config?.fanqie) {
|
||||
return;
|
||||
}
|
||||
const bookId = e.msg.replace(/^#?fq下载/, '').trim();
|
||||
return this.downloadFanqieBook(e, bookId);
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@ export class CrystelfMusic extends plugin {
|
||||
super({
|
||||
name: 'crystelf-music',
|
||||
dsc: '音乐点歌插件',
|
||||
event: 'message.group',
|
||||
event: 'message',
|
||||
priority: -1000,
|
||||
rule: [
|
||||
{
|
||||
|
||||
@ -16,5 +16,6 @@
|
||||
"faceReply": true,
|
||||
"ai": true,
|
||||
"blackWords": true,
|
||||
"music": true
|
||||
"music": true,
|
||||
"auth": true
|
||||
}
|
||||
|
||||
53
index.js
53
index.js
@ -23,22 +23,65 @@ if(appConfig.autoUpdate) {
|
||||
|
||||
const appPath = Path.apps;
|
||||
const jsFiles = await fc.readDirRecursive(appPath, 'js');
|
||||
const enabledApps = [];
|
||||
const disabledApps = [];
|
||||
|
||||
let ret = jsFiles.map((file) => {
|
||||
for (const file of jsFiles) {
|
||||
const name = file.replace('.js', '');
|
||||
const configKey = getConfigKey(name);
|
||||
if (appConfig[configKey] === false) {
|
||||
disabledApps.push(name);
|
||||
logger.info(`[crystelf-plugin] 插件 ${name} 已禁用,跳过加载`);
|
||||
} else {
|
||||
enabledApps.push(file);
|
||||
}
|
||||
}
|
||||
|
||||
if (disabledApps.length > 0) {
|
||||
logger.info(`[crystelf-plugin] 已跳过 ${disabledApps.length} 个禁用的插件: ${disabledApps.join(', ')}`);
|
||||
}
|
||||
|
||||
let ret = enabledApps.map((file) => {
|
||||
return import(`./apps/${file}`);
|
||||
});
|
||||
|
||||
ret = await Promise.allSettled(ret);
|
||||
|
||||
let apps = {};
|
||||
for (let i in jsFiles) {
|
||||
let name = jsFiles[i].replace('.js', '');
|
||||
|
||||
for (let i in enabledApps) {
|
||||
let name = enabledApps[i].replace('.js', '');
|
||||
if (ret[i].status !== 'fulfilled') {
|
||||
logger.error(name, ret[i].reason);
|
||||
logger.error(`[crystelf-plugin] 插件 ${name} 加载失败:`, ret[i].reason);
|
||||
continue;
|
||||
}
|
||||
apps[name] = ret[i].value[Object.keys(ret[i].value)[0]];
|
||||
}
|
||||
logger.info(`[crystelf-plugin] 成功加载 ${Object.keys(apps).length} 个插件`);
|
||||
|
||||
export { apps };
|
||||
|
||||
/**
|
||||
* 将插件文件名映射到配置键名
|
||||
* @param {string} fileName
|
||||
* @returns {string}
|
||||
*/
|
||||
function getConfigKey(fileName) {
|
||||
const keyMap = {
|
||||
'60s': '60s',
|
||||
'ai': 'ai',
|
||||
'auth': 'auth',
|
||||
'auth-set': 'auth',
|
||||
'face-reply': 'faceReply',
|
||||
'face-reply-message': 'faceReply',
|
||||
'fanqie': 'fanqie',
|
||||
'help': 'help',
|
||||
'music': 'music',
|
||||
'poke': 'poke',
|
||||
'rssPush': 'rss',
|
||||
'welcome': 'welcome',
|
||||
'welcome-set': 'welcome',
|
||||
'zwa': 'zwa'
|
||||
};
|
||||
|
||||
return keyMap[fileName] || fileName;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user