mirror of
https://github.com/Jerryplusy/crystelf-plugin.git
synced 2026-01-29 01:07:27 +00:00
🐛 fix(plugin): resolve issue causing incorrect message formatting in bot responses
This commit is contained in:
parent
27609a7c80
commit
a57c9b2c55
@ -141,7 +141,7 @@ class UserConfigManager {
|
||||
|
||||
/**
|
||||
* 清除用户配置缓存
|
||||
* @param {string} userId - 用户QQ号,如果不传则清除所有缓存
|
||||
* @param {string|null} userId - 用户QQ号,如果不传则清除所有缓存
|
||||
*/
|
||||
clearCache(userId) {
|
||||
if (userId) {
|
||||
|
||||
@ -22,14 +22,14 @@ async function init() {
|
||||
await fsp.mkdir(dataConfigPath, { recursive: true });
|
||||
logger.mark(`[crystelf-plugin] 配置目录创建成功: ${dataConfigPath}`);
|
||||
}
|
||||
|
||||
|
||||
// 确保默认配置目录存在
|
||||
try {
|
||||
await fsp.access(pluginConfigPath);
|
||||
} catch {
|
||||
logger.warn(`[crystelf-plugin] 默认配置目录不存在: ${pluginConfigPath}`);
|
||||
}
|
||||
|
||||
|
||||
// 处理主配置文件
|
||||
const pluginDefaultFile = path.join(pluginConfigPath, 'config.json');
|
||||
try {
|
||||
@ -39,7 +39,7 @@ async function init() {
|
||||
await fsp.copyFile(pluginDefaultFile, configFile);
|
||||
logger.mark(`[crystelf-plugin] 默认配置复制成功: ${configFile}`);
|
||||
} catch (copyError) {
|
||||
logger.warn(`[crystelf-plugin] 复制默认配置失败,创建空配置: ${copyError.message}`);
|
||||
logger.warn(`[crystelf-plugin] 复制默认配置失败,创建空配置: ${copyError}`);
|
||||
await fc.writeJSON(configFile, {});
|
||||
}
|
||||
}
|
||||
@ -47,9 +47,9 @@ async function init() {
|
||||
try {
|
||||
pluginFiles = (await fsp.readdir(pluginConfigPath)).filter((f) => f.endsWith('.json'));
|
||||
} catch (error) {
|
||||
logger.warn(`[crystelf-plugin] 读取默认配置目录失败: ${error.message}`);
|
||||
logger.warn(`[crystelf-plugin] 读取默认配置目录失败: ${error}`);
|
||||
}
|
||||
|
||||
|
||||
// 复制缺失的配置文件
|
||||
for (const file of pluginFiles) {
|
||||
const pluginFilePath = path.join(pluginConfigPath, file);
|
||||
@ -61,15 +61,15 @@ async function init() {
|
||||
await fsp.copyFile(pluginFilePath, dataFilePath);
|
||||
logger.mark(`[crystelf-plugin] 配置文件缺失,已复制: ${file}`);
|
||||
} catch (copyError) {
|
||||
logger.warn(`[crystelf-plugin] 复制配置文件失败 ${file}: ${copyError.message}`);
|
||||
logger.warn(`[crystelf-plugin] 复制配置文件失败 ${file}: ${copyError}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 读取所有配置文件
|
||||
const files = (await fsp.readdir(dataConfigPath)).filter((f) => f.endsWith('.json'));
|
||||
configCache = {};
|
||||
|
||||
|
||||
for (const file of files) {
|
||||
const filePath = path.join(dataConfigPath, file);
|
||||
const name = path.basename(file, '.json');
|
||||
@ -79,7 +79,7 @@ async function init() {
|
||||
try {
|
||||
await fsp.access(pluginFilePath);
|
||||
const pluginData = await fc.readJSON(pluginFilePath);
|
||||
|
||||
|
||||
if (Array.isArray(data) && Array.isArray(pluginData)) {
|
||||
// 合并数组类型配置
|
||||
const strSet = new Set(data.map((x) => JSON.stringify(x)));
|
||||
@ -94,20 +94,21 @@ async function init() {
|
||||
// 合并对象类型配置
|
||||
data = fc.mergeConfig(data, pluginData);
|
||||
}
|
||||
|
||||
|
||||
// 保存合并后的配置
|
||||
await fc.writeJSON(filePath, data);
|
||||
} catch (mergeError) {
|
||||
logger.error('[crystelf-plugin]合并配置失败..');
|
||||
logger.error(mergeError);
|
||||
// 忽略合并错误,使用现有数据
|
||||
}
|
||||
|
||||
|
||||
configCache[name] = data;
|
||||
} catch (e) {
|
||||
logger.warn(`[crystelf-plugin] 读取配置文件 ${file} 失败:`, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (configCache.debug) {
|
||||
logger.info('[crystelf-plugin] 配置模块初始化成功..');
|
||||
}
|
||||
@ -137,7 +138,7 @@ function watchConfigs() {
|
||||
const data = await fc.readJSON(filePath);
|
||||
const name = path.basename(file, '.json');
|
||||
configCache[name] = data;
|
||||
logger.info(`[crystelf-plugin] 配置热更新: ${file}`);
|
||||
logger.info(`[crystelf-plugin] 配置热更新: ${file}`);
|
||||
} catch (e) {
|
||||
logger.warn(`[crystelf-plugin] 热更新读取失败 ${file}:`, e);
|
||||
}
|
||||
@ -162,7 +163,7 @@ const configControl = {
|
||||
// 更新内存中的配置
|
||||
configCache[key] = value;
|
||||
const filePath = path.join(dataConfigPath, `${key}.json`);
|
||||
|
||||
|
||||
try {
|
||||
// 尝试访问文件,如果存在则直接写入
|
||||
await fsp.access(filePath);
|
||||
@ -176,7 +177,7 @@ const configControl = {
|
||||
await fc.writeJSON(filePath, value);
|
||||
logger.mark(`[crystelf-plugin] 创建新配置文件: ${filePath}`);
|
||||
} catch (writeError) {
|
||||
logger.error(`[crystelf-plugin] 创建配置文件失败: ${writeError.message}`);
|
||||
logger.error(`[crystelf-plugin] 创建配置文件失败: ${writeError}`);
|
||||
throw writeError;
|
||||
}
|
||||
}
|
||||
@ -189,17 +190,17 @@ const configControl = {
|
||||
async setMultiple(configs) {
|
||||
// 确保目录存在
|
||||
await fsp.mkdir(dataConfigPath, { recursive: true });
|
||||
|
||||
|
||||
for (const [key, value] of Object.entries(configs)) {
|
||||
try {
|
||||
// 更新内存中的配置
|
||||
configCache[key] = value;
|
||||
const filePath = path.join(dataConfigPath, `${key}.json`);
|
||||
|
||||
|
||||
// 写入配置文件
|
||||
await fc.writeJSON(filePath, value);
|
||||
} catch (error) {
|
||||
logger.error(`[crystelf-plugin] 设置配置失败 ${key}: ${error.message}`);
|
||||
logger.error(`[crystelf-plugin] 设置配置失败 ${key}: ${error}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@ -208,15 +209,15 @@ const configControl = {
|
||||
async save() {
|
||||
// 确保目录存在
|
||||
await fsp.mkdir(dataConfigPath, { recursive: true });
|
||||
|
||||
|
||||
for (const [key, value] of Object.entries(configCache)) {
|
||||
const filePath = path.join(dataConfigPath, `${key}.json`);
|
||||
|
||||
|
||||
try {
|
||||
// 直接写入配置文件
|
||||
await fc.writeJSON(filePath, value);
|
||||
} catch (error) {
|
||||
logger.error(`[crystelf-plugin] 保存配置文件失败 ${filePath}: ${error.message}`);
|
||||
logger.error(`[crystelf-plugin] 保存配置文件失败 ${filePath}: ${error}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
BIN
resources/img/logo.png
Normal file
BIN
resources/img/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 92 KiB |
Loading…
x
Reference in New Issue
Block a user