From f32a6320fc6042786c24d74937dd1b344a58ef1b Mon Sep 17 00:00:00 2001 From: linyuchen Date: Sat, 4 May 2024 21:56:45 +0800 Subject: [PATCH] remove webapi get group members --- .../action/group/GetGroupMemberInfo.ts | 21 +++++++++++-------- .../action/group/GetGroupMemberList.ts | 21 ++++++++++--------- src/onebot11/server/ws/ReverseWebsocket.ts | 4 +++- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/onebot11/action/group/GetGroupMemberInfo.ts b/src/onebot11/action/group/GetGroupMemberInfo.ts index 9e013e7b..be70dc1f 100644 --- a/src/onebot11/action/group/GetGroupMemberInfo.ts +++ b/src/onebot11/action/group/GetGroupMemberInfo.ts @@ -6,12 +6,13 @@ import { ActionName } from '../types'; import { NTQQUserApi } from '@/core/apis/user'; import { log, logDebug } from '@/common/utils/log'; import { isNull } from '../../../common/utils/helper'; -import { WebApi } from '@/core/apis/webapi'; +import { WebApi, WebApiGroupMember } from '@/core/apis/webapi'; export interface PayloadType { group_id: number; user_id: number; + no_cache?: boolean | string; } class GetGroupMemberInfo extends BaseAction { @@ -22,7 +23,10 @@ class GetGroupMemberInfo extends BaseAction { if (!group) { throw (`群(${payload.group_id})不存在`); } - const WebGroupMember = await WebApi.getGroupMembers(payload.group_id.toString()); + const webGroupMembers: WebApiGroupMember[] = []; + if (payload.no_cache === true || payload.no_cache === 'true') { + // webGroupMembers = await WebApi.getGroupMembers(payload.group_id.toString()); + } const member = await getGroupMember(payload.group_id.toString(), payload.user_id.toString()); // log(member); if (member) { @@ -35,14 +39,13 @@ class GetGroupMemberInfo extends BaseAction { logDebug('获取群成员详细信息失败, 只能返回基础信息', e); } const retMember = OB11Constructor.groupMember(payload.group_id.toString(), member); - for (let i = 0, len = WebGroupMember.length; i < len; i++) { - if (WebGroupMember[i]?.uin && WebGroupMember[i].uin === retMember.user_id) { - retMember.join_time = WebGroupMember[i]?.join_time; - retMember.last_sent_time = WebGroupMember[i]?.last_speak_time; - retMember.qage = WebGroupMember[i]?.qage; - retMember.level = WebGroupMember[i]?.lv.level; + for (let i = 0, len = webGroupMembers.length; i < len; i++) { + if (webGroupMembers[i]?.uin && webGroupMembers[i].uin === retMember.user_id) { + retMember.join_time = webGroupMembers[i]?.join_time; + retMember.last_sent_time = webGroupMembers[i]?.last_speak_time; + retMember.qage = webGroupMembers[i]?.qage; + retMember.level = webGroupMembers[i]?.lv.level; } - } return retMember; } else { diff --git a/src/onebot11/action/group/GetGroupMemberList.ts b/src/onebot11/action/group/GetGroupMemberList.ts index c2285a5c..cf59f854 100644 --- a/src/onebot11/action/group/GetGroupMemberList.ts +++ b/src/onebot11/action/group/GetGroupMemberList.ts @@ -3,7 +3,7 @@ import { OB11GroupMember } from '../../types'; import { OB11Constructor } from '../../constructor'; import BaseAction from '../BaseAction'; import { ActionName } from '../types'; -import { napCatCore, NTQQGroupApi } from '@/core'; +import { napCatCore, NTQQGroupApi, WebApiGroupMember } from '@/core'; import { WebApi } from '@/core/apis/webapi'; import { logDebug } from '@/common/utils/log'; @@ -18,13 +18,14 @@ class GetGroupMemberList extends BaseAction { protected async _handle(payload: PayloadType) { const MemberMap: Map = new Map(); - const WebGroupMember = await WebApi.getGroupMembers(payload.group_id.toString()); + const webGroupMembers: WebApiGroupMember[] = []; // await NTQQGroupApi.getGroupMembers(payload.group_id.toString()); const group = await getGroup(payload.group_id.toString()); if (!group) { throw (`群${payload.group_id}不存在`); } if (payload.no_cache || payload.no_cache === 'true') { + // webGroupMembers = await WebApi.getGroupMembers(payload.group_id.toString()); const _groupMembers = await NTQQGroupApi.getGroupMembers(payload.group_id.toString()); groupMembers.set(group.groupCode, _groupMembers); } @@ -35,17 +36,17 @@ class GetGroupMemberList extends BaseAction { MemberMap.set(_groupMembers[i].user_id, _groupMembers[i]); } // 合并数据 - for (let i = 0, len = WebGroupMember.length; i < len; i++) { - if (!WebGroupMember[i]?.uin) { + for (let i = 0, len = webGroupMembers.length; i < len; i++) { + if (!webGroupMembers[i]?.uin) { continue; } - const MemberData = MemberMap.get(WebGroupMember[i]?.uin); + const MemberData = MemberMap.get(webGroupMembers[i]?.uin); if (MemberData) { - MemberData.join_time = WebGroupMember[i]?.join_time; - MemberData.last_sent_time = WebGroupMember[i]?.last_speak_time; - MemberData.qage = WebGroupMember[i]?.qage; - MemberData.level = WebGroupMember[i]?.lv.level; - MemberMap.set(WebGroupMember[i]?.uin, MemberData); + MemberData.join_time = webGroupMembers[i]?.join_time; + MemberData.last_sent_time = webGroupMembers[i]?.last_speak_time; + MemberData.qage = webGroupMembers[i]?.qage; + MemberData.level = webGroupMembers[i]?.lv.level; + MemberMap.set(webGroupMembers[i]?.uin, MemberData); } } // 还原Map到Array diff --git a/src/onebot11/server/ws/ReverseWebsocket.ts b/src/onebot11/server/ws/ReverseWebsocket.ts index 1fa0dedc..9c8762fd 100644 --- a/src/onebot11/server/ws/ReverseWebsocket.ts +++ b/src/onebot11/server/ws/ReverseWebsocket.ts @@ -101,7 +101,9 @@ export class ReverseWebsocket { await this.onmessage(data.toString()); }); - this.websocket.on('error', log); + this.websocket.on('error', (err) => { + logError('websocket error', err.toString()); + }); const wsClientInterval = setInterval(() => { postWsEvent(new OB11HeartbeatEvent(!!selfInfo.online, true, heartInterval));