diff --git a/napcat.webui/index.html b/napcat.webui/index.html index 1f07d8e5..de5376cf 100644 --- a/napcat.webui/index.html +++ b/napcat.webui/index.html @@ -1,13 +1,13 @@ - + - + NapCat WebUI - - -
- - + + +
+ + diff --git a/napcat.webui/package.json b/napcat.webui/package.json index 5b0739d4..f6b8c6e7 100644 --- a/napcat.webui/package.json +++ b/napcat.webui/package.json @@ -14,7 +14,7 @@ "qrcode": "^1.5.4", "tdesign-icons-vue-next": "^0.3.3", "tdesign-vue-next": "^1.10.3", - "vue": "^3.5.12", + "vue": "^3.5.13", "vue-router": "^4.4.5" }, "devDependencies": { diff --git a/napcat.webui/public/logo_webui.png b/napcat.webui/public/logo_webui.png new file mode 100644 index 00000000..03aa7f5b Binary files /dev/null and b/napcat.webui/public/logo_webui.png differ diff --git a/napcat.webui/src/App.vue b/napcat.webui/src/App.vue index e5fe963f..d26b9165 100644 --- a/napcat.webui/src/App.vue +++ b/napcat.webui/src/App.vue @@ -1,7 +1,112 @@ - + + diff --git a/napcat.webui/src/assets/logo_webui.png b/napcat.webui/src/assets/logo_webui.png new file mode 100644 index 00000000..03aa7f5b Binary files /dev/null and b/napcat.webui/src/assets/logo_webui.png differ diff --git a/napcat.webui/src/backend/shell.ts b/napcat.webui/src/backend/shell.ts index 0819e0b8..16c69eb1 100644 --- a/napcat.webui/src/backend/shell.ts +++ b/napcat.webui/src/backend/shell.ts @@ -74,7 +74,7 @@ export class QQLoginManager { } return false; } - public async checkQQLoginStatusWithQrcode(): Promise<{ qrcodeurl: string, isLogin: string } | undefined> { + public async checkQQLoginStatusWithQrcode(): Promise<{ qrcodeurl: string; isLogin: string } | undefined> { try { const QQLoginResponse = await fetch(`${this.apiPrefix}/QQLogin/CheckLoginStatus`, { method: 'POST', diff --git a/napcat.webui/src/components/Dashboard.vue b/napcat.webui/src/components/Dashboard.vue index 7d8fcb13..8bd8a031 100644 --- a/napcat.webui/src/components/Dashboard.vue +++ b/napcat.webui/src/components/Dashboard.vue @@ -1,16 +1,18 @@ diff --git a/napcat.webui/src/components/WebUiLogin.vue b/napcat.webui/src/components/WebUiLogin.vue index 956f3d60..091ed144 100644 --- a/napcat.webui/src/components/WebUiLogin.vue +++ b/napcat.webui/src/components/WebUiLogin.vue @@ -1,20 +1,22 @@ diff --git a/napcat.webui/src/components/webui/Nav.vue b/napcat.webui/src/components/webui/Nav.vue index ddf489bd..7eea7366 100644 --- a/napcat.webui/src/components/webui/Nav.vue +++ b/napcat.webui/src/components/webui/Nav.vue @@ -1,16 +1,31 @@ + diff --git a/napcat.webui/src/pages/OtherConfig.vue b/napcat.webui/src/pages/OtherConfig.vue index 5fff6ff9..76bf7c84 100644 --- a/napcat.webui/src/pages/OtherConfig.vue +++ b/napcat.webui/src/pages/OtherConfig.vue @@ -1,25 +1,24 @@ diff --git a/napcat.webui/src/pages/network/EmptyStateComponent.vue b/napcat.webui/src/pages/network/EmptyStateComponent.vue deleted file mode 100644 index 29fb8e9b..00000000 --- a/napcat.webui/src/pages/network/EmptyStateComponent.vue +++ /dev/null @@ -1,22 +0,0 @@ - - - - - diff --git a/napcat.webui/src/pages/network/HttpClientComponent.vue b/napcat.webui/src/pages/network/HttpClientComponent.vue index 71cd8d14..901baa44 100644 --- a/napcat.webui/src/pages/network/HttpClientComponent.vue +++ b/napcat.webui/src/pages/network/HttpClientComponent.vue @@ -1,28 +1,25 @@ @@ -49,20 +46,4 @@ watch( ); - + diff --git a/napcat.webui/src/pages/network/HttpServerComponent.vue b/napcat.webui/src/pages/network/HttpServerComponent.vue index 5e61b253..9988bcc0 100644 --- a/napcat.webui/src/pages/network/HttpServerComponent.vue +++ b/napcat.webui/src/pages/network/HttpServerComponent.vue @@ -1,34 +1,31 @@ @@ -55,20 +52,4 @@ watch( ); - + diff --git a/napcat.webui/src/pages/network/WebsocketClientComponent.vue b/napcat.webui/src/pages/network/WebsocketClientComponent.vue index d7c2f657..7ea25fb7 100644 --- a/napcat.webui/src/pages/network/WebsocketClientComponent.vue +++ b/napcat.webui/src/pages/network/WebsocketClientComponent.vue @@ -1,31 +1,28 @@ @@ -52,20 +49,4 @@ watch( ); - + diff --git a/napcat.webui/src/pages/network/WebsocketServerComponent.vue b/napcat.webui/src/pages/network/WebsocketServerComponent.vue index 88830ffa..4e95c9ca 100644 --- a/napcat.webui/src/pages/network/WebsocketServerComponent.vue +++ b/napcat.webui/src/pages/network/WebsocketServerComponent.vue @@ -1,37 +1,34 @@ @@ -58,20 +55,4 @@ watch( ); - + diff --git a/napcat.webui/src/ts/event-bus.ts b/napcat.webui/src/ts/event-bus.ts new file mode 100644 index 00000000..40972579 --- /dev/null +++ b/napcat.webui/src/ts/event-bus.ts @@ -0,0 +1,3 @@ +import mitt from 'mitt'; +const emitter = mitt(); +export default emitter; diff --git a/src/common/file.ts b/src/common/file.ts index 5fa19f05..487325ae 100644 --- a/src/common/file.ts +++ b/src/common/file.ts @@ -182,7 +182,6 @@ export enum FileUriType { } export async function checkUriType(Uri: string) { - const LocalFileRet = await solveProblem((uri: string) => { if (fs.existsSync(uri)) { return { Uri: uri, Type: FileUriType.Local }; @@ -200,14 +199,7 @@ export async function checkUriType(Uri: string) { return { Uri: uri, Type: FileUriType.Base64 }; } if (uri.startsWith('file://')) { - let filePath: string; - const pathname = decodeURIComponent(new URL(uri).pathname + new URL(uri).hash); - if (process.platform === 'win32') { - filePath = pathname.slice(1); - } else { - filePath = pathname; - } - + let filePath: string = uri.slice(7); return { Uri: filePath, Type: FileUriType.Local }; } if (uri.startsWith('data:')) { @@ -222,14 +214,16 @@ export async function checkUriType(Uri: string) { export async function uri2local(dir: string, uri: string, filename: string | undefined = undefined): Promise { const { Uri: HandledUri, Type: UriType } = await checkUriType(uri); + //解析失败 const tempName = randomUUID(); if (!filename) filename = randomUUID(); - //解析Http和Https协议 + //解析Http和Https协议 if (UriType == FileUriType.Unknown) { return { success: false, errMsg: `未知文件类型, uri= ${uri}`, fileName: '', ext: '', path: '' }; } + //解析File协议和本地文件 if (UriType == FileUriType.Local) { const fileExt = path.extname(HandledUri); @@ -241,8 +235,8 @@ export async function uri2local(dir: string, uri: string, filename: string | und fs.copyFileSync(HandledUri, filePath); return { success: true, errMsg: '', fileName: filename, ext: fileExt, path: filePath }; } + //接下来都要有文件名 - if (UriType == FileUriType.Remote) { const pathInfo = path.parse(decodeURIComponent(new URL(HandledUri).pathname)); if (pathInfo.name) { @@ -260,6 +254,7 @@ export async function uri2local(dir: string, uri: string, filename: string | und fs.writeFileSync(filePath, buffer, { flag: 'wx' }); return { success: true, errMsg: '', fileName: filename, ext: fileExt, path: filePath }; } + //解析Base64 if (UriType == FileUriType.Base64) { const base64 = HandledUri.replace(/^base64:\/\//, ''); diff --git a/src/core/packet/transformer/proto/message/message.ts b/src/core/packet/transformer/proto/message/message.ts index c5916e86..1cb6ecfe 100644 --- a/src/core/packet/transformer/proto/message/message.ts +++ b/src/core/packet/transformer/proto/message/message.ts @@ -54,6 +54,16 @@ export const PushMsg = { generalFlag: ProtoField(9, ScalarType.INT32, true), }; +export const GroupChange = { + groupUin: ProtoField(1, ScalarType.UINT32), + flag: ProtoField(2, ScalarType.UINT32), + memberUid: ProtoField(3, ScalarType.STRING, true), + decreaseType: ProtoField(4, ScalarType.UINT32), + operatorUid: ProtoField(5, ScalarType.STRING, true), + increaseType: ProtoField(6, ScalarType.UINT32), + field7: ProtoField(7, ScalarType.BYTES, true), +} + export const PushMsgBody = { responseHead: ProtoField(1, () => ResponseHead), contentHead: ProtoField(2, () => ContentHead), diff --git a/src/onebot/api/group.ts b/src/onebot/api/group.ts index 5a189a78..faa8ee02 100644 --- a/src/onebot/api/group.ts +++ b/src/onebot/api/group.ts @@ -23,7 +23,6 @@ import { OB11GroupCardEvent } from '@/onebot/event/notice/OB11GroupCardEvent'; import { OB11GroupPokeEvent } from '@/onebot/event/notice/OB11PokeEvent'; import { OB11GroupEssenceEvent } from '@/onebot/event/notice/OB11GroupEssenceEvent'; import { OB11GroupTitleEvent } from '@/onebot/event/notice/OB11GroupTitleEvent'; -import { OB11EmitEventContent } from '../network'; import { OB11GroupUploadNoticeEvent } from '../event/notice/OB11GroupUploadNoticeEvent'; import { pathToFileURL } from 'node:url'; import { FileNapCatOneBotUUID } from '@/common/helper'; @@ -93,40 +92,40 @@ export class OneBotGroupApi { return undefined; } - async parseGroupMemberIncreaseEvent(GroupCode: string, grayTipElement: GrayTipElement) { - const groupElement = grayTipElement?.groupElement; - if (!groupElement) return undefined; - const member = await this.core.apis.UserApi.getUserDetailInfo(groupElement.memberUid); - const memberUin = member?.uin; - const adminMember = await this.core.apis.GroupApi.getGroupMember(GroupCode, groupElement.adminUid); - if (memberUin) { - const operatorUin = adminMember?.uin ?? memberUin; - return new OB11GroupIncreaseEvent( - this.core, - parseInt(GroupCode), - parseInt(memberUin), - parseInt(operatorUin), - ); - } else { - return undefined; - } - } + // async parseGroupMemberIncreaseEvent(GroupCode: string, grayTipElement: GrayTipElement) { + // const groupElement = grayTipElement?.groupElement; + // if (!groupElement) return undefined; + // const member = await this.core.apis.UserApi.getUserDetailInfo(groupElement.memberUid); + // const memberUin = member?.uin; + // const adminMember = await this.core.apis.GroupApi.getGroupMember(GroupCode, groupElement.adminUid); + // if (memberUin) { + // const operatorUin = adminMember?.uin ?? memberUin; + // return new OB11GroupIncreaseEvent( + // this.core, + // parseInt(GroupCode), + // parseInt(memberUin), + // parseInt(operatorUin), + // ); + // } else { + // return undefined; + // } + // } - async parseGroupKickEvent(GroupCode: string, grayTipElement: GrayTipElement) { - const groupElement = grayTipElement?.groupElement; - if (!groupElement) return undefined; - const adminUin = (await this.core.apis.GroupApi.getGroupMember(GroupCode, groupElement.adminUid))?.uin ?? (await this.core.apis.UserApi.getUidByUinV2(groupElement.adminUid)); - if (adminUin) { - return new OB11GroupDecreaseEvent( - this.core, - parseInt(GroupCode), - parseInt(this.core.selfInfo.uin), - parseInt(adminUin), - 'kick_me', - ); - } - return undefined; - } + // async parseGroupKickEvent(GroupCode: string, grayTipElement: GrayTipElement) { + // const groupElement = grayTipElement?.groupElement; + // if (!groupElement) return undefined; + // const adminUin = (await this.core.apis.GroupApi.getGroupMember(GroupCode, groupElement.adminUid))?.uin ?? (await this.core.apis.UserApi.getUidByUinV2(groupElement.adminUid)); + // if (adminUin) { + // return new OB11GroupDecreaseEvent( + // this.core, + // parseInt(GroupCode), + // parseInt(this.core.selfInfo.uin), + // parseInt(adminUin), + // 'kick_me', + // ); + // } + // return undefined; + // } async parseGroupEmojiLikeEventByGrayTip( groupCode: string, @@ -188,30 +187,30 @@ export class OneBotGroupApi { return undefined; } - async parseGroupElement(msg: RawMessage, groupElement: TipGroupElement, elementWrapper: GrayTipElement) { - if (groupElement.type == TipGroupElementType.KMEMBERADD) { - const MemberIncreaseEvent = await this.obContext.apis.GroupApi.parseGroupMemberIncreaseEvent(msg.peerUid, elementWrapper); - if (MemberIncreaseEvent) return MemberIncreaseEvent; - } else if (groupElement.type === TipGroupElementType.KSHUTUP) { - const BanEvent = await this.obContext.apis.GroupApi.parseGroupBanEvent(msg.peerUid, elementWrapper); - if (BanEvent) return BanEvent; - } else if (groupElement.type == TipGroupElementType.KQUITTE) { - this.core.apis.GroupApi.quitGroup(msg.peerUid).then(); - try { - const KickEvent = await this.obContext.apis.GroupApi.parseGroupKickEvent(msg.peerUid, elementWrapper); - if (KickEvent) return KickEvent; - } catch (e) { - return new OB11GroupDecreaseEvent( - this.core, - parseInt(msg.peerUid), - parseInt(this.core.selfInfo.uin), - 0, - 'leave', - ); - } - } - return undefined; - } + // async parseGroupElement(msg: RawMessage, groupElement: TipGroupElement, elementWrapper: GrayTipElement) { + // if (groupElement.type == TipGroupElementType.KMEMBERADD) { + // const MemberIncreaseEvent = await this.obContext.apis.GroupApi.parseGroupMemberIncreaseEvent(msg.peerUid, elementWrapper); + // if (MemberIncreaseEvent) return MemberIncreaseEvent; + // } else if (groupElement.type === TipGroupElementType.KSHUTUP) { + // const BanEvent = await this.obContext.apis.GroupApi.parseGroupBanEvent(msg.peerUid, elementWrapper); + // if (BanEvent) return BanEvent; + // } else if (groupElement.type == TipGroupElementType.KQUITTE) { + // this.core.apis.GroupApi.quitGroup(msg.peerUid).then(); + // try { + // const KickEvent = await this.obContext.apis.GroupApi.parseGroupKickEvent(msg.peerUid, elementWrapper); + // if (KickEvent) return KickEvent; + // } catch (e) { + // return new OB11GroupDecreaseEvent( + // this.core, + // parseInt(msg.peerUid), + // parseInt(this.core.selfInfo.uin), + // 0, + // 'leave', + // ); + // } + // } + // return undefined; + // } async parsePaiYiPai(msg: RawMessage, jsonStr: string) { const json = JSON.parse(jsonStr); @@ -298,8 +297,8 @@ export class OneBotGroupApi { async parseGrayTipElement(msg: RawMessage, grayTipElement: GrayTipElement) { if (grayTipElement.subElementType === NTGrayTipElementSubTypeV2.GRAYTIP_ELEMENT_SUBTYPE_GROUP) { - // 解析群组事件 - return await this.parseGroupElement(msg, grayTipElement.groupElement, grayTipElement); + // 解析群组事件 由sysmsg解析 + // return await this.parseGroupElement(msg, grayTipElement.groupElement, grayTipElement); } else if (grayTipElement.subElementType === NTGrayTipElementSubTypeV2.GRAYTIP_ELEMENT_SUBTYPE_XMLMSG) { // 筛选出表情回应 事件 diff --git a/src/onebot/api/msg.ts b/src/onebot/api/msg.ts index c987d400..610c7462 100644 --- a/src/onebot/api/msg.ts +++ b/src/onebot/api/msg.ts @@ -32,6 +32,10 @@ import { OB11FriendAddNoticeEvent } from '@/onebot/event/notice/OB11FriendAddNot // import { decodeSysMessage } from '@/core/packet/proto/old/ProfileLike'; import { ForwardMsgBuilder } from "@/common/forward-msg-builder"; import { decodeSysMessage } from "@/core/helper/adaptDecoder"; +import { GroupChange, PushMsgBody } from "@/core/packet/transformer/proto"; +import { NapProtoMsg } from '@napneko/nap-proto-core'; +import { OB11GroupIncreaseEvent } from '../event/notice/OB11GroupIncreaseEvent'; +import { OB11GroupDecreaseEvent, GroupDecreaseSubType } from '../event/notice/OB11GroupDecreaseEvent'; type RawToOb11Converters = { [Key in keyof MessageElement as Key extends `${string}Element` ? Key : never]: ( @@ -953,16 +957,51 @@ export class OneBotMsgApi { return { path, fileName: inputdata.name ?? fileName }; } + groupChangDecreseType2String(type: number): GroupDecreaseSubType { + switch (type) { + case 130: + return 'kick'; + case 131: + return 'leave'; + case 3: + return 'kick_me'; + default: + return 'kick'; + } + } async parseSysMessage(msg: number[]) { - const sysMsg = decodeSysMessage(Uint8Array.from(msg)); - if (sysMsg.msgSpec.length === 0) { - return; - } - const { msgType, subType, subSubType } = sysMsg.msgSpec[0]; - if (msgType === 528 && subType === 39 && subSubType === 39) { - if (!sysMsg.bodyWrapper) return; - return await this.obContext.apis.UserApi.parseLikeEvent(sysMsg.bodyWrapper.wrappedBody); + // Todo Refactor + // const sysMsg = decodeSysMessage(Uint8Array.from(msg)); + // if (sysMsg.msgSpec.length === 0) { + // return; + // } + // const { msgType, subType, subSubType } = sysMsg.msgSpec[0]; + // if (msgType === 528 && subType === 39 && subSubType === 39) { + // if (!sysMsg.bodyWrapper) return; + // return await this.obContext.apis.UserApi.parseLikeEvent(sysMsg.bodyWrapper.wrappedBody); + // } + let SysMessage = new NapProtoMsg(PushMsgBody).decode(Uint8Array.from(msg)); + if (SysMessage.contentHead.type == 33 && SysMessage.body?.msgContent) { + const groupChange = new NapProtoMsg(GroupChange).decode(SysMessage.body.msgContent); + console.log(JSON.stringify(groupChange)); + return new OB11GroupIncreaseEvent( + this.core, + groupChange.groupUin, + groupChange.memberUid ? +await this.core.apis.UserApi.getUinByUidV2(groupChange.memberUid) : 0, + groupChange.operatorUid ? +await this.core.apis.UserApi.getUinByUidV2(groupChange.operatorUid) : 0, + groupChange.decreaseType == 131 ? 'invite' : 'approve', + ); + } else if (SysMessage.contentHead.type == 34 && SysMessage.body?.msgContent) { + const groupChange = new NapProtoMsg(GroupChange).decode(SysMessage.body.msgContent); + // console.log(JSON.stringify(groupChange),JSON.stringify(SysMessage)); + return new OB11GroupDecreaseEvent( + this.core, + groupChange.groupUin, + +this.core.selfInfo.uin, + groupChange.operatorUid ? +await this.core.apis.UserApi.getUinByUidV2(groupChange.operatorUid) : 0, + this.groupChangDecreseType2String(groupChange.decreaseType), + ); } /* if (msgType === 732 && subType === 16 && subSubType === 16) { diff --git a/src/onebot/index.ts b/src/onebot/index.ts index a8858bc6..4964da34 100644 --- a/src/onebot/index.ts +++ b/src/onebot/index.ts @@ -42,7 +42,7 @@ import { MessageUnique } from '@/common/message-unique'; import { proxiedListenerOf } from '@/common/proxy-handler'; import { OB11FriendRequestEvent } from '@/onebot/event/request/OB11FriendRequest'; import { OB11GroupAdminNoticeEvent } from '@/onebot/event/notice/OB11GroupAdminNoticeEvent'; -import { GroupDecreaseSubType, OB11GroupDecreaseEvent } from '@/onebot/event/notice/OB11GroupDecreaseEvent'; +// import { GroupDecreaseSubType, OB11GroupDecreaseEvent } from '@/onebot/event/notice/OB11GroupDecreaseEvent'; import { OB11GroupRequestEvent } from '@/onebot/event/request/OB11GroupRequest'; import { OB11FriendRecallNoticeEvent } from '@/onebot/event/notice/OB11FriendRecallNoticeEvent'; import { OB11GroupRecallNoticeEvent } from '@/onebot/event/notice/OB11GroupRecallNoticeEvent'; @@ -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,102 +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; + } 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 + ); } - 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( + } 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) - ); - } } } };