From 58747d7d4ae12b3ae9e663d86f94ec1a76c37d10 Mon Sep 17 00:00:00 2001 From: linyuchen Date: Tue, 16 Apr 2024 23:10:29 +0800 Subject: [PATCH] fix: delete group --- src/common/data.ts | 5 +++++ src/onebot11/constructor.ts | 17 ++++++++++++----- src/onebot11/main.ts | 3 +-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/common/data.ts b/src/common/data.ts index 85f24feb1..01ac1102a 100644 --- a/src/common/data.ts +++ b/src/common/data.ts @@ -18,6 +18,11 @@ export const selfInfo: SelfInfo = { // groupCode -> Group export const groups: Map = new Map(); +export function deleteGroup(groupQQ: string) { + groups.delete(groupQQ); + groupMembers.delete(groupQQ); +} + // 群号 -> 群成员map(uid=>GroupMember) export const groupMembers: Map> = new Map>(); diff --git a/src/onebot11/constructor.ts b/src/onebot11/constructor.ts index ef3feee63..723f2d467 100644 --- a/src/onebot11/constructor.ts +++ b/src/onebot11/constructor.ts @@ -38,7 +38,8 @@ import { OB11GroupTitleEvent } from './event/notice/OB11GroupTitleEvent'; import { OB11GroupCardEvent } from './event/notice/OB11GroupCardEvent'; import { OB11GroupDecreaseEvent } from './event/notice/OB11GroupDecreaseEvent'; import { ob11Config } from '@/onebot11/config'; -import { getFriend, getGroupMember, groupMembers, selfInfo, tempGroupCodeMap } from '@/common/data'; +import { deleteGroup, getFriend, getGroupMember, groupMembers, selfInfo, tempGroupCodeMap } from '@/common/data'; +import { NTQQGroupApi, NTQQUserApi } from '@/core/qqnt/apis'; export class OB11Constructor { @@ -322,10 +323,16 @@ export class OB11Constructor { return event; } } else if (groupElement.type == TipGroupElementType.kicked) { - log('收到我被踢出提示', groupElement); - const adminUin = (await getGroupMember(msg.peerUid, groupElement.adminUid))?.uin; //|| (await NTQQUserApi.getUserDetailInfo(groupElement.adminUid))?.uin - if (adminUin) { - return new OB11GroupDecreaseEvent(parseInt(msg.peerUid), parseInt(selfInfo.uin), parseInt(adminUin), 'kick_me'); + log(`收到我被踢出或退群提示, 群${msg.peerUid}`, groupElement); + deleteGroup(msg.peerUid); + NTQQGroupApi.quitGroup(msg.peerUid).then(); + try { + const adminUin = (await getGroupMember(msg.peerUid, groupElement.adminUid))?.uin || (await NTQQUserApi.getUserDetailInfo(groupElement.adminUid))?.uin; + if (adminUin) { + return new OB11GroupDecreaseEvent(parseInt(msg.peerUid), parseInt(selfInfo.uin), parseInt(adminUin), 'kick_me'); + } + } catch (e) { + return new OB11GroupDecreaseEvent(parseInt(msg.peerUid), parseInt(selfInfo.uin), 0, 'leave'); } } } else if (element.fileElement) { diff --git a/src/onebot11/main.ts b/src/onebot11/main.ts index de8894201..cc07bb88f 100644 --- a/src/onebot11/main.ts +++ b/src/onebot11/main.ts @@ -29,7 +29,7 @@ import { OB11GroupRecallNoticeEvent } from '@/onebot11/event/notice/OB11GroupRec export class NapCatOnebot11 { - private bootTime: number = Date.now() / 1000; + private bootTime: number = Date.now() / 1000; // 秒 constructor() { @@ -130,7 +130,6 @@ export class NapCatOnebot11 { // if (message.senderUin !== selfInfo.uin){ // message.msgShortId = await dbUtil.addMsg(message); // } - OB11Constructor.message(message).then((msg) => { if (debug) { msg.raw = message;