mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
refactor: #637
This commit is contained in:
@@ -19,12 +19,11 @@ export default class SetGroupAddRequest extends OneBotAction<Payload, null> {
|
|||||||
const flag = payload.flag.toString();
|
const flag = payload.flag.toString();
|
||||||
const approve = payload.approve?.toString() !== 'false';
|
const approve = payload.approve?.toString() !== 'false';
|
||||||
const reason = payload.reason ?? ' ';
|
const reason = payload.reason ?? ' ';
|
||||||
|
let invite_notify = this.obContext.apis.MsgApi.notifyGroupInvite.get(flag);
|
||||||
const notify = await this.findNotify(flag);
|
const notify = invite_notify ?? await this.findNotify(flag);
|
||||||
if (!notify) {
|
if (!notify) {
|
||||||
throw new Error('No such request');
|
throw new Error('No such request');
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.core.apis.GroupApi.handleGroupRequest(
|
await this.core.apis.GroupApi.handleGroupRequest(
|
||||||
notify,
|
notify,
|
||||||
approve ? NTGroupRequestOperateTypes.KAGREE : NTGroupRequestOperateTypes.KREFUSE,
|
approve ? NTGroupRequestOperateTypes.KAGREE : NTGroupRequestOperateTypes.KREFUSE,
|
||||||
|
@@ -17,6 +17,7 @@ import {
|
|||||||
SendTextElement,
|
SendTextElement,
|
||||||
FaceType,
|
FaceType,
|
||||||
GrayTipElement,
|
GrayTipElement,
|
||||||
|
GroupNotify,
|
||||||
} from '@/core';
|
} from '@/core';
|
||||||
import faceConfig from '@/core/external/face_config.json';
|
import faceConfig from '@/core/external/face_config.json';
|
||||||
import { NapCatOneBot11Adapter, OB11Message, OB11MessageData, OB11MessageDataType, OB11MessageFileBase, OB11MessageForward, } from '@/onebot';
|
import { NapCatOneBot11Adapter, OB11Message, OB11MessageData, OB11MessageDataType, OB11MessageFileBase, OB11MessageForward, } from '@/onebot';
|
||||||
@@ -35,6 +36,7 @@ import { GroupAdmin } from '@/core/packet/transformer/proto/message/groupAdmin';
|
|||||||
import { OB11GroupAdminNoticeEvent } from '../event/notice/OB11GroupAdminNoticeEvent';
|
import { OB11GroupAdminNoticeEvent } from '../event/notice/OB11GroupAdminNoticeEvent';
|
||||||
import { GroupChange, GroupChangeInfo, GroupInvite, PushMsgBody } from '@/core/packet/transformer/proto';
|
import { GroupChange, GroupChangeInfo, GroupInvite, PushMsgBody } from '@/core/packet/transformer/proto';
|
||||||
import { OB11GroupRequestEvent } from '../event/request/OB11GroupRequest';
|
import { OB11GroupRequestEvent } from '../event/request/OB11GroupRequest';
|
||||||
|
import { LRUCache } from '@/common/lru-cache';
|
||||||
|
|
||||||
type RawToOb11Converters = {
|
type RawToOb11Converters = {
|
||||||
[Key in keyof MessageElement as Key extends `${string}Element` ? Key : never]: (
|
[Key in keyof MessageElement as Key extends `${string}Element` ? Key : never]: (
|
||||||
@@ -68,7 +70,8 @@ function keyCanBeParsed(key: string, parser: RawToOb11Converters): key is keyof
|
|||||||
export class OneBotMsgApi {
|
export class OneBotMsgApi {
|
||||||
obContext: NapCatOneBot11Adapter;
|
obContext: NapCatOneBot11Adapter;
|
||||||
core: NapCatCore;
|
core: NapCatCore;
|
||||||
|
notifyGroupInvite: LRUCache<string, GroupNotify> = new LRUCache(50);
|
||||||
|
// seq -> notify
|
||||||
rawToOb11Converters: RawToOb11Converters = {
|
rawToOb11Converters: RawToOb11Converters = {
|
||||||
textElement: async element => {
|
textElement: async element => {
|
||||||
if (element.atType === NTMsgAtType.ATTYPEUNKNOWN) {
|
if (element.atType === NTMsgAtType.ATTYPEUNKNOWN) {
|
||||||
@@ -1037,22 +1040,61 @@ export class OneBotMsgApi {
|
|||||||
} else if (SysMessage.contentHead.type == 87 && SysMessage.body?.msgContent) {
|
} else if (SysMessage.contentHead.type == 87 && SysMessage.body?.msgContent) {
|
||||||
let groupInvite = new NapProtoMsg(GroupInvite).decode(SysMessage.body.msgContent);
|
let groupInvite = new NapProtoMsg(GroupInvite).decode(SysMessage.body.msgContent);
|
||||||
let request_seq = '';
|
let request_seq = '';
|
||||||
await this.core.eventWrapper.registerListen('NodeIKernelMsgListener/onRecvMsg', (msgs) => {
|
try {
|
||||||
for (const msg of msgs) {
|
await this.core.eventWrapper.registerListen('NodeIKernelMsgListener/onRecvMsg', (msgs) => {
|
||||||
if (msg.senderUid === groupInvite.invitorUid && msg.msgType === 11) {
|
for (const msg of msgs) {
|
||||||
let jumpUrl = JSON.parse(msg.elements.find(e => e.elementType === 10)?.arkElement?.bytesData ?? '').meta?.news?.jumpUrl;
|
if (msg.senderUid === groupInvite.invitorUid && msg.msgType === 11) {
|
||||||
let jumpUrlParams = new URLSearchParams(jumpUrl);
|
let jumpUrl = JSON.parse(msg.elements.find(e => e.elementType === 10)?.arkElement?.bytesData ?? '').meta?.news?.jumpUrl;
|
||||||
let groupcode = jumpUrlParams.get('groupcode');
|
let jumpUrlParams = new URLSearchParams(jumpUrl);
|
||||||
let receiveruin = jumpUrlParams.get('receiveruin');
|
let groupcode = jumpUrlParams.get('groupcode');
|
||||||
let msgseq = jumpUrlParams.get('msgseq');
|
let receiveruin = jumpUrlParams.get('receiveruin');
|
||||||
request_seq = msgseq ?? '';
|
let msgseq = jumpUrlParams.get('msgseq');
|
||||||
if (groupcode === groupInvite.groupUin.toString() && receiveruin === this.core.selfInfo.uin) {
|
request_seq = msgseq ?? '';
|
||||||
return true;
|
if (groupcode === groupInvite.groupUin.toString() && receiveruin === this.core.selfInfo.uin) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
return false;
|
||||||
return false;
|
}, 1, 1000);
|
||||||
}, 1, 1000);
|
} catch (error) {
|
||||||
|
request_seq = '';
|
||||||
|
}
|
||||||
|
// 未拉取到seq
|
||||||
|
if (request_seq === '') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 创建个假的
|
||||||
|
this.notifyGroupInvite.put(request_seq, {
|
||||||
|
seq: request_seq,
|
||||||
|
type: 1,
|
||||||
|
group: {
|
||||||
|
groupCode: groupInvite.groupUin.toString(),
|
||||||
|
groupName: '',
|
||||||
|
},
|
||||||
|
user1: {
|
||||||
|
uid: groupInvite.invitorUid,
|
||||||
|
nickName: '',
|
||||||
|
},
|
||||||
|
user2: {
|
||||||
|
uid: this.core.selfInfo.uid,
|
||||||
|
nickName: '',
|
||||||
|
},
|
||||||
|
actionUser: {
|
||||||
|
uid: groupInvite.invitorUid,
|
||||||
|
nickName: '',
|
||||||
|
},
|
||||||
|
actionTime: Date.now().toString(),
|
||||||
|
postscript: '',
|
||||||
|
repeatSeqs: [],
|
||||||
|
warningTips: '',
|
||||||
|
invitationExt: {
|
||||||
|
srcType: 1,
|
||||||
|
groupCode: groupInvite.groupUin.toString(),
|
||||||
|
waitStatus: 1,
|
||||||
|
},
|
||||||
|
status: 1
|
||||||
|
})
|
||||||
return new OB11GroupRequestEvent(
|
return new OB11GroupRequestEvent(
|
||||||
this.core,
|
this.core,
|
||||||
+groupInvite.groupUin,
|
+groupInvite.groupUin,
|
||||||
|
@@ -91,11 +91,13 @@ export class OneBotQuickActionApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async handleGroupRequest(request: OB11GroupRequestEvent, quickAction: QuickActionGroupRequest) {
|
async handleGroupRequest(request: OB11GroupRequestEvent, quickAction: QuickActionGroupRequest) {
|
||||||
const noify = await this.findNotify(request.flag);
|
|
||||||
|
let invite_notify = this.obContext.apis.MsgApi.notifyGroupInvite.get(request.flag);
|
||||||
|
const notify = invite_notify ?? await this.findNotify(request.flag);
|
||||||
|
|
||||||
if (!isNull(quickAction.approve) && noify) {
|
if (!isNull(quickAction.approve) && notify) {
|
||||||
this.core.apis.GroupApi.handleGroupRequest(
|
this.core.apis.GroupApi.handleGroupRequest(
|
||||||
noify,
|
notify,
|
||||||
quickAction.approve ? NTGroupRequestOperateTypes.KAGREE : NTGroupRequestOperateTypes.KREFUSE,
|
quickAction.approve ? NTGroupRequestOperateTypes.KAGREE : NTGroupRequestOperateTypes.KREFUSE,
|
||||||
quickAction.reason,
|
quickAction.reason,
|
||||||
).catch(e => this.core.context.logger.logError(e));
|
).catch(e => this.core.context.logger.logError(e));
|
||||||
|
Reference in New Issue
Block a user