Merge pull request #147 from serfend/default-config

fix[config]support overwrite by user #145
This commit is contained in:
手瓜一十雪 2024-07-24 14:28:42 +08:00 committed by GitHub
commit 60796c26ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 4 deletions

View File

@ -73,8 +73,12 @@ export class ConfigBase<T> {
} }
} }
save(config: T) { save(config: T, overwrite: boolean = false) {
Object.assign(this, config); Object.assign(this, config);
if (overwrite) {
// 用户要求强制写入,则变更当前文件为目标文件
this.pathName = `${selfInfo.uin}`
}
const configPath = this.getConfigPath(this.pathName); const configPath = this.getConfigPath(this.pathName);
try { try {
fs.writeFileSync(configPath, JSON.stringify(this, this.getKeys(), 2)); fs.writeFileSync(configPath, JSON.stringify(this, this.getKeys(), 2));

View File

@ -15,6 +15,6 @@ export class SetConfigAction extends BaseAction<OB11Config, void> {
actionName = ActionName.SetConfig; actionName = ActionName.SetConfig;
protected async _handle(payload: OB11Config): Promise<void> { protected async _handle(payload: OB11Config): Promise<void> {
ob11Config.save(payload); ob11Config.save(payload, true);
} }
} }

View File

@ -385,7 +385,7 @@ export class NapCatOnebot11 {
// throw new Error('Invalid configuration object'); // throw new Error('Invalid configuration object');
// } // }
const OldConfig = JSON.parse(JSON.stringify(ob11Config)); //进行深拷贝 const OldConfig = JSON.parse(JSON.stringify(ob11Config)); //进行深拷贝
ob11Config.save(NewOb11);//保存新配置 ob11Config.save(NewOb11, true);//保存新配置
const isHttpChanged = !isEqual(NewOb11.http.enable, OldConfig.http.enable) || const isHttpChanged = !isEqual(NewOb11.http.enable, OldConfig.http.enable) ||
!isEqual(NewOb11.http.host, OldConfig.http.host) || !isEqual(NewOb11.http.host, OldConfig.http.host) ||
@ -525,7 +525,7 @@ export class NapCatOnebot11 {
groupRequestEvent.flag = flag; groupRequestEvent.flag = flag;
postOB11Event(groupRequestEvent); postOB11Event(groupRequestEvent);
} else if (notify.type == GroupNotifyTypes.INVITE_ME) { } else if (notify.type == GroupNotifyTypes.INVITE_ME) {
logDebug('收到邀请我加群通知'); logDebug(`收到邀请我加群通知:${notify}`);
const groupInviteEvent = new OB11GroupRequestEvent(); const groupInviteEvent = new OB11GroupRequestEvent();
groupInviteEvent.group_id = parseInt(notify.group.groupCode); groupInviteEvent.group_id = parseInt(notify.group.groupCode);
const user_id = (await NTQQUserApi.getUinByUid(notify.user2.uid)) || ''; const user_id = (await NTQQUserApi.getUinByUid(notify.user2.uid)) || '';