fix(onebot): distinguish group invitation identities
Expose joining members, inviters and request operators separately. Preserve existing notice fields and report unavailable invitation identities explicitly. Refs #643
This commit is contained in:
20 files changed
+853
-63
No files matched your search
@@ -10003,7 +10003,7 @@
|
||||
"name": "get_group_system_msg",
|
||||
"aliases": [],
|
||||
"summary": "获取群系统消息",
|
||||
"returns": "群系统消息数组,可按群号或未处理状态过滤。",
|
||||
"returns": "群系统消息数组,分别提供入群者、邀请人和处理者,可按群号或未处理状态过滤。身份为 0 时须查看状态;未知不代表不存在邀请人。",
|
||||
"returnsSchema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
@@ -10023,20 +10023,60 @@
|
||||
},
|
||||
"requester_uin": {
|
||||
"type": "integer",
|
||||
"description": "申请人 QQ 号"
|
||||
"description": "请求发起人 QQ 号;邀请登录账号入群时表示邀请人"
|
||||
},
|
||||
"requester_nick": {
|
||||
"type": "string",
|
||||
"description": "申请人昵称"
|
||||
"description": "请求发起人昵称"
|
||||
},
|
||||
"target_uin": {
|
||||
"type": "integer",
|
||||
"description": "申请或被邀请入群者 QQ 号,未知时为 0"
|
||||
},
|
||||
"target_nick": {
|
||||
"type": "string",
|
||||
"description": "入群者昵称"
|
||||
},
|
||||
"target_status": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"known",
|
||||
"unknown"
|
||||
],
|
||||
"description": "入群者 QQ 号是否已知"
|
||||
},
|
||||
"invitor_uin": {
|
||||
"type": "integer",
|
||||
"description": "邀请人 QQ 号,无邀请时为 0"
|
||||
"description": "邀请人 QQ 号,未知时为 0;不能据此认定没有邀请人"
|
||||
},
|
||||
"invitor_nick": {
|
||||
"type": "string",
|
||||
"description": "邀请人昵称"
|
||||
},
|
||||
"invitor_status": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"known",
|
||||
"unknown"
|
||||
],
|
||||
"description": "邀请人 QQ 号是否已知;缺失信息为 unknown"
|
||||
},
|
||||
"operator_uin": {
|
||||
"type": "integer",
|
||||
"description": "处理该申请的操作者 QQ 号,未知时为 0"
|
||||
},
|
||||
"operator_nick": {
|
||||
"type": "string",
|
||||
"description": "处理者昵称"
|
||||
},
|
||||
"operator_status": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"known",
|
||||
"unknown"
|
||||
],
|
||||
"description": "处理者 QQ 号是否已知;已知不代表审批通过"
|
||||
},
|
||||
"message": {
|
||||
"type": "string",
|
||||
"description": "验证留言"
|
||||
@@ -10056,8 +10096,15 @@
|
||||
"request_id",
|
||||
"requester_uin",
|
||||
"requester_nick",
|
||||
"target_uin",
|
||||
"target_nick",
|
||||
"target_status",
|
||||
"invitor_uin",
|
||||
"invitor_nick",
|
||||
"invitor_status",
|
||||
"operator_uin",
|
||||
"operator_nick",
|
||||
"operator_status",
|
||||
"message",
|
||||
"checked",
|
||||
"flag"
|
||||
|
||||
@@ -10006,7 +10006,7 @@ export const ACTIONS: CatalogAction[] = [
|
||||
"name": "get_group_system_msg",
|
||||
"aliases": [],
|
||||
"summary": "获取群系统消息",
|
||||
"returns": "群系统消息数组,可按群号或未处理状态过滤。",
|
||||
"returns": "群系统消息数组,分别提供入群者、邀请人和处理者,可按群号或未处理状态过滤。身份为 0 时须查看状态;未知不代表不存在邀请人。",
|
||||
"returnsSchema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
@@ -10026,20 +10026,60 @@ export const ACTIONS: CatalogAction[] = [
|
||||
},
|
||||
"requester_uin": {
|
||||
"type": "integer",
|
||||
"description": "申请人 QQ 号"
|
||||
"description": "请求发起人 QQ 号;邀请登录账号入群时表示邀请人"
|
||||
},
|
||||
"requester_nick": {
|
||||
"type": "string",
|
||||
"description": "申请人昵称"
|
||||
"description": "请求发起人昵称"
|
||||
},
|
||||
"target_uin": {
|
||||
"type": "integer",
|
||||
"description": "申请或被邀请入群者 QQ 号,未知时为 0"
|
||||
},
|
||||
"target_nick": {
|
||||
"type": "string",
|
||||
"description": "入群者昵称"
|
||||
},
|
||||
"target_status": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"known",
|
||||
"unknown"
|
||||
],
|
||||
"description": "入群者 QQ 号是否已知"
|
||||
},
|
||||
"invitor_uin": {
|
||||
"type": "integer",
|
||||
"description": "邀请人 QQ 号,无邀请时为 0"
|
||||
"description": "邀请人 QQ 号,未知时为 0;不能据此认定没有邀请人"
|
||||
},
|
||||
"invitor_nick": {
|
||||
"type": "string",
|
||||
"description": "邀请人昵称"
|
||||
},
|
||||
"invitor_status": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"known",
|
||||
"unknown"
|
||||
],
|
||||
"description": "邀请人 QQ 号是否已知;缺失信息为 unknown"
|
||||
},
|
||||
"operator_uin": {
|
||||
"type": "integer",
|
||||
"description": "处理该申请的操作者 QQ 号,未知时为 0"
|
||||
},
|
||||
"operator_nick": {
|
||||
"type": "string",
|
||||
"description": "处理者昵称"
|
||||
},
|
||||
"operator_status": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"known",
|
||||
"unknown"
|
||||
],
|
||||
"description": "处理者 QQ 号是否已知;已知不代表审批通过"
|
||||
},
|
||||
"message": {
|
||||
"type": "string",
|
||||
"description": "验证留言"
|
||||
@@ -10059,8 +10099,15 @@ export const ACTIONS: CatalogAction[] = [
|
||||
"request_id",
|
||||
"requester_uin",
|
||||
"requester_nick",
|
||||
"target_uin",
|
||||
"target_nick",
|
||||
"target_status",
|
||||
"invitor_uin",
|
||||
"invitor_nick",
|
||||
"invitor_status",
|
||||
"operator_uin",
|
||||
"operator_nick",
|
||||
"operator_status",
|
||||
"message",
|
||||
"checked",
|
||||
"flag"
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
# 群邀请与入群身份
|
||||
|
||||
成员 A 邀请 B,管理员 C 审批时,邀请人、入群者与处理者是三个独立身份。
|
||||
不要把 `group_increase.operator_id` 当成邀请人,也不要仅凭 `sub_type: invite` 推断两者相同。
|
||||
|
||||
## 入群通知
|
||||
|
||||
`group_increase` 保留原有的 `user_id`、`operator_id` 和 `sub_type`,增加:
|
||||
|
||||
| 字段 | 含义 |
|
||||
| --- | --- |
|
||||
| `invitor_id` | QQ 明确提供的独立邀请人 QQ 号;无法确定时为 `0` |
|
||||
| `invitor_status` | `known` 表示邀请人 QQ 号已知;`unknown` 表示无法确定 |
|
||||
|
||||
部分审批入群推送提供独立邀请人信息,SnowLuma 从该推送读取并解析身份。
|
||||
二维码分享者与邀请人分开处理;旧式推送、自身入群通知或缺少来源信息的通知保留 `unknown`。
|
||||
不会按同群、同成员或时间接近程度猜测邀请关系,也不会用操作者填充邀请人。
|
||||
身份查询失败会留下日志,入群事件仍按现有策略上报,未知邀请人不阻断通知。
|
||||
|
||||
## 群申请列表
|
||||
|
||||
`get_group_system_msg` 返回的每条记录增加以下字段:
|
||||
|
||||
| 字段 | 含义 |
|
||||
| --- | --- |
|
||||
| `target_uin`、`target_nick` | 申请或被邀请入群者,始终表示 B |
|
||||
| `operator_uin`、`operator_nick` | 处理该申请的操作者;审批场景中表示 C |
|
||||
| `target_status`、`invitor_status`、`operator_status` | 对应 QQ 号为 `known` 或 `unknown` |
|
||||
|
||||
原有 `invitor_uin`、`invitor_nick` 表示 A。`requester_uin` 保持兼容:普通申请表示申请人,
|
||||
邀请登录账号入群的记录则表示邀请人。需要区分三方时,应使用 `target_uin`、`invitor_uin`、`operator_uin`。
|
||||
QQ 只提供 UID 时会查询对应 QQ 号,查询去重并限制并发;查询错误会返回接口错误,不伪装成空列表。
|
||||
|
||||
```json
|
||||
{
|
||||
"target_uin": 10002,
|
||||
"target_status": "known",
|
||||
"invitor_uin": 10004,
|
||||
"invitor_status": "known",
|
||||
"operator_uin": 10003,
|
||||
"operator_status": "known",
|
||||
"checked": true
|
||||
}
|
||||
```
|
||||
|
||||
**`0` 或 `unknown` 不代表“没有邀请人”。** QQ 未提供身份、记录不可见、身份尚未解析等情况均不能证明没有邀请人。
|
||||
当前已确认的字段不足以对缺失信息可靠作出“无邀请人”的判断,因此不输出这种推断。
|
||||
同样,`checked: true` 只表示已处理,不代表必然审批通过;`operator_uin` 也可能是拒绝请求的人。
|
||||
|
||||
`count` 限制每个收件箱读取的记录数(最多 100);`group_id` 在读取后过滤,
|
||||
并非查询指定群的完整历史。`only_pending` 默认为 `false`。空数组表示本次读取范围内没有匹配记录,
|
||||
不能证明某次入群没有邀请人。调试日志会分别记录收件箱数量、类型筛选和最终筛选数量。
|
||||
|
||||
SDK 的 `getGroupSystemMessages()` 提供相应类型。新增字段在 SDK 中可选,以兼容旧服务端;
|
||||
连接旧服务端时,缺失的状态也应视为未知。
|
||||
@@ -577,7 +577,8 @@ export const actions = [
|
||||
],
|
||||
summary: '获取群系统消息',
|
||||
readOnly: true,
|
||||
returns: '群系统消息数组,可按群号或未处理状态过滤。',
|
||||
returns:
|
||||
'群系统消息数组,分别提供入群者、邀请人和处理者,可按群号或未处理状态过滤。身份为 0 时须查看状态;未知不代表不存在邀请人。',
|
||||
returnsSchema: {
|
||||
type: 'array',
|
||||
items: {
|
||||
@@ -586,10 +587,41 @@ export const actions = [
|
||||
group_id: { type: 'integer', description: '群号' },
|
||||
group_name: { type: 'string', description: '群名称' },
|
||||
request_id: { type: 'integer', description: '请求序列号' },
|
||||
requester_uin: { type: 'integer', description: '申请人 QQ 号' },
|
||||
requester_nick: { type: 'string', description: '申请人昵称' },
|
||||
invitor_uin: { type: 'integer', description: '邀请人 QQ 号,无邀请时为 0' },
|
||||
requester_uin: {
|
||||
type: 'integer',
|
||||
description: '请求发起人 QQ 号;邀请登录账号入群时表示邀请人',
|
||||
},
|
||||
requester_nick: { type: 'string', description: '请求发起人昵称' },
|
||||
target_uin: {
|
||||
type: 'integer',
|
||||
description: '申请或被邀请入群者 QQ 号,未知时为 0',
|
||||
},
|
||||
target_nick: { type: 'string', description: '入群者昵称' },
|
||||
target_status: {
|
||||
type: 'string',
|
||||
enum: ['known', 'unknown'],
|
||||
description: '入群者 QQ 号是否已知',
|
||||
},
|
||||
invitor_uin: {
|
||||
type: 'integer',
|
||||
description: '邀请人 QQ 号,未知时为 0;不能据此认定没有邀请人',
|
||||
},
|
||||
invitor_nick: { type: 'string', description: '邀请人昵称' },
|
||||
invitor_status: {
|
||||
type: 'string',
|
||||
enum: ['known', 'unknown'],
|
||||
description: '邀请人 QQ 号是否已知;缺失信息为 unknown',
|
||||
},
|
||||
operator_uin: {
|
||||
type: 'integer',
|
||||
description: '处理该申请的操作者 QQ 号,未知时为 0',
|
||||
},
|
||||
operator_nick: { type: 'string', description: '处理者昵称' },
|
||||
operator_status: {
|
||||
type: 'string',
|
||||
enum: ['known', 'unknown'],
|
||||
description: '处理者 QQ 号是否已知;已知不代表审批通过',
|
||||
},
|
||||
message: { type: 'string', description: '验证留言' },
|
||||
checked: { type: 'boolean', description: '是否已处理' },
|
||||
flag: { type: 'string', description: '处理请求使用的规范 flag' },
|
||||
@@ -600,8 +632,15 @@ export const actions = [
|
||||
'request_id',
|
||||
'requester_uin',
|
||||
'requester_nick',
|
||||
'target_uin',
|
||||
'target_nick',
|
||||
'target_status',
|
||||
'invitor_uin',
|
||||
'invitor_nick',
|
||||
'invitor_status',
|
||||
'operator_uin',
|
||||
'operator_nick',
|
||||
'operator_status',
|
||||
'message',
|
||||
'checked',
|
||||
'flag',
|
||||
|
||||
@@ -35,6 +35,8 @@ export function convertGroupMemberJoin(ctx: ConverterContext, event: GroupMember
|
||||
group_id: event.groupId,
|
||||
operator_id: event.operatorUin,
|
||||
user_id: event.userUin,
|
||||
invitor_id: event.invitorUin ?? 0,
|
||||
invitor_status: (event.invitorUin ?? 0) > 0 ? 'known' : 'unknown',
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -491,26 +491,46 @@ export async function getStrangerInfo(
|
||||
}
|
||||
}
|
||||
|
||||
async function resolveRequesterUins(
|
||||
async function resolveGroupRequestUins(
|
||||
bridge: BridgeInterface,
|
||||
requests: readonly GroupRequestInfo[],
|
||||
): 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 roles = new Map<string, string>();
|
||||
const unresolvedUins = new Set<number>();
|
||||
|
||||
for (const request of requests) {
|
||||
const actor = groupRequestActor(request);
|
||||
const actors = requests.flatMap((request) =>
|
||||
(['target', 'invitor', 'operator'] as const).map((role) => ({
|
||||
...groupRequestPerson(request, role),
|
||||
groupId: request.groupId,
|
||||
role,
|
||||
})),
|
||||
);
|
||||
|
||||
for (const actor of actors) {
|
||||
const uid = actor.uid;
|
||||
|
||||
if (uid) {
|
||||
roles.set(uid, actor.role === 'target' ? 'requester' : actor.role);
|
||||
}
|
||||
|
||||
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);
|
||||
if (actor.uin > 0) {
|
||||
resolved.set(uid || `uin:${actor.uin}`, { uin: actor.uin, name: actor.name });
|
||||
|
||||
if (uid) {
|
||||
unresolved.delete(uid);
|
||||
}
|
||||
|
||||
if (!actor.name) {
|
||||
unresolvedUins.add(actor.uin);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -520,21 +540,21 @@ async function resolveRequesterUins(
|
||||
}
|
||||
|
||||
const cached =
|
||||
bridge.identity.findUinByUid(uid, request.groupId) ??
|
||||
bridge.identity.findUinByUid(uid, actor.groupId) ??
|
||||
bridge.identity.findUinByUid(uid);
|
||||
|
||||
if (cached && cached > 0 && actor.name) {
|
||||
if (cached && cached > 0) {
|
||||
resolved.set(uid, { uin: cached, name: actor.name });
|
||||
|
||||
if (!actor.name) {
|
||||
unresolvedUins.add(cached);
|
||||
}
|
||||
} else {
|
||||
unresolved.add(uid);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (actor.uin > 0 && !actor.name) {
|
||||
unresolvedUins.add(actor.uin);
|
||||
}
|
||||
}
|
||||
|
||||
const profiles = await mapWithConcurrency(
|
||||
@@ -547,13 +567,16 @@ async function resolveRequesterUins(
|
||||
profile = await bridge.apis.contacts.fetchUserProfileByUid(uid);
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
throw new Error(`failed to resolve requester UIN for UID ${uid}: ${message}`, {
|
||||
cause: error,
|
||||
});
|
||||
throw new Error(
|
||||
`failed to resolve ${roles.get(uid)} UIN for UID ${uid}: ${message}`,
|
||||
{
|
||||
cause: error,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
if (!Number.isSafeInteger(profile.uin) || profile.uin <= 0) {
|
||||
throw new Error(`failed to resolve requester UIN for UID ${uid}`);
|
||||
throw new Error(`failed to resolve ${roles.get(uid)} UIN for UID ${uid}`);
|
||||
}
|
||||
|
||||
return [uid, profile] as const;
|
||||
@@ -573,7 +596,12 @@ async function resolveRequesterUins(
|
||||
async (uin) => {
|
||||
try {
|
||||
return [uin, await bridge.apis.contacts.fetchUserProfile(uin)] as const;
|
||||
} catch {
|
||||
} catch (error) {
|
||||
log.warn(
|
||||
'group request actor nickname unavailable: uin=%d error=%s',
|
||||
uin,
|
||||
error instanceof Error ? error.message : String(error),
|
||||
);
|
||||
return [uin, undefined] as const;
|
||||
}
|
||||
},
|
||||
@@ -590,23 +618,18 @@ async function resolveRequesterUins(
|
||||
return resolved;
|
||||
}
|
||||
|
||||
function groupRequestActor(request: GroupRequestInfo): {
|
||||
function groupRequestPerson(
|
||||
request: GroupRequestInfo,
|
||||
role: 'target' | 'invitor' | 'operator',
|
||||
): {
|
||||
uid: string;
|
||||
uin: number;
|
||||
name: string;
|
||||
} {
|
||||
if (isSelfGroupInvitation(request)) {
|
||||
return {
|
||||
uid: request.invitorUid,
|
||||
uin: request.invitorUin,
|
||||
name: request.invitorName,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
uid: request.targetUid,
|
||||
uin: request.targetUin,
|
||||
name: request.targetName,
|
||||
uid: request[`${role}Uid`],
|
||||
uin: request[`${role}Uin`],
|
||||
name: request[`${role}Name`],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -649,21 +672,47 @@ export async function getGroupSystemMessages(
|
||||
|
||||
return true;
|
||||
});
|
||||
const requesterUins = await resolveRequesterUins(bridge, requests);
|
||||
log.debug(
|
||||
'group request list: main=%d filtered=%d relevant=%d selected=%d group=%s onlyPending=%s',
|
||||
main.length,
|
||||
filtered.length,
|
||||
unique.size,
|
||||
requests.length,
|
||||
query.groupId ?? 'all',
|
||||
Boolean(query.onlyPending),
|
||||
);
|
||||
const actorUins = await resolveGroupRequestUins(bridge, requests);
|
||||
|
||||
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);
|
||||
const person = (role: 'target' | 'invitor' | 'operator') => {
|
||||
const actor = groupRequestPerson(request, role);
|
||||
const resolved =
|
||||
(actor.uid ? actorUins.get(actor.uid) : undefined) ??
|
||||
(actor.uin > 0 ? actorUins.get(`uin:${actor.uin}`) : undefined);
|
||||
const uin = actor.uin || resolved?.uin || 0;
|
||||
const name = actor.name || actorUins.get(`uin:${uin}`)?.name || resolved?.name || '';
|
||||
return { uin, name, status: uin > 0 ? 'known' : 'unknown' };
|
||||
};
|
||||
|
||||
const target = person('target');
|
||||
const invitor = person('invitor');
|
||||
const operator = person('operator');
|
||||
const requester = isSelfGroupInvitation(request) ? invitor : target;
|
||||
return {
|
||||
group_id: request.groupId,
|
||||
group_name: request.groupName,
|
||||
request_id: request.sequence,
|
||||
requester_uin: resolved?.uin ?? actor.uin,
|
||||
requester_nick: resolved?.name || actor.name,
|
||||
invitor_uin: request.invitorUin,
|
||||
invitor_nick: request.invitorName,
|
||||
requester_uin: requester.uin,
|
||||
requester_nick: requester.name,
|
||||
target_uin: target.uin,
|
||||
target_nick: target.name,
|
||||
target_status: target.status,
|
||||
invitor_uin: invitor.uin,
|
||||
invitor_nick: invitor.name,
|
||||
invitor_status: invitor.status,
|
||||
operator_uin: operator.uin,
|
||||
operator_nick: operator.name,
|
||||
operator_status: operator.status,
|
||||
message: request.comment,
|
||||
checked: request.state !== 1,
|
||||
flag: formatGroupRequestFlag(request),
|
||||
|
||||
@@ -1056,6 +1056,98 @@ describe('onebot/contact-actions / getStrangerInfo', () => {
|
||||
});
|
||||
|
||||
describe('onebot/contact-actions / getGroupSystemMessages', () => {
|
||||
it('reports the invitee, inviter and reviewing operator independently (#643)', async () => {
|
||||
const bridge = fakeBridge({
|
||||
fetchGroupRequests: vi.fn(async (filtered: boolean) =>
|
||||
filtered ? [] : [makeGroupRequest({ state: 2 })],
|
||||
),
|
||||
});
|
||||
expect(await getGroupSystemMessages(bridge)).toEqual([
|
||||
expect.objectContaining({
|
||||
requester_uin: 123,
|
||||
target_uin: 123,
|
||||
target_nick: 'target',
|
||||
target_status: 'known',
|
||||
invitor_uin: 456,
|
||||
invitor_nick: 'inviter',
|
||||
invitor_status: 'known',
|
||||
operator_uin: 789,
|
||||
operator_nick: 'operator',
|
||||
operator_status: 'known',
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
it('marks omitted actors unknown rather than claiming there was no inviter', async () => {
|
||||
const bridge = fakeBridge({
|
||||
fetchGroupRequests: vi.fn(async (filtered: boolean) =>
|
||||
filtered
|
||||
? []
|
||||
: [
|
||||
makeGroupRequest({
|
||||
invitorUid: '',
|
||||
invitorUin: 0,
|
||||
invitorName: '',
|
||||
operatorUid: '',
|
||||
operatorUin: 0,
|
||||
operatorName: '',
|
||||
}),
|
||||
],
|
||||
),
|
||||
});
|
||||
expect(await getGroupSystemMessages(bridge)).toEqual([
|
||||
expect.objectContaining({
|
||||
invitor_uin: 0,
|
||||
invitor_status: 'unknown',
|
||||
operator_uin: 0,
|
||||
operator_status: 'unknown',
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
it('resolves UID-only inviters and operators as well as the requester', async () => {
|
||||
const fetchUserProfileByUid = vi.fn(async (uid: string) =>
|
||||
makeProfile(uid === 'u_inviter' ? 456 : 789, uid),
|
||||
);
|
||||
const bridge = fakeBridge({
|
||||
fetchGroupRequests: vi.fn(async (filtered: boolean) =>
|
||||
filtered ? [] : [makeGroupRequest({ invitorUin: 0, operatorUin: 0 })],
|
||||
),
|
||||
fetchUserProfileByUid,
|
||||
identity: fakeIdentity({ findUinByUid: () => null }),
|
||||
});
|
||||
expect(await getGroupSystemMessages(bridge)).toEqual([
|
||||
expect.objectContaining({
|
||||
invitor_uin: 456,
|
||||
invitor_status: 'known',
|
||||
operator_uin: 789,
|
||||
operator_status: 'known',
|
||||
}),
|
||||
]);
|
||||
expect(fetchUserProfileByUid.mock.calls.map(([uid]) => uid).sort()).toEqual([
|
||||
'u_inviter',
|
||||
'u_operator',
|
||||
]);
|
||||
});
|
||||
|
||||
it.each(['invitor', 'operator'] as const)(
|
||||
'propagates %s lookup failures instead of reporting absence',
|
||||
async (role) => {
|
||||
const bridge = fakeBridge({
|
||||
fetchGroupRequests: vi.fn(async (filtered: boolean) =>
|
||||
filtered ? [] : [makeGroupRequest({ [`${role}Uin`]: 0 })],
|
||||
),
|
||||
fetchUserProfileByUid: vi.fn(async () => {
|
||||
throw new Error('profile offline');
|
||||
}),
|
||||
identity: fakeIdentity({ findUinByUid: () => null }),
|
||||
});
|
||||
await expect(getGroupSystemMessages(bridge)).rejects.toThrow(
|
||||
`failed to resolve ${role} UIN`,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it('reads both request inboxes with the requested per-inbox count', async () => {
|
||||
const fetchGroupRequests = vi.fn(async (filtered: boolean) =>
|
||||
filtered
|
||||
@@ -1150,6 +1242,8 @@ describe('onebot/contact-actions / getGroupSystemMessages', () => {
|
||||
expect.objectContaining({
|
||||
requester_uin: 45_678,
|
||||
requester_nick: 'inviter',
|
||||
target_uin: 10_001,
|
||||
target_nick: 'bot',
|
||||
invitor_uin: 45_678,
|
||||
invitor_nick: 'inviter',
|
||||
}),
|
||||
|
||||
@@ -0,0 +1,183 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { protobuf_encode, type pb, type uint_32, type bytes } from '@snowluma/proton';
|
||||
import { IdentityService } from '@snowluma/protocol/identity-service';
|
||||
import { parseMsgPush, parseMsgPushOrThrow } from '@snowluma/protocol/msg-push';
|
||||
import type { PacketInfo } from '@snowluma/common/protocol-types';
|
||||
import { convertEvent } from '../src/event-converter';
|
||||
|
||||
// Independent wire fixture: routing header 1.8.8.4.1 contains the join
|
||||
// origin. The member-change body has its own operator, not the inviter.
|
||||
interface ObservedOrigin {
|
||||
type?: pb<1, uint_32>;
|
||||
uid?: pb<3, bytes>;
|
||||
}
|
||||
interface ObservedJoinInfo {
|
||||
origin?: pb<1, ObservedOrigin>;
|
||||
}
|
||||
interface ObservedGroupKey {
|
||||
extra?: pb<4, ObservedJoinInfo>;
|
||||
}
|
||||
interface ObservedGroupRoute {
|
||||
key?: pb<8, ObservedGroupKey>;
|
||||
}
|
||||
interface ObservedRoute {
|
||||
from?: pb<1, uint_32>;
|
||||
group?: pb<8, ObservedGroupRoute>;
|
||||
}
|
||||
interface ObservedHead {
|
||||
type?: pb<1, uint_32>;
|
||||
time?: pb<6, uint_32>;
|
||||
}
|
||||
interface ObservedBody {
|
||||
content?: pb<2, bytes>;
|
||||
}
|
||||
interface ObservedMessage {
|
||||
route?: pb<1, ObservedRoute>;
|
||||
head?: pb<2, ObservedHead>;
|
||||
body?: pb<3, ObservedBody>;
|
||||
}
|
||||
interface ObservedPush {
|
||||
message?: pb<1, ObservedMessage>;
|
||||
}
|
||||
interface ObservedChange {
|
||||
group?: pb<1, uint_32>;
|
||||
member?: pb<3, string>;
|
||||
operation?: pb<4, uint_32>;
|
||||
operator?: pb<5, bytes>;
|
||||
}
|
||||
|
||||
function packet(operation: number, origin?: ObservedOrigin): PacketInfo {
|
||||
return {
|
||||
pid: 0,
|
||||
uin: '10001',
|
||||
seqId: 1,
|
||||
retCode: 0,
|
||||
fromClient: false,
|
||||
serviceCmd: 'trpc.msg.olpush.OlPushService.MsgPush',
|
||||
body: protobuf_encode<ObservedPush>({
|
||||
message: {
|
||||
route: { from: 90001, group: { key: { extra: { origin } } } },
|
||||
head: { type: 33, time: 1_700_000_000 },
|
||||
body: {
|
||||
content: protobuf_encode<ObservedChange>({
|
||||
group: 90001,
|
||||
member: 'u_member',
|
||||
operation,
|
||||
operator: Buffer.from('u_admin'),
|
||||
}),
|
||||
},
|
||||
},
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
function identity() {
|
||||
const result = IdentityService.memory('10001');
|
||||
|
||||
for (const [uid, uin] of [
|
||||
['u_member', 10002],
|
||||
['u_admin', 10003],
|
||||
['u_inviter', 10004],
|
||||
] as const) {
|
||||
result.rememberRequestIdentity({ uid, uin, source: 'group_request' });
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
async function notice(pkt: PacketInfo, identities = identity()) {
|
||||
const events = parseMsgPush(pkt, identities);
|
||||
expect(events).toHaveLength(1);
|
||||
return convertEvent(
|
||||
{
|
||||
selfId: 10001,
|
||||
imageUrlResolver: null,
|
||||
mediaUrlResolver: null,
|
||||
messageIdResolver: null,
|
||||
mediaSegmentSink: null,
|
||||
},
|
||||
events[0]!,
|
||||
);
|
||||
}
|
||||
|
||||
describe('group join identities (#643)', () => {
|
||||
it.each([2, 130])('keeps all three actors distinct for operation %d', async (operation) => {
|
||||
expect(
|
||||
await notice(packet(operation, { type: 0, uid: Buffer.from('u_inviter') })),
|
||||
).toMatchObject({
|
||||
notice_type: 'group_increase',
|
||||
sub_type: 'approve',
|
||||
group_id: 90001,
|
||||
user_id: 10002,
|
||||
operator_id: 10003,
|
||||
invitor_id: 10004,
|
||||
invitor_status: 'known',
|
||||
});
|
||||
});
|
||||
|
||||
it.each([3, 131, 0x102, 0x103])(
|
||||
'does not guess the inviter from operation %d',
|
||||
async (operation) => {
|
||||
expect(
|
||||
await notice(packet(operation, { type: 0, uid: Buffer.from('u_inviter') })),
|
||||
).toMatchObject({
|
||||
user_id: 10002,
|
||||
operator_id: 10003,
|
||||
invitor_id: 0,
|
||||
invitor_status: 'unknown',
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it('does not label a QR-code sharer as an inviter', async () => {
|
||||
expect(await notice(packet(130, { type: 1, uid: Buffer.from('u_inviter') }))).toMatchObject(
|
||||
{
|
||||
operator_id: 10003,
|
||||
invitor_id: 0,
|
||||
invitor_status: 'unknown',
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it.each([undefined, {}, { type: 0, uid: new Uint8Array() }])(
|
||||
'reports missing origin as unknown',
|
||||
async (origin) => {
|
||||
expect(await notice(packet(130, origin))).toMatchObject({
|
||||
invitor_id: 0,
|
||||
invitor_status: 'unknown',
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it('keeps an unresolved inviter unknown without substituting the administrator', async () => {
|
||||
expect(
|
||||
await notice(packet(130, { type: 0, uid: Buffer.from('u_unresolved') })),
|
||||
).toMatchObject({
|
||||
operator_id: 10003,
|
||||
invitor_id: 0,
|
||||
invitor_status: 'unknown',
|
||||
});
|
||||
});
|
||||
|
||||
it.each([Buffer.from([0xff]), Buffer.from('u_bad\nuid')])(
|
||||
'rejects malformed inviter identities',
|
||||
(uid) => {
|
||||
expect(() => parseMsgPushOrThrow(packet(130, { type: 0, uid }), identity())).toThrow(
|
||||
/invitation origin/,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it("does not reuse another account's identity cache", async () => {
|
||||
identity();
|
||||
expect(
|
||||
await notice(
|
||||
packet(130, { type: 0, uid: Buffer.from('u_inviter') }),
|
||||
IdentityService.memory('20001'),
|
||||
),
|
||||
).toMatchObject({
|
||||
invitor_id: 0,
|
||||
invitor_status: 'unknown',
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1013,8 +1013,15 @@ describe('buildApiContext contact reads', () => {
|
||||
request_id: 888,
|
||||
requester_uin: 20002,
|
||||
requester_nick: 'applicant',
|
||||
target_uin: 20002,
|
||||
target_nick: 'applicant',
|
||||
target_status: 'known',
|
||||
invitor_uin: 30003,
|
||||
invitor_nick: 'inviter',
|
||||
invitor_status: 'known',
|
||||
operator_uin: 40004,
|
||||
operator_nick: 'operator',
|
||||
operator_status: 'known',
|
||||
message: 'please add',
|
||||
checked: false,
|
||||
flag: 'slreq:1:888:710010:22:0',
|
||||
|
||||
@@ -10,6 +10,21 @@ export interface RichGroupCard {
|
||||
parts?: pb_repeated<1, GroupCardPart>;
|
||||
}
|
||||
|
||||
/** Join-origin metadata used by QQ's member-add notification handler. */
|
||||
export interface GroupJoinOrigin {
|
||||
/** 1 names a QR-code sharer rather than an inviter. */
|
||||
type?: pb<1, uint_32>;
|
||||
uid?: pb<3, bytes>;
|
||||
}
|
||||
|
||||
export interface GroupJoinExtra {
|
||||
origin?: pb<1, GroupJoinOrigin>;
|
||||
}
|
||||
|
||||
export interface GroupMessageKey {
|
||||
joinExtra?: pb<4, GroupJoinExtra>;
|
||||
}
|
||||
|
||||
// ResponseHead.Grp
|
||||
export interface ResponseGrp {
|
||||
groupUin?: pb<1, uint_32>;
|
||||
@@ -27,6 +42,7 @@ export interface ResponseGrp {
|
||||
memberCardType?: pb<5, uint_32>;
|
||||
/** The real group name (Lagrange: GroupName). "测试123" on-target. */
|
||||
groupName?: pb<7, string>;
|
||||
messageKey?: pb<8, GroupMessageKey>;
|
||||
}
|
||||
|
||||
export interface ResponseForward {
|
||||
|
||||
@@ -346,6 +346,9 @@ export interface GroupMemberJoin extends QQEvent {
|
||||
operatorUin: number;
|
||||
userUid?: string;
|
||||
operatorUid?: string;
|
||||
/** Independent invitation origin; never inferred from the operator. */
|
||||
invitorUid?: string;
|
||||
invitorUin?: number;
|
||||
/**
|
||||
* Admission mode derived from GroupChange field 4. This is deliberately
|
||||
* separate from QQ's nested invitation-source enum, which has different
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
import { protobuf_decode } from '@snowluma/proton';
|
||||
import { createLogger } from '@snowluma/common/logger';
|
||||
import type { GroupMemberJoin, GroupMemberLeave } from '../../events';
|
||||
import type { GroupChange, SelfJoinInGroup } from '@snowluma/proto-defs/notify';
|
||||
import { decodeGroupChangeOperatorUid, decodeNestedOperatorUid, resolveUidToUin } from '../helpers';
|
||||
import {
|
||||
decodeGroupChangeOperatorUid,
|
||||
decodeNestedOperatorUid,
|
||||
decodeRawOperatorUid,
|
||||
resolveUidToUin,
|
||||
} from '../helpers';
|
||||
import type { MsgPushDecoder } from '../registry';
|
||||
|
||||
const log = createLogger('MsgPush.GroupJoin');
|
||||
|
||||
function joinTypeFromOperationType(raw: number): NonNullable<GroupMemberJoin['joinType']> {
|
||||
// QQ uses bit 0x80 as a flag on the PkgType=33 operation code. Clear only
|
||||
// that bit: other high bits remain significant in the native handler. The
|
||||
@@ -26,6 +34,22 @@ export const decodeGroupMemberJoin: MsgPushDecoder = (ctx) => {
|
||||
change.operatorBytes ?? new Uint8Array(0),
|
||||
'group member increase',
|
||||
);
|
||||
const operation = (change.decreaseType ?? 0) - ((change.decreaseType ?? 0) & 0x80);
|
||||
const origin = ctx.responseHead?.grp?.messageKey?.joinExtra?.origin;
|
||||
// QQ consumes this independent origin only for operation 2. Type 1
|
||||
// identifies a QR-code sharer; neither that person nor the approving
|
||||
// operator is evidence of an invitation.
|
||||
const invitorUid =
|
||||
operation === 2 && origin?.type !== 1 && origin?.uid?.length
|
||||
? decodeRawOperatorUid(origin.uid, 'group member invitation origin')
|
||||
: '';
|
||||
log.trace(
|
||||
'join identity: group=%d operation=%d originType=%s inviterProvided=%s',
|
||||
groupId,
|
||||
operation,
|
||||
origin?.type === undefined ? 'absent' : String(origin.type),
|
||||
Boolean(invitorUid),
|
||||
);
|
||||
const ev: GroupMemberJoin = {
|
||||
kind: 'group_member_join',
|
||||
time: ctx.head.timestamp,
|
||||
@@ -35,6 +59,9 @@ export const decodeGroupMemberJoin: MsgPushDecoder = (ctx) => {
|
||||
operatorUin: resolveUidToUin(ctx.identity, groupId, operatorUid),
|
||||
userUid,
|
||||
operatorUid,
|
||||
...(invitorUid
|
||||
? { invitorUid, invitorUin: resolveUidToUin(ctx.identity, groupId, invitorUid) }
|
||||
: {}),
|
||||
joinType: joinTypeFromOperationType(change.decreaseType ?? 0),
|
||||
};
|
||||
return [ev];
|
||||
|
||||
@@ -464,8 +464,8 @@ export class IncomingPacketPipeline {
|
||||
return (
|
||||
event.kind === 'group_member_join' &&
|
||||
event.groupId > 0 &&
|
||||
event.userUin <= 0 &&
|
||||
Boolean(event.userUid)
|
||||
((event.userUin <= 0 && Boolean(event.userUid)) ||
|
||||
((event.invitorUin ?? 0) <= 0 && Boolean(event.invitorUid)))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -601,17 +601,46 @@ export class IncomingPacketPipeline {
|
||||
): Promise<void> {
|
||||
this.resolveMemberIdentityFromCache(event);
|
||||
|
||||
if (event.userUin > 0 || !event.userUid) {
|
||||
return;
|
||||
}
|
||||
const results = await Promise.allSettled(
|
||||
(
|
||||
[
|
||||
['userUid', 'userUin'],
|
||||
['invitorUid', 'invitorUin'],
|
||||
] as const
|
||||
).map(async ([uidKey, uinKey]) => {
|
||||
const uid = event[uidKey];
|
||||
|
||||
const uin = await this.deps.identity.resolveUin(event.userUid, event.groupId);
|
||||
if (!uid || (event[uinKey] ?? 0) > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (uin !== null) {
|
||||
event.userUin = uin;
|
||||
}
|
||||
const uin = await this.deps.identity.resolveUin(uid, event.groupId);
|
||||
|
||||
if (uin !== null) {
|
||||
event[uinKey] = uin;
|
||||
} else {
|
||||
this.log.warn(
|
||||
'group join identity unavailable: group=%d role=%s',
|
||||
event.groupId,
|
||||
uidKey,
|
||||
);
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
this.resolveMemberIdentityFromCache(event);
|
||||
const failures = results.filter((result) => result.status === 'rejected');
|
||||
|
||||
if (failures.length) {
|
||||
throw new AggregateError(
|
||||
failures.map((result) => result.reason),
|
||||
`group join identity lookup failed: ${failures
|
||||
.map(({ reason }) =>
|
||||
reason instanceof Error ? reason.message : String(reason),
|
||||
)
|
||||
.join('; ')}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private resolveMemberIdentityFromCache(event: GroupMemberIdentityEvent): void {
|
||||
@@ -634,6 +663,18 @@ export class IncomingPacketPipeline {
|
||||
event.operatorUin = uin;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
event.kind === 'group_member_join' &&
|
||||
(event.invitorUin ?? 0) <= 0 &&
|
||||
event.invitorUid
|
||||
) {
|
||||
const uin = this.deps.identity.findUinByUid(event.invitorUid, event.groupId);
|
||||
|
||||
if (uin !== null) {
|
||||
event.invitorUin = uin;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private isSelfMemberIdentity(uin: number, uid?: string): boolean {
|
||||
@@ -744,6 +785,15 @@ export class IncomingPacketPipeline {
|
||||
}
|
||||
|
||||
case 'group_member_join':
|
||||
if (event.invitorUid) {
|
||||
this.deps.identity.rememberRequestIdentity({
|
||||
groupId: event.groupId,
|
||||
uid: event.invitorUid,
|
||||
uin: event.invitorUin ?? 0,
|
||||
source: 'group_request',
|
||||
});
|
||||
}
|
||||
|
||||
this.deps.identity.rememberGroupMemberIdentity(event.groupId, {
|
||||
uid: event.userUid,
|
||||
uin: event.userUin,
|
||||
|
||||
@@ -3,7 +3,8 @@ import { GroupInviteTracker } from '@snowluma/protocol/group-invite-tracker';
|
||||
import { IncomingPacketPipeline } from '@snowluma/protocol/packet-pipeline';
|
||||
import { BridgeEventBus } from '@snowluma/protocol/event-bus';
|
||||
import { IdentityService } from '@snowluma/protocol/identity-service';
|
||||
import type { GroupInviteEvent, QQEventVariant } from '@snowluma/protocol/events';
|
||||
import type { GroupInviteEvent, GroupMemberJoin, QQEventVariant } from '@snowluma/protocol/events';
|
||||
import { subscribeLogs } from '@snowluma/common/logger';
|
||||
import type {
|
||||
GroupMemberInfo,
|
||||
GroupRequestInfo,
|
||||
@@ -111,6 +112,99 @@ async function receive(pipeline: IncomingPacketPipeline, event: GroupInviteEvent
|
||||
await pipeline.process({ serviceCmd: 'test.cmd' } as PacketInfo);
|
||||
}
|
||||
|
||||
describe('IncomingPacketPipeline / independent join inviter', () => {
|
||||
function join(): GroupMemberJoin {
|
||||
return {
|
||||
kind: 'group_member_join',
|
||||
time: 1,
|
||||
selfUin: 10001,
|
||||
groupId: 12345,
|
||||
userUid: 'u_member',
|
||||
userUin: 10002,
|
||||
operatorUid: 'u_admin',
|
||||
operatorUin: 10003,
|
||||
invitorUid: 'u_inviter',
|
||||
invitorUin: 0,
|
||||
joinType: 'approve',
|
||||
};
|
||||
}
|
||||
|
||||
it('resolves an inviter even when the joining member is already known', async () => {
|
||||
const fetchProfileByUid = vi.fn(async () => makeProfile(10004, 'u_inviter'));
|
||||
const { pipeline, captured, resolveGroupJoinRequest } = makePipeline({ fetchProfileByUid });
|
||||
await pipeline.processEvents({ serviceCmd: 'test.cmd' } as PacketInfo, [join()]);
|
||||
expect(captured).toEqual([
|
||||
expect.objectContaining({ userUin: 10002, operatorUin: 10003, invitorUin: 10004 }),
|
||||
]);
|
||||
expect(fetchProfileByUid).toHaveBeenCalledExactlyOnceWith('u_inviter');
|
||||
expect(resolveGroupJoinRequest).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('keeps the event observable when the inviter cannot be resolved', async () => {
|
||||
const fetchProfileByUid = vi.fn(async () => {
|
||||
throw new Error('profile unavailable');
|
||||
});
|
||||
const { pipeline, captured } = makePipeline({ fetchProfileByUid });
|
||||
const warnings: string[] = [];
|
||||
const unsubscribe = subscribeLogs((entry) => {
|
||||
if (entry.level === 'warn') {
|
||||
warnings.push(entry.message);
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
await pipeline.processEvents({ serviceCmd: 'test.cmd' } as PacketInfo, [join()]);
|
||||
} finally {
|
||||
unsubscribe();
|
||||
}
|
||||
|
||||
expect(captured).toEqual([expect.objectContaining({ invitorUin: 0, operatorUin: 10003 })]);
|
||||
expect(
|
||||
warnings.some((message) => message.includes('group join identity unavailable')),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('waits for both identities before dispatching a join', async () => {
|
||||
let finishInviter!: (profile: UserProfileInfo) => void;
|
||||
const fetchProfileByUid = vi.fn((uid: string) =>
|
||||
uid === 'u_member'
|
||||
? Promise.resolve(makeProfile(10002, uid))
|
||||
: new Promise<UserProfileInfo>((resolve) => {
|
||||
finishInviter = resolve;
|
||||
}),
|
||||
);
|
||||
const { pipeline, captured } = makePipeline({ fetchProfileByUid });
|
||||
const pending = pipeline.processEvents({ serviceCmd: 'test.cmd' } as PacketInfo, [
|
||||
{ ...join(), userUin: 0 },
|
||||
]);
|
||||
await vi.waitFor(() => expect(fetchProfileByUid).toHaveBeenCalledTimes(2));
|
||||
expect(captured).toEqual([]);
|
||||
finishInviter(makeProfile(10004, 'u_inviter'));
|
||||
await pending;
|
||||
expect(captured).toEqual([expect.objectContaining({ userUin: 10002, invitorUin: 10004 })]);
|
||||
});
|
||||
|
||||
it('retains the original identity failure in the warning', async () => {
|
||||
const { pipeline, identity, captured } = makePipeline();
|
||||
vi.spyOn(identity, 'resolveUin').mockRejectedValueOnce(new Error('identity store closed'));
|
||||
const warnings: string[] = [];
|
||||
const unsubscribe = subscribeLogs((entry) => {
|
||||
if (entry.level === 'warn') {
|
||||
warnings.push(entry.message);
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
await pipeline.processEvents({ serviceCmd: 'test.cmd' } as PacketInfo, [join()]);
|
||||
} finally {
|
||||
unsubscribe();
|
||||
}
|
||||
|
||||
expect(captured).toHaveLength(1);
|
||||
expect(warnings.some((message) => message.includes('identity store closed'))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('IncomingPacketPipeline / group requests', () => {
|
||||
it('resolves an unknown requester before dispatch', async () => {
|
||||
const fetchProfileByUid = vi.fn(async () => makeProfile(222, 'u_requester', 'Alice'));
|
||||
|
||||
@@ -19,6 +19,8 @@ SnowLuma 的 TypeScript SDK,提供 OneBot HTTP / WebSocket 客户端、事件
|
||||
- [项目结构](#项目结构)
|
||||
- [版本策略](#版本策略)
|
||||
|
||||
群申请中的入群者、邀请人和审批人,以及入群通知的身份可用状态,见[群邀请与入群身份](../onebot/GROUP_REQUESTS.md)。
|
||||
|
||||
## 安装
|
||||
|
||||
在本 monorepo 内直接通过 workspace 引用:
|
||||
|
||||
@@ -161,6 +161,7 @@ import type {
|
||||
GroupFileUrl,
|
||||
GroupMessageHistory,
|
||||
GroupNoticeInfo,
|
||||
GroupSystemMessage,
|
||||
GroupTodoListItem,
|
||||
LoginInfo,
|
||||
MediaInfo,
|
||||
@@ -242,7 +243,7 @@ export interface SnowLumaActionMap {
|
||||
get_group_member_list: { params: GetGroupMemberListParams; data: JsonObject[] };
|
||||
get_group_member_info: { params: GetGroupMemberInfoParams; data: JsonObject };
|
||||
get_group_honor_info: { params: GetGroupHonorInfoParams; data: JsonValue };
|
||||
get_group_system_msg: { params: GetGroupSystemMsgParams; data: JsonObject[] };
|
||||
get_group_system_msg: { params: GetGroupSystemMsgParams; data: GroupSystemMessage[] };
|
||||
set_group_kick: { params: SetGroupKickParams; data: EmptyData };
|
||||
set_group_kick_members: { params: SetGroupKickMembersParams; data: EmptyData };
|
||||
set_group_ban: { params: SetGroupBanParams; data: EmptyData };
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { JsonObject, JsonValue } from './json.js';
|
||||
import type { GroupIdentityStatus } from './results.js';
|
||||
|
||||
export interface OneBotBaseEvent extends JsonObject {
|
||||
time: number;
|
||||
@@ -52,6 +53,17 @@ export interface OneBotNoticeEvent extends OneBotBaseEvent {
|
||||
notice_type: string;
|
||||
}
|
||||
|
||||
export interface OneBotGroupIncreaseEvent extends OneBotNoticeEvent {
|
||||
notice_type: 'group_increase';
|
||||
sub_type: 'approve' | 'invite';
|
||||
group_id: number;
|
||||
user_id: number;
|
||||
operator_id: number;
|
||||
/** Independent inviter, when QQ supplies one. Zero does not prove absence. */
|
||||
invitor_id?: number;
|
||||
invitor_status?: GroupIdentityStatus;
|
||||
}
|
||||
|
||||
export type BotStatusSubType = 'online' | 'offline';
|
||||
|
||||
/** Bridge session edge. Not KickNT `bot_offline`. */
|
||||
|
||||
@@ -1,6 +1,31 @@
|
||||
import type { OneBotPrivateMessageEvent } from './events.js';
|
||||
import type { JsonArray, JsonObject, JsonValue } from './json.js';
|
||||
|
||||
/** Unknown includes missing information; it does not mean that no such person exists. */
|
||||
export type GroupIdentityStatus = 'known' | 'unknown';
|
||||
|
||||
export interface GroupSystemMessage extends JsonObject {
|
||||
group_id: number;
|
||||
group_name: string;
|
||||
request_id: number;
|
||||
requester_uin: number;
|
||||
requester_nick: string;
|
||||
invitor_uin: number;
|
||||
invitor_nick: string;
|
||||
message: string;
|
||||
checked: boolean;
|
||||
flag: string;
|
||||
/** Always the applicant or invitee; unlike requester_uin on self invitations. */
|
||||
target_uin?: number;
|
||||
target_nick?: string;
|
||||
target_status?: GroupIdentityStatus;
|
||||
invitor_status?: GroupIdentityStatus;
|
||||
/** The person who handled the request, not necessarily the inviter. */
|
||||
operator_uin?: number;
|
||||
operator_nick?: string;
|
||||
operator_status?: GroupIdentityStatus;
|
||||
}
|
||||
|
||||
export interface QzoneCommentReply {
|
||||
uin: number;
|
||||
name: string;
|
||||
|
||||
@@ -43,6 +43,12 @@ export type QuickAlias = AssertTrue<
|
||||
declare const http: SnowLumaHttpClient;
|
||||
declare const ws: SnowLumaWebSocketClient;
|
||||
|
||||
const groupSystemMessages = await http.getGroupSystemMessages({ groupId: 10001 });
|
||||
export const invitationTarget: number | undefined = groupSystemMessages[0]?.target_uin;
|
||||
export const invitationOperator: number | undefined = groupSystemMessages[0]?.operator_uin;
|
||||
export const invitationIdentityStatus: 'known' | 'unknown' | undefined =
|
||||
groupSystemMessages[0]?.invitor_status;
|
||||
|
||||
const adminPermissions = await http.raw('get_group_admin_permissions', {
|
||||
group_id: 10001,
|
||||
user_id: 10002,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, expectTypeOf, it, vi } from 'vitest';
|
||||
import type { QzoneMsgDetailResult, QzoneProfileResult } from '../src';
|
||||
import type { GroupSystemMessage, QzoneMsgDetailResult, QzoneProfileResult } from '../src';
|
||||
import {
|
||||
SnowLumaAbortError,
|
||||
SnowLumaApiError,
|
||||
@@ -9,6 +9,37 @@ import {
|
||||
} from '../src';
|
||||
|
||||
describe('SnowLumaHttpClient', () => {
|
||||
it('retains independent group request actors and supports old servers', async () => {
|
||||
const legacy: GroupSystemMessage = {
|
||||
group_id: 90001,
|
||||
group_name: 'group',
|
||||
request_id: 1,
|
||||
requester_uin: 10002,
|
||||
requester_nick: 'member',
|
||||
invitor_uin: 10004,
|
||||
invitor_nick: 'inviter',
|
||||
message: '',
|
||||
checked: true,
|
||||
flag: 'request-1',
|
||||
};
|
||||
const current: GroupSystemMessage = {
|
||||
...legacy,
|
||||
target_uin: 10002,
|
||||
target_status: 'known',
|
||||
operator_uin: 10003,
|
||||
operator_status: 'known',
|
||||
invitor_status: 'known',
|
||||
};
|
||||
const fetchImpl = vi.fn(
|
||||
async () =>
|
||||
new Response(JSON.stringify({ status: 'ok', retcode: 0, data: [current, legacy] })),
|
||||
);
|
||||
const client = new SnowLumaHttpClient({ fetch: fetchImpl });
|
||||
const result = await client.getGroupSystemMessages({ groupId: 90001 });
|
||||
expectTypeOf(result).toEqualTypeOf<GroupSystemMessage[]>();
|
||||
expect(result).toEqual([current, legacy]);
|
||||
expect(result[1]).not.toHaveProperty('invitor_status');
|
||||
});
|
||||
it('reads typed space profiles for the current and an explicit account', async () => {
|
||||
const data: QzoneProfileResult = { name: 'Space', description: 'Description' };
|
||||
const fetchImpl = vi
|
||||
|
||||
Reference in new issue
Block a user