From a41cd42e8deb66d673364bbf22f44ebfb64fc7a2 Mon Sep 17 00:00:00 2001 From: linyuchen Date: Sun, 5 May 2024 13:26:33 +0800 Subject: [PATCH] =?UTF-8?q?build-1.2.1-beta1,fix:=20webapi=E7=BE=A4?= =?UTF-8?q?=E6=88=90=E5=91=98=E5=88=97=E8=A1=A8=E5=8A=A0=E5=85=A5=E7=BC=93?= =?UTF-8?q?=E5=AD=98=EF=BC=8C=E8=A1=A8=E6=83=85=E5=9B=9E=E5=BA=94=E5=85=BC?= =?UTF-8?q?=E5=AE=B9int=E7=B1=BB=E5=9E=8Bemoji=5Fid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../action/group/GetGroupMemberInfo.ts | 21 ++++++++++++------- .../action/group/GetGroupMemberList.ts | 20 +++++++++--------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/onebot11/action/group/GetGroupMemberInfo.ts b/src/onebot11/action/group/GetGroupMemberInfo.ts index 9e013e7b..f9ae9901 100644 --- a/src/onebot11/action/group/GetGroupMemberInfo.ts +++ b/src/onebot11/action/group/GetGroupMemberInfo.ts @@ -1,5 +1,5 @@ import { OB11GroupMember } from '../../types'; -import { getGroup, getGroupMember } from '@/core/data'; +import { getGroup, getGroupMember, groupMembers } from '@/core/data'; import { OB11Constructor } from '../../constructor'; import BaseAction from '../BaseAction'; import { ActionName } from '../types'; @@ -7,11 +7,13 @@ 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 { NTQQGroupApi } from '@/core'; export interface PayloadType { group_id: number; user_id: number; + no_cache?: boolean | string; } class GetGroupMemberInfo extends BaseAction { @@ -22,7 +24,10 @@ class GetGroupMemberInfo extends BaseAction { if (!group) { throw (`群(${payload.group_id})不存在`); } - const WebGroupMember = await WebApi.getGroupMembers(payload.group_id.toString()); + const webGroupMembers = await WebApi.getGroupMembers(payload.group_id.toString()); + if (payload.no_cache == true || payload.no_cache === 'true') { + groupMembers.set(group.groupCode, await NTQQGroupApi.getGroupMembers(payload.group_id.toString())); + } const member = await getGroupMember(payload.group_id.toString(), payload.user_id.toString()); // log(member); if (member) { @@ -35,12 +40,12 @@ 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; } } diff --git a/src/onebot11/action/group/GetGroupMemberList.ts b/src/onebot11/action/group/GetGroupMemberList.ts index 4281f68d..ad2acb23 100644 --- a/src/onebot11/action/group/GetGroupMemberList.ts +++ b/src/onebot11/action/group/GetGroupMemberList.ts @@ -18,12 +18,12 @@ 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 = await WebApi.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') { + if (payload.no_cache == true || 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 +35,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