@@ -341,7 +341,7 @@ export class NTQQGroupApi {
|
||||
return undefined;
|
||||
}
|
||||
if (isNumeric(memberUinOrUidStr)) {
|
||||
return Array.from(members.values()).find(member => member.uin === memberUinOrUidStr);
|
||||
return Array.from(members.values()).find(member => member.uin?.toString() === memberUinOrUidStr);
|
||||
} else {
|
||||
return members.get(memberUinOrUidStr);
|
||||
}
|
||||
@@ -360,7 +360,7 @@ export class NTQQGroupApi {
|
||||
getUidFromMemberCache (uin: string) {
|
||||
for (const members of this.groupMemberCache.values()) {
|
||||
for (const [uid, member] of members) {
|
||||
if (member.uin === uin) {
|
||||
if (member.uin?.toString() === uin) {
|
||||
return uid;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,28 +38,31 @@ class GetGroupMemberInfo extends OneBotAction<PayloadType, ReturnType> {
|
||||
return uid;
|
||||
}
|
||||
|
||||
private async getGroupMemberInfo (payload: PayloadType, uid: string, isNocache: boolean) {
|
||||
const groupMemberCache = this.core.apis.GroupApi.groupMemberCache.get(payload.group_id.toString());
|
||||
const groupMember = groupMemberCache?.get(uid);
|
||||
private async getGroupMemberInfo (payload: PayloadType, isNocache: boolean) {
|
||||
const groupId = payload.group_id.toString();
|
||||
// 全局 UIN -> UID 转换可能与目标群的成员记录不一致,优先按 QQ 号在本群查询。
|
||||
// getGroupMember 会在缓存未命中时刷新一次,避免冷缓存被误判为成员不存在。
|
||||
const groupMember = await this.core.apis.GroupApi.getGroupMember(groupId, payload.user_id);
|
||||
const uid = groupMember?.uid || await this.getUid(payload.user_id);
|
||||
|
||||
const [member, info] = await Promise.all([
|
||||
this.core.apis.GroupApi.getGroupMemberEx(payload.group_id.toString(), uid, isNocache),
|
||||
this.core.apis.UserApi.getUserDetailInfo(uid, isNocache),
|
||||
this.core.apis.GroupApi.getGroupMemberEx(groupId, uid, isNocache),
|
||||
this.core.apis.UserApi.getUserDetailInfo(uid, isNocache).catch((error) => {
|
||||
this.core.context.logger.logDebug(`获取群成员补充资料失败, 群号: ${groupId}, QQ号: ${payload.user_id}, 错误: ${error}`);
|
||||
return undefined;
|
||||
}),
|
||||
]);
|
||||
|
||||
if (!member || !groupMember) throw new Error(`群(${payload.group_id})成员${payload.user_id}不存在`);
|
||||
const baseMember = member ?? groupMember;
|
||||
if (!baseMember) throw new Error(`群(${payload.group_id})成员${payload.user_id}不存在`);
|
||||
|
||||
return info ? { ...groupMember, ...member, ...info } : member;
|
||||
// 个人资料只补充信息,不能覆盖已确认的群成员身份。
|
||||
return { ...groupMember, ...baseMember, ...info, uid: baseMember.uid, uin: baseMember.uin };
|
||||
}
|
||||
|
||||
async _handle (payload: PayloadType) {
|
||||
const isNocache = this.parseBoolean(payload.no_cache ?? true);
|
||||
const uid = await this.getUid(payload.user_id);
|
||||
const member = await this.getGroupMemberInfo(payload, uid, isNocache);
|
||||
|
||||
if (!member) {
|
||||
this.core.context.logger.logDebug('获取群成员详细信息失败, 只能返回基础信息');
|
||||
}
|
||||
const member = await this.getGroupMemberInfo(payload, isNocache);
|
||||
|
||||
return OB11Construct.groupMember(payload.group_id.toString(), member);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// @ts-nocheck
|
||||
import { MessageType, PartialMessage, RepeatType, ScalarType } from '@protobuf-ts/runtime';
|
||||
import { BinaryReader, MessageType, PartialMessage, RepeatType, ScalarType } from '@protobuf-ts/runtime';
|
||||
import { PartialFieldInfo } from '@protobuf-ts/runtime/build/types/reflection-info';
|
||||
|
||||
export type LowerCamelCase<S extends string> = CamelCaseHelper<S, false, true>;
|
||||
@@ -179,7 +179,11 @@ class NapProtoRealMsg<T extends ProtoMessageType> {
|
||||
}
|
||||
|
||||
decode (data: Uint8Array): NapProtoDecodeStructType<T> {
|
||||
return this._proto_msg.fromBinary(data) as NapProtoDecodeStructType<T>;
|
||||
return this._proto_msg.fromBinary(data, {
|
||||
// QQ may send truncated UTF-8 in names. Replace invalid characters without
|
||||
// dropping the whole packet; retain BinaryReader's bounds checks and BOM handling.
|
||||
readerFactory: bytes => new BinaryReader(bytes, new TextDecoder('utf-8', { fatal: false, ignoreBOM: true })),
|
||||
}) as NapProtoDecodeStructType<T>;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user