BUG修复

1.尝试让所有人能收到group_admin事件
2.修复请求API: delete_msg(POST请求网址传参)将负数判定为文本导致无法调用的问题
This commit is contained in:
Alen 2024-07-22 01:22:38 +08:00
parent 0b4b25a11e
commit b1c6ce3885
4 changed files with 59 additions and 6 deletions

View File

@ -21,7 +21,7 @@ import { dbUtil } from '@/common/utils/db';
import { sleep } from '@/common/utils/helper';
import crypto from 'node:crypto';
import { rawFriends, friends, groupMembers, groups, selfInfo, stat } from '@/core/data';
import { RawMessage } from '@/core/entities';
import { GroupMember, RawMessage } from '@/core/entities';
import { NTEventDispatch } from '@/common/utils/EventTask';
import {
enableConsoleLog,
@ -346,7 +346,7 @@ export class NapCatCore {
// console.log('onMemberListChange', groupCode, arg);
};
groupListener.onMemberInfoChange = (groupCode, changeType, members) => {
// console.log('onMemberInfoChange', arg);
//console.log('onMemberInfoChange', groupCode, changeType, members);
if (changeType === 0 && members.get(selfInfo.uid)?.isDelete) {
// 自身退群或者被踢退群 5s用于Api操作 之后不再出现
setTimeout(() => {
@ -359,6 +359,9 @@ export class NapCatCore {
members.forEach((member, uid) => {
const existMember = existMembers.get(uid);
if (existMember) {
// 检查管理变动
member.isChangeRole = this.checkAdminEvent(groupCode, member, existMember);
// 更新成员信息
Object.assign(existMember, member);
}
else {
@ -471,6 +474,13 @@ export class NapCatCore {
const loginList = await this.loginService.getLoginList();
return loginList;
}
checkAdminEvent(groupCode: string, memberNew: GroupMember, memberOld: GroupMember | undefined ) : boolean {
if (memberNew.role !== memberOld.role) {
log(`${groupCode} ${memberNew.nick} 角色变更为 ${memberNew.role === 3 ? '管理员' : '群员' }`);
return true;
}
return false;
}
}
export const napCatCore = new NapCatCore();

View File

@ -52,4 +52,5 @@ export interface GroupMember {
isRobot: boolean;
sex?: Sex
qqLevel?: QQLevel
isChangeRole: boolean;
}

View File

@ -7,7 +7,12 @@ import { FromSchema, JSONSchema } from 'json-schema-to-ts';
const SchemaData = {
type: 'object',
properties: {
message_id: { type: 'number' },
message_id: {
oneOf:[
{ type: 'number' },
{ type: 'string' }
]
}
},
required: ['message_id']
} as const satisfies JSONSchema;
@ -18,7 +23,7 @@ class DeleteMsg extends BaseAction<Payload, void> {
actionName = ActionName.DeleteMsg;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
const msg = await dbUtil.getMsgByShortId(payload.message_id);
const msg = await dbUtil.getMsgByShortId(Number(payload.message_id));
if (msg) {
await NTQQMsgApi.recallMsg({ peerUid: msg.peerUid, chatType: msg.chatType }, [msg.msgId]);
}

View File

@ -19,7 +19,7 @@ import { OB11Config, ob11Config } from '@/onebot11/config';
import { httpHeart, ob11HTTPServer } from '@/onebot11/server/http';
import { ob11WebsocketServer } from '@/onebot11/server/ws/WebsocketServer';
import { ob11ReverseWebsockets } from '@/onebot11/server/ws/ReverseWebsocket';
import { getGroup, getGroupMember, selfInfo, tempGroupCodeMap } from '@/core/data';
import { getGroup, getGroupMember, groupMembers, selfInfo, tempGroupCodeMap } from '@/core/data';
import { dbUtil } from '@/common/utils/db';
import { BuddyListener, GroupListener, NodeIKernelBuddyListener } from '@/core/listeners';
import { OB11FriendRequestEvent } from '@/onebot11/event/request/OB11FriendRequest';
@ -267,9 +267,46 @@ export class NapCatOnebot11 {
const groupListener = new GroupListener();
groupListener.onGroupNotifiesUpdated = async (doubt, notifies) => {
//console.log('ob11 onGroupNotifiesUpdated', notifies[0]);
this.postGroupNotifies(notifies).then().catch(e => logError('postGroupNotifies error: ', e));
if (![GroupNotifyTypes.ADMIN_SET, GroupNotifyTypes.ADMIN_UNSET, GroupNotifyTypes.ADMIN_UNSET_OTHER].includes(notifies[0].type)) {
this.postGroupNotifies(notifies).then().catch(e => logError('postGroupNotifies error: ', e));
};
};
groupListener.onMemberInfoChange = async (groupCode: string, changeType: number, members: Map<string, GroupMember>) => {
//console.log("ob11 onMemberInfoChange", groupCode, changeType, members)
if (changeType === 1) {
let member;
for (const [key, value] of members) {
member = value;
break;
}
const existMembers = groupMembers.get(groupCode);
if (existMembers) {
const existMember = existMembers.get(member.uid);
if (existMember) {
if (existMember.isChangeRole) {
//console.log("ob11 onMemberInfoChange:eventMember:localMember", member, existMember)
const notify: GroupNotify[] = [
{
time: Date.now(),
seq: (Date.now() * 1000 * 1000).toString(),
type: member.role === GroupMemberRole.admin ? GroupNotifyTypes.ADMIN_SET : GroupNotifyTypes.ADMIN_UNSET_OTHER, // 8 设置; 13 取消
status: 0,
group: { groupCode: groupCode, groupName: '' },
user1: { uid: member.uid, nickName: member.nick },
user2: { uid: member.uid, nickName: member.nick },
actionUser: { uid: '', nickName: '' },
actionTime: '0',
invitationExt: { srcType: 0, groupCode: '0', waitStatus: 0 },
postscript: '',
repeatSeqs: [],
warningTips: ''
}
];
this.postGroupNotifies(notify).then().catch(e => logError('postGroupNotifies error: ', e));
}
}
}
}
// 如果自身是非管理员也许要从这里获取Delete 成员变动 待测试与验证
const role = (await getGroupMember(groupCode, selfInfo.uin))?.role;
const isPrivilege = role === 3 || role === 4;