mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
@@ -56,6 +56,7 @@ export interface GrayTipElement {
|
|||||||
aioOpGrayTipElement: TipAioOpGrayTipElement;
|
aioOpGrayTipElement: TipAioOpGrayTipElement;
|
||||||
groupElement: TipGroupElement;
|
groupElement: TipGroupElement;
|
||||||
xmlElement: {
|
xmlElement: {
|
||||||
|
busiId: string;
|
||||||
content: string;
|
content: string;
|
||||||
templId: string;
|
templId: string;
|
||||||
};
|
};
|
||||||
|
@@ -24,6 +24,7 @@ import { OB11GroupUploadNoticeEvent } from '../event/notice/OB11GroupUploadNotic
|
|||||||
import { OB11GroupNameEvent } from '../event/notice/OB11GroupNameEvent';
|
import { OB11GroupNameEvent } from '../event/notice/OB11GroupNameEvent';
|
||||||
import { pathToFileURL } from 'node:url';
|
import { pathToFileURL } from 'node:url';
|
||||||
import { FileNapCatOneBotUUID } from '@/common/helper';
|
import { FileNapCatOneBotUUID } from '@/common/helper';
|
||||||
|
import { OB11GroupIncreaseEvent } from '../event/notice/OB11GroupIncreaseEvent';
|
||||||
|
|
||||||
export class OneBotGroupApi {
|
export class OneBotGroupApi {
|
||||||
obContext: NapCatOneBot11Adapter;
|
obContext: NapCatOneBot11Adapter;
|
||||||
@@ -219,16 +220,51 @@ export class OneBotGroupApi {
|
|||||||
} else if (element.type === TipGroupElementType.KSHUTUP) {
|
} else if (element.type === TipGroupElementType.KSHUTUP) {
|
||||||
let event = await this.parseGroupBanEvent(msg.peerUid, elementWrapper);
|
let event = await this.parseGroupBanEvent(msg.peerUid, elementWrapper);
|
||||||
return event;
|
return event;
|
||||||
|
} else if (element.type === TipGroupElementType.KMEMBERADD) {
|
||||||
|
// 自己的通知 协议推送为type->85 在这里实现为了避免邀请出现问题
|
||||||
|
if (element.memberUid == this.core.selfInfo.uid) {
|
||||||
|
this.core.apis.GroupApi.refreshGroupMemberCache(msg.peerUid).then().catch();
|
||||||
|
return new OB11GroupIncreaseEvent(
|
||||||
|
this.core,
|
||||||
|
parseInt(msg.peerUid),
|
||||||
|
+this.core.selfInfo.uin,
|
||||||
|
element.adminUid ? +await this.core.apis.UserApi.getUinByUidV2(element.adminUid) : 0,
|
||||||
|
'approve'
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async parseSelfInviteEvent(msg: RawMessage, inviterUin: string, inviteeUin: string) {
|
||||||
|
return new OB11GroupIncreaseEvent(
|
||||||
|
this.core,
|
||||||
|
parseInt(msg.peerUid),
|
||||||
|
+inviteeUin,
|
||||||
|
+inviterUin,
|
||||||
|
'invite'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
async parseGrayTipElement(msg: RawMessage, grayTipElement: GrayTipElement) {
|
async parseGrayTipElement(msg: RawMessage, grayTipElement: GrayTipElement) {
|
||||||
if (grayTipElement.subElementType === NTGrayTipElementSubTypeV2.GRAYTIP_ELEMENT_SUBTYPE_GROUP) {
|
if (grayTipElement.subElementType === NTGrayTipElementSubTypeV2.GRAYTIP_ELEMENT_SUBTYPE_GROUP) {
|
||||||
// 解析群组事件 由sysmsg解析
|
// 解析群组事件 由sysmsg解析
|
||||||
return await this.parseGroupElement(msg, grayTipElement.groupElement, grayTipElement);
|
return await this.parseGroupElement(msg, grayTipElement.groupElement, grayTipElement);
|
||||||
} else if (grayTipElement.subElementType === NTGrayTipElementSubTypeV2.GRAYTIP_ELEMENT_SUBTYPE_XMLMSG) {
|
} else if (grayTipElement.subElementType === NTGrayTipElementSubTypeV2.GRAYTIP_ELEMENT_SUBTYPE_XMLMSG) {
|
||||||
// 筛选出表情回应 事件
|
// 筛选自身入群情况
|
||||||
if (grayTipElement.xmlElement?.templId === '10382') {
|
// if (grayTipElement.xmlElement.busiId === '10145') {
|
||||||
|
// const inviteData = new fastXmlParser.XMLParser({
|
||||||
|
// ignoreAttributes: false,
|
||||||
|
// attributeNamePrefix: '',
|
||||||
|
// }).parse(grayTipElement.xmlElement.content);
|
||||||
|
|
||||||
|
// const inviterUin: string = inviteData.gtip.qq[0].jp;
|
||||||
|
// const inviteeUin: string = inviteData.gtip.qq[1].jp;
|
||||||
|
// //刷新群缓存
|
||||||
|
// if (inviteeUin === this.core.selfInfo.uin) {
|
||||||
|
// this.core.apis.GroupApi.refreshGroupMemberCache(msg.peerUid).then().catch();
|
||||||
|
// return this.parseSelfInviteEvent(msg, inviterUin, inviteeUin);
|
||||||
|
// }
|
||||||
|
} else if (grayTipElement.xmlElement?.templId === '10382') {
|
||||||
return await this.obContext.apis.GroupApi.parseGroupEmojiLikeEventByGrayTip(msg.peerUid, grayTipElement);
|
return await this.obContext.apis.GroupApi.parseGroupEmojiLikeEventByGrayTip(msg.peerUid, grayTipElement);
|
||||||
} else {
|
} else {
|
||||||
//return await this.obContext.apis.GroupApi.parseGroupIncreaseEvent(msg.peerUid, grayTipElement);
|
//return await this.obContext.apis.GroupApi.parseGroupIncreaseEvent(msg.peerUid, grayTipElement);
|
||||||
|
@@ -972,6 +972,7 @@ export class OneBotMsgApi {
|
|||||||
|
|
||||||
return { path, fileName: inputdata.name ?? fileName };
|
return { path, fileName: inputdata.name ?? fileName };
|
||||||
}
|
}
|
||||||
|
|
||||||
groupChangDecreseType2String(type: number): GroupDecreaseSubType {
|
groupChangDecreseType2String(type: number): GroupDecreaseSubType {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 130:
|
case 130:
|
||||||
@@ -985,12 +986,41 @@ export class OneBotMsgApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async waitGroupNotify(groupUin: string, memberUid?: string, operatorUid?: string) {
|
||||||
|
let groupRole = this.core.apis.GroupApi.groupMemberCache.get(groupUin)?.get(this.core.selfInfo.uid.toString())?.role;
|
||||||
|
let isAdminOrOwner = groupRole === 3 || groupRole === 4;
|
||||||
|
|
||||||
|
if (isAdminOrOwner && !operatorUid) {
|
||||||
|
let dataNotify: GroupNotify | undefined;
|
||||||
|
await this.core.eventWrapper.registerListen('NodeIKernelGroupListener/onGroupNotifiesUpdated',
|
||||||
|
(doubt, notifies) => {
|
||||||
|
for (const notify of notifies) {
|
||||||
|
if (notify.group.groupCode === groupUin && notify.user1.uid === memberUid) {
|
||||||
|
dataNotify = notify;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}, 1, 1000).catch(undefined);
|
||||||
|
if (dataNotify) {
|
||||||
|
return !dataNotify.actionUser.uid ? dataNotify.user2.uid : dataNotify.actionUser.uid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return operatorUid;
|
||||||
|
}
|
||||||
|
|
||||||
async parseSysMessage(msg: number[]) {
|
async parseSysMessage(msg: number[]) {
|
||||||
const SysMessage = new NapProtoMsg(PushMsgBody).decode(Uint8Array.from(msg));
|
const SysMessage = new NapProtoMsg(PushMsgBody).decode(Uint8Array.from(msg));
|
||||||
|
// 邀请需要解grayTipElement
|
||||||
if (SysMessage.contentHead.type == 33 && SysMessage.body?.msgContent) {
|
if (SysMessage.contentHead.type == 33 && SysMessage.body?.msgContent) {
|
||||||
const groupChange = new NapProtoMsg(GroupChange).decode(SysMessage.body.msgContent);
|
const groupChange = new NapProtoMsg(GroupChange).decode(SysMessage.body.msgContent);
|
||||||
this.core.apis.GroupApi.refreshGroupMemberCache(groupChange.groupUin.toString()).then().catch();
|
this.core.apis.GroupApi.refreshGroupMemberCache(groupChange.groupUin.toString()).then().catch();
|
||||||
const operatorUid = groupChange.operatorInfo ? Buffer.from(groupChange.operatorInfo).toString() : '';
|
let operatorUid = await this.waitGroupNotify(
|
||||||
|
groupChange.groupUin.toString(),
|
||||||
|
groupChange.memberUid,
|
||||||
|
groupChange.operatorInfo ? Buffer.from(groupChange.operatorInfo).toString() : ''
|
||||||
|
);
|
||||||
return new OB11GroupIncreaseEvent(
|
return new OB11GroupIncreaseEvent(
|
||||||
this.core,
|
this.core,
|
||||||
groupChange.groupUin,
|
groupChange.groupUin,
|
||||||
@@ -998,12 +1028,17 @@ export class OneBotMsgApi {
|
|||||||
operatorUid ? +await this.core.apis.UserApi.getUinByUidV2(operatorUid) : 0,
|
operatorUid ? +await this.core.apis.UserApi.getUinByUidV2(operatorUid) : 0,
|
||||||
groupChange.decreaseType == 131 ? 'invite' : 'approve',
|
groupChange.decreaseType == 131 ? 'invite' : 'approve',
|
||||||
);
|
);
|
||||||
|
|
||||||
} else if (SysMessage.contentHead.type == 34 && SysMessage.body?.msgContent) {
|
} else if (SysMessage.contentHead.type == 34 && SysMessage.body?.msgContent) {
|
||||||
const groupChange = new NapProtoMsg(GroupChange).decode(SysMessage.body.msgContent);
|
const groupChange = new NapProtoMsg(GroupChange).decode(SysMessage.body.msgContent);
|
||||||
// 自身被踢出时operatorInfo会是一个protobuf 否则大多数情况为一个string
|
// 自身被踢出时operatorInfo会是一个protobuf 否则大多数情况为一个string
|
||||||
const operatorUid = groupChange.decreaseType === 3 && groupChange.operatorInfo ?
|
let operatorUid = await this.waitGroupNotify(
|
||||||
new NapProtoMsg(GroupChangeInfo).decode(groupChange.operatorInfo).operator?.operatorUid :
|
groupChange.groupUin.toString(),
|
||||||
groupChange.operatorInfo?.toString();
|
groupChange.memberUid,
|
||||||
|
groupChange.decreaseType === 3 && groupChange.operatorInfo ?
|
||||||
|
new NapProtoMsg(GroupChangeInfo).decode(groupChange.operatorInfo).operator?.operatorUid :
|
||||||
|
groupChange.operatorInfo?.toString()
|
||||||
|
);
|
||||||
if (groupChange.memberUid === this.core.selfInfo.uid) {
|
if (groupChange.memberUid === this.core.selfInfo.uid) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.core.apis.GroupApi.groupMemberCache.delete(groupChange.groupUin.toString());
|
this.core.apis.GroupApi.groupMemberCache.delete(groupChange.groupUin.toString());
|
||||||
@@ -1103,8 +1138,7 @@ export class OneBotMsgApi {
|
|||||||
'',
|
'',
|
||||||
request_seq
|
request_seq
|
||||||
);
|
);
|
||||||
}
|
} else if (SysMessage.contentHead.type == 528 && SysMessage.contentHead.subType == 39 && SysMessage.body?.msgContent) {
|
||||||
else if (SysMessage.contentHead.type == 528 && SysMessage.contentHead.subType == 39 && SysMessage.body?.msgContent) {
|
|
||||||
return await this.obContext.apis.UserApi.parseLikeEvent(SysMessage.body?.msgContent);
|
return await this.obContext.apis.UserApi.parseLikeEvent(SysMessage.body?.msgContent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user