Skip to content

Commit

Permalink
fix: delete group
Browse files Browse the repository at this point in the history
  • Loading branch information
linyuchen committed Apr 16, 2024
1 parent 0773a4f commit 58747d7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/common/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export const selfInfo: SelfInfo = {
// groupCode -> Group
export const groups: Map<string, Group> = new Map<string, Group>();

export function deleteGroup(groupQQ: string) {
groups.delete(groupQQ);
groupMembers.delete(groupQQ);
}

// 群号 -> 群成员map(uid=>GroupMember)
export const groupMembers: Map<string, Map<string, GroupMember>> = new Map<string, Map<string, GroupMember>>();

Expand Down
17 changes: 12 additions & 5 deletions src/onebot11/constructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions src/onebot11/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 58747d7

Please sign in to comment.