fix(onebot): restore group and doubt request accounts
get_group_system_msg now keeps join and invite records, reports the inviter, and fills a missing requester nick from the user profile. get_doubt_friends_add_request returns the QQ number plus the request message, source, and time that QQ actually sends. Closes #400 Closes #401 Closes #402 Closes #403
This commit is contained in:
13 files changed
+418
-79
No files matched your search
@@ -996,12 +996,10 @@ export const actions = [
|
||||
params: {
|
||||
nickname: f.string().optional(),
|
||||
personal_note: f.string().optional(),
|
||||
sex: f.int({ min: 0, max: 2 }).optional().describe('0 未知,1 男,2 女'),
|
||||
},
|
||||
run: async (p, ctx) => {
|
||||
const nickname = p.nickname;
|
||||
const personalNote = p.personal_note;
|
||||
|
||||
await ctx.bridge.apis.profile.setProfile(nickname, personalNote);
|
||||
await ctx.bridge.apis.profile.setProfile(p.nickname, p.personal_note, p.sex);
|
||||
return okResponse();
|
||||
},
|
||||
}),
|
||||
@@ -1400,6 +1398,41 @@ export const actions = [
|
||||
},
|
||||
}),
|
||||
|
||||
defineAction({
|
||||
name: 'get_msg_emoji_likes',
|
||||
summary: '获取一条消息的全部表情回应',
|
||||
readOnly: true,
|
||||
returns: '该消息上每个表情回应的编号、数量与用户列表。',
|
||||
returnsSchema: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
emoji_id: { type: 'string', description: '表情编号' },
|
||||
emoji_type: { type: 'integer', description: '表情类型' },
|
||||
count: { type: 'integer', description: '回应数量' },
|
||||
last_reaction_time: { type: 'integer', description: '最近一次回应时间' },
|
||||
users: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: { user_id: { type: 'integer', description: '用户 QQ 号' } },
|
||||
required: ['user_id'],
|
||||
},
|
||||
},
|
||||
},
|
||||
required: ['emoji_id', 'emoji_type', 'count', 'last_reaction_time', 'users'],
|
||||
},
|
||||
},
|
||||
params: { message_id: f.messageId() },
|
||||
run: async (p, ctx) => {
|
||||
if (!ctx.fetchEmojiLikeSummary) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'emoji reaction summary is unavailable');
|
||||
}
|
||||
return okResponse(await ctx.fetchEmojiLikeSummary(p.message_id));
|
||||
},
|
||||
}),
|
||||
|
||||
defineAction({
|
||||
name: 'get_friends_with_category',
|
||||
summary: '获取分组好友列表',
|
||||
@@ -1746,12 +1779,15 @@ export const actions = [
|
||||
type: 'object',
|
||||
properties: {
|
||||
uid: { type: 'string', description: '申请人 uid(回传作 set_doubt_friends_add_request 的 flag)' },
|
||||
user_id: { type: 'integer', description: '申请人 QQ 号' },
|
||||
nick: { type: 'string', description: '申请人昵称' },
|
||||
source: { type: 'string', description: '申请来源' },
|
||||
reason: { type: 'string', description: '附加说明' },
|
||||
msg: { type: 'string', description: '验证留言' },
|
||||
group_code: { type: 'string', description: '来源群号,无则为空串' },
|
||||
reqTime: { type: 'integer', description: '申请时间戳' },
|
||||
},
|
||||
required: ['uid', 'nick', 'source', 'msg', 'reqTime'],
|
||||
required: ['uid', 'user_id', 'nick', 'source', 'reason', 'msg', 'group_code', 'reqTime'],
|
||||
},
|
||||
},
|
||||
params: { count: f.int({ min: 0 }).default(50) },
|
||||
|
||||
@@ -224,13 +224,16 @@ export const actions = [
|
||||
request_id: { type: 'integer', description: '请求序列号' },
|
||||
requester_uin: { type: 'integer', description: '申请人 QQ 号' },
|
||||
requester_nick: { type: 'string', description: '申请人昵称' },
|
||||
invitor_uin: { type: 'integer', description: '邀请人 QQ 号,无邀请时为 0' },
|
||||
invitor_nick: { type: 'string', description: '邀请人昵称' },
|
||||
message: { type: 'string', description: '验证留言' },
|
||||
checked: { type: 'boolean', description: '是否已处理' },
|
||||
flag: { type: 'string', description: '处理请求使用的规范 flag' },
|
||||
},
|
||||
required: [
|
||||
'group_id', 'group_name', 'request_id', 'requester_uin',
|
||||
'requester_nick', 'message', 'checked', 'flag',
|
||||
'requester_nick', 'invitor_uin', 'invitor_nick',
|
||||
'message', 'checked', 'flag',
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
@@ -280,35 +280,39 @@ export async function getGroupFiles(
|
||||
};
|
||||
}
|
||||
|
||||
function formatStrangerInfo(p: UserProfileInfo): JsonObject {
|
||||
return {
|
||||
user_id: p.uin,
|
||||
nickname: p.nickname,
|
||||
remark: p.remark,
|
||||
sex: p.sex,
|
||||
age: p.age,
|
||||
long_nick: p.sign,
|
||||
qq_level: p.level,
|
||||
level: p.level,
|
||||
status: p.status ?? 0,
|
||||
extStatus: p.extStatus ?? 0,
|
||||
ext_status: p.extStatus ?? 0,
|
||||
batteryStatus: p.batteryStatus ?? 0,
|
||||
customStatus: p.customStatus ?? null,
|
||||
customStatusDescInfo: p.customStatusDesc ?? '',
|
||||
};
|
||||
}
|
||||
|
||||
export async function getStrangerInfo(
|
||||
bridge: BridgeInterface,
|
||||
userId: number,
|
||||
): Promise<JsonObject | null> {
|
||||
try {
|
||||
const p = await bridge.apis.contacts.fetchUserProfile(userId);
|
||||
return {
|
||||
user_id: p.uin,
|
||||
nickname: p.nickname,
|
||||
remark: p.remark,
|
||||
sex: p.sex,
|
||||
age: p.age,
|
||||
long_nick: p.sign,
|
||||
qq_level: p.level,
|
||||
level: p.level,
|
||||
};
|
||||
return formatStrangerInfo(p);
|
||||
} catch {
|
||||
const p = bridge.identity.findUserProfile(userId);
|
||||
if (p) {
|
||||
return {
|
||||
user_id: p.uin,
|
||||
nickname: p.nickname,
|
||||
return formatStrangerInfo({
|
||||
...p,
|
||||
remark: p.remark || bridge.identity.findFriend(userId)?.remark || '',
|
||||
sex: p.sex,
|
||||
age: p.age,
|
||||
long_nick: p.sign,
|
||||
qq_level: p.level,
|
||||
level: p.level,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
const friend = bridge.identity.findFriend(userId);
|
||||
@@ -327,24 +331,33 @@ export async function getStrangerInfo(
|
||||
async function resolveRequesterUins(
|
||||
bridge: BridgeInterface,
|
||||
requests: readonly GroupRequestInfo[],
|
||||
): Promise<Map<string, number>> {
|
||||
const resolved = new Map<string, number>();
|
||||
): Promise<Map<string, { uin: number; name: string }>> {
|
||||
const resolved = new Map<string, { uin: number; name: string }>();
|
||||
const unresolved = new Set<string>();
|
||||
const names = new Map<string, string>();
|
||||
const unresolvedUins = new Set<number>();
|
||||
|
||||
for (const request of requests) {
|
||||
const actor = groupRequestActor(request);
|
||||
const uid = actor.uid;
|
||||
if (!uid || resolved.has(uid)) continue;
|
||||
if (actor.uin > 0) {
|
||||
resolved.set(uid, actor.uin);
|
||||
if (actor.name) names.set(uid || `uin:${actor.uin}`, actor.name);
|
||||
if (uid && actor.uin > 0 && actor.name) {
|
||||
resolved.set(uid, { uin: actor.uin, name: actor.name });
|
||||
unresolved.delete(uid);
|
||||
continue;
|
||||
}
|
||||
if (unresolved.has(uid)) continue;
|
||||
const cached = bridge.identity.findUinByUid(uid, request.groupId)
|
||||
?? bridge.identity.findUinByUid(uid);
|
||||
if (cached && cached > 0) resolved.set(uid, cached);
|
||||
else unresolved.add(uid);
|
||||
if (uid) {
|
||||
if (resolved.has(uid) || unresolved.has(uid)) continue;
|
||||
const cached = bridge.identity.findUinByUid(uid, request.groupId)
|
||||
?? bridge.identity.findUinByUid(uid);
|
||||
if (cached && cached > 0 && actor.name) {
|
||||
resolved.set(uid, { uin: cached, name: actor.name });
|
||||
} else {
|
||||
unresolved.add(uid);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (actor.uin > 0 && !actor.name) unresolvedUins.add(actor.uin);
|
||||
}
|
||||
|
||||
const profiles = await mapWithConcurrency(
|
||||
@@ -361,13 +374,43 @@ async function resolveRequesterUins(
|
||||
if (!Number.isSafeInteger(profile.uin) || profile.uin <= 0) {
|
||||
throw new Error(`failed to resolve requester UIN for UID ${uid}`);
|
||||
}
|
||||
return [uid, profile.uin] as const;
|
||||
return [uid, profile] as const;
|
||||
},
|
||||
);
|
||||
for (const [uid, uin] of profiles) resolved.set(uid, uin);
|
||||
for (const [uid, profile] of profiles) {
|
||||
resolved.set(uid, {
|
||||
uin: profile.uin,
|
||||
name: names.get(uid) || profile.nickname || '',
|
||||
});
|
||||
}
|
||||
|
||||
const uinProfiles = await mapWithConcurrency(
|
||||
[...unresolvedUins],
|
||||
REQUESTER_PROFILE_CONCURRENCY,
|
||||
async (uin) => {
|
||||
try {
|
||||
return [uin, await bridge.apis.contacts.fetchUserProfile(uin)] as const;
|
||||
} catch {
|
||||
return [uin, undefined] as const;
|
||||
}
|
||||
},
|
||||
);
|
||||
for (const [uin, profile] of uinProfiles) {
|
||||
if (!profile) continue;
|
||||
resolved.set(`uin:${uin}`, { uin: profile.uin, name: profile.nickname || '' });
|
||||
}
|
||||
return resolved;
|
||||
}
|
||||
|
||||
/** Join request (7) or invite that still needs an admin (5 / mapped 22). */
|
||||
function isJoinOrInviteNotify(notifyType: number | undefined): boolean {
|
||||
return notifyType === undefined
|
||||
|| notifyType === 1
|
||||
|| notifyType === 5
|
||||
|| notifyType === 7
|
||||
|| notifyType === 22;
|
||||
}
|
||||
|
||||
function groupRequestActor(request: GroupRequestInfo): {
|
||||
uid: string;
|
||||
uin: number;
|
||||
@@ -401,9 +444,7 @@ export async function getGroupSystemMessages(
|
||||
]);
|
||||
const unique = new Map<string, GroupRequestInfo>();
|
||||
for (const request of [...main, ...filtered]) {
|
||||
if (request.notifyType !== undefined
|
||||
&& request.notifyType !== 1
|
||||
&& request.notifyType !== 7) continue;
|
||||
if (!isJoinOrInviteNotify(request.notifyType)) continue;
|
||||
if (request.eventType <= 0) continue;
|
||||
const flag = formatGroupRequestFlag(request);
|
||||
if (!unique.has(flag)) unique.set(flag, request);
|
||||
@@ -417,12 +458,16 @@ export async function getGroupSystemMessages(
|
||||
|
||||
return requests.map((request) => {
|
||||
const actor = groupRequestActor(request);
|
||||
const resolved = (actor.uid ? requesterUins.get(actor.uid) : undefined)
|
||||
?? (actor.uin > 0 ? requesterUins.get(`uin:${actor.uin}`) : undefined);
|
||||
return {
|
||||
group_id: request.groupId,
|
||||
group_name: request.groupName,
|
||||
request_id: request.sequence,
|
||||
requester_uin: requesterUins.get(actor.uid) ?? actor.uin,
|
||||
requester_nick: actor.name,
|
||||
requester_uin: resolved?.uin ?? actor.uin,
|
||||
requester_nick: resolved?.name || actor.name,
|
||||
invitor_uin: request.invitorUin,
|
||||
invitor_nick: request.invitorName,
|
||||
message: request.comment,
|
||||
checked: request.state !== 1,
|
||||
flag: formatGroupRequestFlag(request),
|
||||
|
||||
Reference in new issue
Block a user