From 91ca4e96c4bfd3e3bed24bb9efa3b95afd730176 Mon Sep 17 00:00:00 2001 From: idranme <96647698+idranme@users.noreply.github.com> Date: Thu, 24 Oct 2024 17:40:35 +0800 Subject: [PATCH] fix --- package.json | 2 +- src/ntqqapi/proto/compiled.d.ts | 68 +++++++++ src/ntqqapi/proto/compiled.js | 141 ++++++++++++++++++ ...upMemberChange.proto => groupNotify.proto} | 5 + .../action/group/GetGroupMemberInfo.ts | 2 +- src/onebot11/adapter.ts | 47 +++--- src/onebot11/entities.ts | 41 ++--- 7 files changed, 254 insertions(+), 52 deletions(-) rename src/ntqqapi/proto/{groupMemberChange.proto => groupNotify.proto} (70%) diff --git a/package.json b/package.json index 3307ede..db33d5e 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "deploy-win": "cmd /c \"xcopy /C /S /Y dist\\* %LITELOADERQQNT_PROFILE%\\plugins\\LLOneBot\\\"", "format": "prettier -cw .", "check": "tsc", - "compile:proto": "pbjs --no-create --no-convert --no-verify -t static-module -w es6 -p src/ntqqapi/proto -o src/ntqqapi/proto/compiled.js profileLikeTip.proto groupMemberChange.proto message.proto richMedia.proto && pbts -o src/ntqqapi/proto/compiled.d.ts src/ntqqapi/proto/compiled.js" + "compile:proto": "pbjs --no-create --no-convert --no-verify -t static-module -w es6 -p src/ntqqapi/proto -o src/ntqqapi/proto/compiled.js profileLikeTip.proto groupNotify.proto message.proto richMedia.proto && pbts -o src/ntqqapi/proto/compiled.d.ts src/ntqqapi/proto/compiled.js" }, "author": "", "license": "MIT", diff --git a/src/ntqqapi/proto/compiled.d.ts b/src/ntqqapi/proto/compiled.d.ts index 4b3318f..1700cfd 100644 --- a/src/ntqqapi/proto/compiled.d.ts +++ b/src/ntqqapi/proto/compiled.d.ts @@ -366,6 +366,74 @@ export namespace SysMsg { */ public static getTypeUrl(typeUrlPrefix?: string): string; } + + /** Properties of a GroupInvite. */ + interface IGroupInvite { + + /** GroupInvite groupCode */ + groupCode?: (number|null); + + /** GroupInvite operatorUid */ + operatorUid?: (string|null); + } + + /** Represents a GroupInvite. */ + class GroupInvite implements IGroupInvite { + + /** + * Constructs a new GroupInvite. + * @param [properties] Properties to set + */ + constructor(properties?: SysMsg.IGroupInvite); + + /** GroupInvite groupCode. */ + public groupCode: number; + + /** GroupInvite operatorUid. */ + public operatorUid: string; + + /** + * Encodes the specified GroupInvite message. Does not implicitly {@link SysMsg.GroupInvite.verify|verify} messages. + * @param message GroupInvite message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: SysMsg.IGroupInvite, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified GroupInvite message, length delimited. Does not implicitly {@link SysMsg.GroupInvite.verify|verify} messages. + * @param message GroupInvite message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: SysMsg.IGroupInvite, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a GroupInvite message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns GroupInvite + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): SysMsg.GroupInvite; + + /** + * Decodes a GroupInvite message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns GroupInvite + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): SysMsg.GroupInvite; + + /** + * Gets the default type url for GroupInvite + * @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns The default type url + */ + public static getTypeUrl(typeUrlPrefix?: string): string; + } } /** Namespace Msg. */ diff --git a/src/ntqqapi/proto/compiled.js b/src/ntqqapi/proto/compiled.js index 2b41bc0..4ad1751 100644 --- a/src/ntqqapi/proto/compiled.js +++ b/src/ntqqapi/proto/compiled.js @@ -781,6 +781,147 @@ export const SysMsg = $root.SysMsg = (() => { return GroupMemberChange; })(); + SysMsg.GroupInvite = (function() { + + /** + * Properties of a GroupInvite. + * @memberof SysMsg + * @interface IGroupInvite + * @property {number|null} [groupCode] GroupInvite groupCode + * @property {string|null} [operatorUid] GroupInvite operatorUid + */ + + /** + * Constructs a new GroupInvite. + * @memberof SysMsg + * @classdesc Represents a GroupInvite. + * @implements IGroupInvite + * @constructor + * @param {SysMsg.IGroupInvite=} [properties] Properties to set + */ + function GroupInvite(properties) { + if (properties) + for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * GroupInvite groupCode. + * @member {number} groupCode + * @memberof SysMsg.GroupInvite + * @instance + */ + GroupInvite.prototype.groupCode = 0; + + /** + * GroupInvite operatorUid. + * @member {string} operatorUid + * @memberof SysMsg.GroupInvite + * @instance + */ + GroupInvite.prototype.operatorUid = ""; + + /** + * Encodes the specified GroupInvite message. Does not implicitly {@link SysMsg.GroupInvite.verify|verify} messages. + * @function encode + * @memberof SysMsg.GroupInvite + * @static + * @param {SysMsg.IGroupInvite} message GroupInvite message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + GroupInvite.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.groupCode != null && Object.hasOwnProperty.call(message, "groupCode")) + writer.uint32(/* id 1, wireType 0 =*/8).uint32(message.groupCode); + if (message.operatorUid != null && Object.hasOwnProperty.call(message, "operatorUid")) + writer.uint32(/* id 5, wireType 2 =*/42).string(message.operatorUid); + return writer; + }; + + /** + * Encodes the specified GroupInvite message, length delimited. Does not implicitly {@link SysMsg.GroupInvite.verify|verify} messages. + * @function encodeDelimited + * @memberof SysMsg.GroupInvite + * @static + * @param {SysMsg.IGroupInvite} message GroupInvite message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + GroupInvite.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a GroupInvite message from the specified reader or buffer. + * @function decode + * @memberof SysMsg.GroupInvite + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {SysMsg.GroupInvite} GroupInvite + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + GroupInvite.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + let end = length === undefined ? reader.len : reader.pos + length, message = new $root.SysMsg.GroupInvite(); + while (reader.pos < end) { + let tag = reader.uint32(); + switch (tag >>> 3) { + case 1: { + message.groupCode = reader.uint32(); + break; + } + case 5: { + message.operatorUid = reader.string(); + break; + } + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a GroupInvite message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof SysMsg.GroupInvite + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {SysMsg.GroupInvite} GroupInvite + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + GroupInvite.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Gets the default type url for GroupInvite + * @function getTypeUrl + * @memberof SysMsg.GroupInvite + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + GroupInvite.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/SysMsg.GroupInvite"; + }; + + return GroupInvite; + })(); + return SysMsg; })(); diff --git a/src/ntqqapi/proto/groupMemberChange.proto b/src/ntqqapi/proto/groupNotify.proto similarity index 70% rename from src/ntqqapi/proto/groupMemberChange.proto rename to src/ntqqapi/proto/groupNotify.proto index dd0ed38..02ca253 100644 --- a/src/ntqqapi/proto/groupMemberChange.proto +++ b/src/ntqqapi/proto/groupNotify.proto @@ -7,3 +7,8 @@ message GroupMemberChange { uint32 type = 4; // 130:主动 131:被动 string adminUid = 5; } + +message GroupInvite { + uint32 groupCode = 1; + string operatorUid = 5; +} diff --git a/src/onebot11/action/group/GetGroupMemberInfo.ts b/src/onebot11/action/group/GetGroupMemberInfo.ts index 9b70fbc..c5a06b0 100644 --- a/src/onebot11/action/group/GetGroupMemberInfo.ts +++ b/src/onebot11/action/group/GetGroupMemberInfo.ts @@ -20,7 +20,7 @@ class GetGroupMemberInfo extends BaseAction { protected async _handle(payload: Payload) { const groupCode = payload.group_id.toString() - const uid = await this.ctx.ntUserApi.getUidByUin(payload.user_id.toString()) + const uid = await this.ctx.ntUserApi.getUidByUin(payload.user_id.toString(), groupCode) if (!uid) throw new Error('无法获取用户信息') const member = await this.ctx.ntGroupApi.getGroupMember(groupCode, uid, payload.no_cache) if (member) { diff --git a/src/onebot11/adapter.ts b/src/onebot11/adapter.ts index 763a516..4833c49 100644 --- a/src/onebot11/adapter.ts +++ b/src/onebot11/adapter.ts @@ -9,7 +9,7 @@ import { } from '../ntqqapi/types' import { OB11GroupRequestEvent } from './event/request/OB11GroupRequest' import { OB11FriendRequestEvent } from './event/request/OB11FriendRequest' -import { GroupDecreaseSubType, OB11GroupDecreaseEvent } from './event/notice/OB11GroupDecreaseEvent' +import { OB11GroupDecreaseEvent } from './event/notice/OB11GroupDecreaseEvent' import { selfInfo } from '../common/globalVars' import { OB11Config, Config as LLOBConfig } from '../common/types' import { OB11WebSocket, OB11WebSocketReverseManager } from './connect/ws' @@ -92,25 +92,18 @@ class OneBot11Adapter extends Service { try { const flag = notify.group.groupCode + '|' + notify.seq + '|' + notify.type if ([GroupNotifyType.MemberLeaveNotifyAdmin, GroupNotifyType.KickMemberNotifyAdmin].includes(notify.type)) { - this.ctx.logger.info('有成员退出通知', notify) - const member1Uin = await this.ctx.ntUserApi.getUinByUid(notify.user1.uid) - let operatorId = member1Uin - let subType: GroupDecreaseSubType = 'leave' if (notify.user2.uid) { - // 是被踢的 - const member2Uin = await this.ctx.ntUserApi.getUinByUid(notify.user2.uid) - if (member2Uin) { - operatorId = member2Uin - } - subType = 'kick' + this.ctx.logger.info('有群成员被踢', notify.group.groupCode, notify.user1.uid, notify.user2.uid) + const memberUin = await this.ctx.ntUserApi.getUinByUid(notify.user1.uid) + const adminUin = await this.ctx.ntUserApi.getUinByUid(notify.user2.uid) + const event = new OB11GroupDecreaseEvent( + parseInt(notify.group.groupCode), + parseInt(memberUin), + parseInt(adminUin), + 'kick', + ) + this.dispatch(event) } - const event = new OB11GroupDecreaseEvent( - parseInt(notify.group.groupCode), - parseInt(member1Uin), - parseInt(operatorId), - subType, - ) - this.dispatch(event) } else if (notify.type === GroupNotifyType.RequestJoinNeedAdminiStratorPass && notify.status === GroupNotifyStatus.Unhandle) { this.ctx.logger.info('有加群请求') @@ -369,15 +362,21 @@ class OneBot11Adapter extends Service { const operatorUin = await this.ctx.ntUserApi.getUinByUid(tip.adminUid) const event = new OB11GroupIncreaseEvent(tip.groupCode, +memberUin, +operatorUin) this.dispatch(event) - }/* else if (msgType === 34) { - const tip = SysMsg.GroupMemberChange.decode(sysMsg.bodyWrapper!.body!) + } else if (msgType === 34) { + const tip = SysMsg.GroupMemberChange.decode(sysMsg.body!.msgContent!) + if (tip.type !== 130) return // adminUid: 0 this.ctx.logger.info('群成员减少', tip) const memberUin = await this.ctx.ntUserApi.getUinByUid(tip.memberUid) - const operatorUin = await this.ctx.ntUserApi.getUinByUid(tip.adminUid) //0 - const subType = tip.type === 130 ? 'leave' : 'kick' - const event = new OB11GroupDecreaseEvent(tip.groupCode, +memberUin, +operatorUin, subType) + const userId = Number(memberUin) + const event = new OB11GroupDecreaseEvent(tip.groupCode, userId, userId) this.dispatch(event) - }*/ + } else if (msgType === 87) { + const tip = SysMsg.GroupInvite.decode(sysMsg.body!.msgContent!) + this.ctx.logger.info('群成员增加', tip) + const operatorUin = await this.ctx.ntUserApi.getUinByUid(tip.operatorUid) + const event = new OB11GroupIncreaseEvent(tip.groupCode, +selfInfo.uin, +operatorUin, 'invite') + this.dispatch(event) + } }) } } diff --git a/src/onebot11/entities.ts b/src/onebot11/entities.ts index 9e7a970..9dac299 100644 --- a/src/onebot11/entities.ts +++ b/src/onebot11/entities.ts @@ -423,6 +423,8 @@ export namespace OB11Entities { for (const element of msg.elements) { const grayTipElement = element.grayTipElement const groupElement = grayTipElement?.groupElement + const xmlElement = grayTipElement?.xmlElement + if (groupElement) { if (groupElement.type === TipGroupElementType.Ban) { ctx.logger.info('收到群成员禁言提示', groupElement) @@ -485,11 +487,8 @@ export namespace OB11Entities { busid: element.fileElement.fileBizId || 0, }) } - - if (grayTipElement) { - const xmlElement = grayTipElement.xmlElement - - if (xmlElement?.templId === '10382') { + else if (xmlElement) { + if (xmlElement.templId === '10382') { ctx.logger.info('收到表情回应我的消息', xmlElement.templParam) try { const senderUin = xmlElement.templParam.get('jp_uin') @@ -517,29 +516,19 @@ export namespace OB11Entities { } catch (e) { ctx.logger.error('解析表情回应消息失败', (e as Error).stack) } - } - - if ( - grayTipElement.subElementType == GrayTipElementSubType.XmlMsg && - xmlElement?.templId == '10179' - ) { - ctx.logger.info('收到新人被邀请进群消息', grayTipElement) - if (xmlElement?.content) { - const regex = /jp="(\d+)"/g - - const matches: string[] = [] - let match: RegExpExecArray | null = null - - while ((match = regex.exec(xmlElement.content)) !== null) { - matches.push(match[1]) - } - if (matches.length === 2) { - const [invitor, invitee] = matches - return new OB11GroupIncreaseEvent(+msg.peerUid, +invitee, +invitor, 'invite') - } + } else if (xmlElement.templId == '10179') { + ctx.logger.info('收到新人被邀请进群消息', xmlElement) + const invitor = xmlElement.templParam.get('invitor') + const invitee = xmlElement.templParam.get('invitee') + if (invitee === selfInfo.uin) return + if (invitor && invitee) { + return new OB11GroupIncreaseEvent(+msg.peerUid, +invitee, +invitor, 'invite') } } - else if (grayTipElement.subElementType == GrayTipElementSubType.JSON) { + } + + if (grayTipElement) { + if (grayTipElement.subElementType == GrayTipElementSubType.JSON) { const json = JSON.parse(grayTipElement.jsonGrayTipElement!.jsonStr) if (grayTipElement.jsonGrayTipElement?.busiId === '1061') { const param = grayTipElement.jsonGrayTipElement.xmlToJsonParam