mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -4,7 +4,6 @@ import type { NapCatCore } from '@/core';
|
|||||||
|
|
||||||
export abstract class ConfigBase<T> {
|
export abstract class ConfigBase<T> {
|
||||||
abstract name: string;
|
abstract name: string;
|
||||||
pathName: string | null = null; // 本次读取的文件路径
|
|
||||||
coreContext: NapCatCore;
|
coreContext: NapCatCore;
|
||||||
configPath: string;
|
configPath: string;
|
||||||
configData: T = {} as T;
|
configData: T = {} as T;
|
||||||
@@ -31,23 +30,22 @@ export abstract class ConfigBase<T> {
|
|||||||
const logger = this.coreContext.context.logger;
|
const logger = this.coreContext.context.logger;
|
||||||
const configPath = this.getConfigPath(this.coreContext.selfInfo.uin);
|
const configPath = this.getConfigPath(this.coreContext.selfInfo.uin);
|
||||||
if (!fs.existsSync(configPath)) {
|
if (!fs.existsSync(configPath)) {
|
||||||
this.pathName = configPath; // 记录有效的设置文件
|
|
||||||
try {
|
try {
|
||||||
fs.writeFileSync(configPath, fs.readFileSync(this.getConfigPath(undefined), 'utf-8'));
|
fs.writeFileSync(configPath, fs.readFileSync(this.getConfigPath(undefined), 'utf-8'));
|
||||||
logger.log(`配置文件${configPath}创建成功!\n`);
|
logger.log(`[Core] [Config] 配置文件创建成功!\n`);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
logger.logError(`创建配置文件 ${configPath} 时发生错误:`, e.message);
|
logger.logError(`[Core] [Config] 创建配置文件时发生错误:`, e.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
this.configData = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
this.configData = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
||||||
logger.logDebug(`配置文件${configPath}已加载`, this.configData);
|
logger.logDebug(`[Core] [Config] 配置文件${configPath}加载`, this.configData);
|
||||||
return this.configData;
|
return this.configData;
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
if (e instanceof SyntaxError) {
|
if (e instanceof SyntaxError) {
|
||||||
logger.logError(`配置文件 ${configPath} 格式错误,请检查配置文件:`, e.message);
|
logger.logError(`[Core] [Config] 配置文件格式错误,请检查配置文件:`, e.message);
|
||||||
} else {
|
} else {
|
||||||
logger.logError(`读取配置文件 ${configPath} 时发生错误:`, e.message);
|
logger.logError(`[Core] [Config] 读取配置文件时发生错误:`, e.message);
|
||||||
}
|
}
|
||||||
return {} as T;
|
return {} as T;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user