mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
refactor: ordered onebot11.json keys
This commit is contained in:
parent
64a0037265
commit
df73e1e5a3
@ -11,6 +11,11 @@ export class ConfigBase<T>{
|
|||||||
constructor() {
|
constructor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected getKeys(): string[] | null {
|
||||||
|
// 决定 key 在json配置文件中的顺序
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
getConfigDir(){
|
getConfigDir(){
|
||||||
const configDir = path.resolve(__dirname, 'config');
|
const configDir = path.resolve(__dirname, 'config');
|
||||||
fs.mkdirSync(configDir, { recursive: true });
|
fs.mkdirSync(configDir, { recursive: true });
|
||||||
@ -24,7 +29,7 @@ export class ConfigBase<T>{
|
|||||||
const configPath = this.getConfigPath();
|
const configPath = this.getConfigPath();
|
||||||
if (!fs.existsSync(configPath)) {
|
if (!fs.existsSync(configPath)) {
|
||||||
try{
|
try{
|
||||||
fs.writeFileSync(configPath, JSON.stringify(this, null, 2));
|
fs.writeFileSync(configPath, JSON.stringify(this, this.getKeys(), 2));
|
||||||
log(`配置文件${configPath}已创建\n如果修改此文件后需要重启 NapCat 生效`);
|
log(`配置文件${configPath}已创建\n如果修改此文件后需要重启 NapCat 生效`);
|
||||||
}
|
}
|
||||||
catch (e: any) {
|
catch (e: any) {
|
||||||
@ -54,7 +59,7 @@ export class ConfigBase<T>{
|
|||||||
Object.assign(this, config);
|
Object.assign(this, config);
|
||||||
const configPath = this.getConfigPath();
|
const configPath = this.getConfigPath();
|
||||||
try {
|
try {
|
||||||
fs.writeFileSync(configPath, JSON.stringify(this, null, 2));
|
fs.writeFileSync(configPath, JSON.stringify(this, this.getKeys(), 2));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
logError(`保存配置文件 ${configPath} 时发生错误:`, e.message);
|
logError(`保存配置文件 ${configPath} 时发生错误:`, e.message);
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,10 @@ class Config extends ConfigBase<OB11Config> implements OB11Config {
|
|||||||
getConfigPath() {
|
getConfigPath() {
|
||||||
return path.join(this.getConfigDir(), `onebot11_${selfInfo.uin}.json`);
|
return path.join(this.getConfigDir(), `onebot11_${selfInfo.uin}.json`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected getKeys(): string[] {
|
||||||
|
return ['httpHost', 'enableHttp', 'httpPort', 'wsHost', 'enableWs', 'wsPort', 'enableWsReverse', 'wsReverseUrls', 'enableHttpPost', 'httpPostUrls', 'enableHttpHeart', 'httpSecret', 'messagePostFormat', 'reportSelfMessage', 'debug', 'enableLocalFile2Url', 'heartInterval', 'token', 'musicSignUrl'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ob11Config = new Config();
|
export const ob11Config = new Config();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user