2 Star 17 Fork 1

最好喝的小米粥 / 寸幼萱插件cunyx-plugin

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
index.js 2.02 KB
一键复制 编辑 原始数据 按行查看 历史
时先思 提交于 2023-12-29 23:12 . 新增若干api
import fs from 'node:fs';
import path from 'path';
import chalk from 'chalk';
logger.info(logger.red('~~~~~~~~~~~~~~~~~~~~'));
logger.info('开始寸幼萱插件初始化');
const folder1 = process.cwd()+'/plugins/cunyx-plugin/config';
const folder2 = process.cwd()+'/plugins/cunyx-plugin/def_config';
function getAllFiles(dirPath, files) {
const fileList = fs.readdirSync(dirPath);
files = files || [];
fileList.forEach((file) => {
const filePath = path.join(dirPath, file);
const stat = fs.statSync(filePath);
if (stat.isDirectory()) {
files = getAllFiles(filePath, files);
} else {
files.push(filePath);
}
});
return files;
}
function compareFolders(folder1, folder2) {
const files1 = getAllFiles(folder1);
const files2 = getAllFiles(folder2);
files2.forEach((file2) => {
if (files1.indexOf(file2) === -1) {
const dest = path.join(folder1, path.relative(folder2, file2));
if (!fs.existsSync(dest)) {
fs.copyFileSync(file2, dest);
logger.info(`检测到文件${path.basename(file2)}初始化,需再次重启机器人才可生效!\n请给机器人发送【#重启】指令完成本次初始化`);
} else {
logger.info(`配置文件${path.basename(file2)}已经存在,略过初始化~`);
}
}
});
}
compareFolders(folder1, folder2);
const files = fs.readdirSync('./plugins/cunyx-plugin/apps').filter(file => file.endsWith('.js'));
let ret = [];
files.forEach((file) => {
ret.push(import (`./apps/${file}`));
});
ret = await Promise.allSettled(ret);
let apps = {};
for (let i in files) {
let name = files[i].replace('.js', '');
if (ret[i].status != 'fulfilled') {
logger.error(`载入插件错误:${logger.red(name)}`);
logger.error(ret[i].reason);
continue
}
apps[name] = ret[i].value[Object.keys(ret[i].value)[0]];
}
logger.info('寸幼萱插件初始化完成');
logger.info(`~\t${chalk.green('寸幼萱交流群')}${' '}${chalk.underline('786034611')}\t~`);
logger.info(logger.red('~~~~~~~~~~~~~~~~~~~~'));
export { apps };
JavaScript
1
https://gitee.com/cunyx/cunyx-plugin.git
git@gitee.com:cunyx/cunyx-plugin.git
cunyx
cunyx-plugin
寸幼萱插件cunyx-plugin
master

搜索帮助