From 6a3713e86c0fdc5f28b6d25b43f879537c6657bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Wed, 27 Nov 2024 12:35:10 +0800 Subject: [PATCH] fix: webui reload --- src/onebot/index.ts | 196 ++++++++++++++++++++++---------------------- 1 file changed, 98 insertions(+), 98 deletions(-) diff --git a/src/onebot/index.ts b/src/onebot/index.ts index 9e252d98..4964da34 100644 --- a/src/onebot/index.ts +++ b/src/onebot/index.ts @@ -195,6 +195,16 @@ export class NapCatOneBot11Adapter { nowConfig: NetworkConfigAdapter[], adapterClass: new (...args: any[]) => IOB11NetworkAdapter ): Promise { + // 比较旧的在新的找不到的回收 + for (const adapterConfig of prevConfig) { + const existingAdapter = nowConfig.find((e) => e.name === adapterConfig.name); + if (!existingAdapter) { + const existingAdapter = this.networkManager.findSomeAdapter(adapterConfig.name); + if (existingAdapter) { + await this.networkManager.closeSomeAdaterWhenOpen([existingAdapter]); + } + } + } // 通知新配置重载 删除关闭的 加入新开的 for (const adapterConfig of nowConfig) { const existingAdapter = this.networkManager.findSomeAdapter(adapterConfig.name); @@ -203,21 +213,11 @@ export class NapCatOneBot11Adapter { if (networkChange === OB11NetworkReloadType.NetWorkClose) { await this.networkManager.closeSomeAdaterWhenOpen([existingAdapter]); } - } else { + } else if(adapterConfig.enable) { const newAdapter = new adapterClass(adapterConfig.name, adapterConfig, this.core, this.actions); await this.networkManager.registerAdapterAndOpen(newAdapter); } } - // 比较旧的找不到的回收 - for (const adapterConfig of prevConfig) { - const existingAdapter = nowConfig.find((e) => e.name === adapterConfig.name); - if (!existingAdapter) { - const existingAdapter = this.networkManager.findSomeAdapter(adapterConfig.name); - if (existingAdapter) { - await this.networkManager.closeSomeAdaterWhenOpen([existingAdapter]); - } - } - } } private initMsgListener() { @@ -406,104 +406,104 @@ export class NapCatOneBot11Adapter { this.core.apis.GroupApi.getGroup(notify.group.groupCode) ); } - } else - // if ( - // notify.type == GroupNotifyMsgType.MEMBER_LEAVE_NOTIFY_ADMIN || - // notify.type == GroupNotifyMsgType.KICK_MEMBER_NOTIFY_ADMIN - // ) { - // this.context.logger.logDebug('有成员退出通知', notify); - // const member1Uin = await this.core.apis.UserApi.getUinByUidV2(notify.user1.uid); - // let operatorId = member1Uin; - // let subType: GroupDecreaseSubType = 'leave'; - // if (notify.user2.uid) { - // // 是被踢的 - // const member2Uin = await this.core.apis.UserApi.getUinByUidV2(notify.user2.uid); - // if (member2Uin) { - // operatorId = member2Uin; - // } - // subType = 'kick'; - // } - // const groupDecreaseEvent = new OB11GroupDecreaseEvent( - // this.core, - // parseInt(notify.group.groupCode), - // parseInt(member1Uin), - // parseInt(operatorId), - // subType - // ); - // this.networkManager - // .emitEvent(groupDecreaseEvent) - // .catch((e) => - // this.context.logger.logError.bind(this.context.logger)('处理群成员退出失败', e) - // ); - // // notify.status == 1 表示未处理 2表示处理完成 - // } else - if ( - [GroupNotifyMsgType.REQUEST_JOIN_NEED_ADMINI_STRATOR_PASS].includes(notify.type) && - notify.status == GroupNotifyMsgStatus.KUNHANDLE - ) { - this.context.logger.logDebug('有加群请求'); - try { - let requestUin = await this.core.apis.UserApi.getUinByUidV2(notify.user1.uid); - if (isNaN(parseInt(requestUin))) { - requestUin = (await this.core.apis.UserApi.getUserDetailInfo(notify.user1.uid)).uin; + } else + // if ( + // notify.type == GroupNotifyMsgType.MEMBER_LEAVE_NOTIFY_ADMIN || + // notify.type == GroupNotifyMsgType.KICK_MEMBER_NOTIFY_ADMIN + // ) { + // this.context.logger.logDebug('有成员退出通知', notify); + // const member1Uin = await this.core.apis.UserApi.getUinByUidV2(notify.user1.uid); + // let operatorId = member1Uin; + // let subType: GroupDecreaseSubType = 'leave'; + // if (notify.user2.uid) { + // // 是被踢的 + // const member2Uin = await this.core.apis.UserApi.getUinByUidV2(notify.user2.uid); + // if (member2Uin) { + // operatorId = member2Uin; + // } + // subType = 'kick'; + // } + // const groupDecreaseEvent = new OB11GroupDecreaseEvent( + // this.core, + // parseInt(notify.group.groupCode), + // parseInt(member1Uin), + // parseInt(operatorId), + // subType + // ); + // this.networkManager + // .emitEvent(groupDecreaseEvent) + // .catch((e) => + // this.context.logger.logError.bind(this.context.logger)('处理群成员退出失败', e) + // ); + // // notify.status == 1 表示未处理 2表示处理完成 + // } else + if ( + [GroupNotifyMsgType.REQUEST_JOIN_NEED_ADMINI_STRATOR_PASS].includes(notify.type) && + notify.status == GroupNotifyMsgStatus.KUNHANDLE + ) { + this.context.logger.logDebug('有加群请求'); + try { + let requestUin = await this.core.apis.UserApi.getUinByUidV2(notify.user1.uid); + if (isNaN(parseInt(requestUin))) { + requestUin = (await this.core.apis.UserApi.getUserDetailInfo(notify.user1.uid)).uin; + } + const groupRequestEvent = new OB11GroupRequestEvent( + this.core, + parseInt(notify.group.groupCode), + parseInt(requestUin), + 'add', + notify.postscript, + flag + ); + this.networkManager + .emitEvent(groupRequestEvent) + .catch((e) => + this.context.logger.logError.bind(this.context.logger)('处理加群请求失败', e) + ); + } catch (e) { + this.context.logger.logError.bind(this.context.logger)( + '获取加群人QQ号失败 Uid:', + notify.user1.uid, + e + ); } - const groupRequestEvent = new OB11GroupRequestEvent( + } else if ( + notify.type == GroupNotifyMsgType.INVITED_BY_MEMBER && + notify.status == GroupNotifyMsgStatus.KUNHANDLE + ) { + this.context.logger.logDebug(`收到邀请我加群通知:${notify}`); + const groupInviteEvent = new OB11GroupRequestEvent( this.core, parseInt(notify.group.groupCode), - parseInt(requestUin), + parseInt(await this.core.apis.UserApi.getUinByUidV2(notify.user2.uid)), + 'invite', + notify.postscript, + flag + ); + this.networkManager + .emitEvent(groupInviteEvent) + .catch((e) => + this.context.logger.logError.bind(this.context.logger)('处理邀请本人加群失败', e) + ); + } else if ( + notify.type == GroupNotifyMsgType.INVITED_NEED_ADMINI_STRATOR_PASS && + notify.status == GroupNotifyMsgStatus.KUNHANDLE + ) { + this.context.logger.logDebug(`收到群员邀请加群通知:${notify}`); + const groupInviteEvent = new OB11GroupRequestEvent( + this.core, + parseInt(notify.group.groupCode), + parseInt(await this.core.apis.UserApi.getUinByUidV2(notify.user1.uid)), 'add', notify.postscript, flag ); this.networkManager - .emitEvent(groupRequestEvent) + .emitEvent(groupInviteEvent) .catch((e) => - this.context.logger.logError.bind(this.context.logger)('处理加群请求失败', e) + this.context.logger.logError.bind(this.context.logger)('处理邀请本人加群失败', e) ); - } catch (e) { - this.context.logger.logError.bind(this.context.logger)( - '获取加群人QQ号失败 Uid:', - notify.user1.uid, - e - ); } - } else if ( - notify.type == GroupNotifyMsgType.INVITED_BY_MEMBER && - notify.status == GroupNotifyMsgStatus.KUNHANDLE - ) { - this.context.logger.logDebug(`收到邀请我加群通知:${notify}`); - const groupInviteEvent = new OB11GroupRequestEvent( - this.core, - parseInt(notify.group.groupCode), - parseInt(await this.core.apis.UserApi.getUinByUidV2(notify.user2.uid)), - 'invite', - notify.postscript, - flag - ); - this.networkManager - .emitEvent(groupInviteEvent) - .catch((e) => - this.context.logger.logError.bind(this.context.logger)('处理邀请本人加群失败', e) - ); - } else if ( - notify.type == GroupNotifyMsgType.INVITED_NEED_ADMINI_STRATOR_PASS && - notify.status == GroupNotifyMsgStatus.KUNHANDLE - ) { - this.context.logger.logDebug(`收到群员邀请加群通知:${notify}`); - const groupInviteEvent = new OB11GroupRequestEvent( - this.core, - parseInt(notify.group.groupCode), - parseInt(await this.core.apis.UserApi.getUinByUidV2(notify.user1.uid)), - 'add', - notify.postscript, - flag - ); - this.networkManager - .emitEvent(groupInviteEvent) - .catch((e) => - this.context.logger.logError.bind(this.context.logger)('处理邀请本人加群失败', e) - ); - } } } };