fix[config]support overwrite by user

This commit is contained in:
汉广 2024-07-24 14:25:58 +08:00
parent 03bc844ad0
commit 28927f950d
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);
if (overwrite) {
// 用户要求强制写入,则变更当前文件为目标文件
this.pathName = `${selfInfo.uin}`
}
const configPath = this.getConfigPath(this.pathName);
try {
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;
protected async _handle(payload: OB11Config): Promise<void> {
ob11Config.save(payload);
ob11Config.save(payload, true);
}
}

View File

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