feat(onebot): expose group-wide mute status

Report whether group-wide mute is enabled through the existing group list and group information responses.

Keep standard and extended queries aligned, support explicit refreshes in the SDK, and update the generated action documentation without adding another endpoint.

Preserve established compatibility values, isolate cached non-member results by account, and add coverage across the request, mapping, action, and client layers.

Closes #313
This commit is contained in:
DrSmoothl committed 2026-08-04 23:27:58 +08:00
1 parent c6619fda0a
commit 634097460c
18 files changed
+687 -56

No files matched your search

@@ -293,6 +293,7 @@ export class ContactsApi {
// is not in the list (0x88D_0 detail only), so it stays undefined here.
createTime: raw.info?.createdTime ?? 0,
memo: raw.info?.announcement || raw.info?.description || '',
allMuted: (raw.info?.shutUpAllTimestamp ?? 0) > 0,
});
}
this.ctx.identity.rememberGroups(groups);
@@ -323,6 +324,7 @@ export class ContactsApi {
createTime: Number(r.createTime ?? 0n),
level: Number(r.level ?? 0n),
memo: r.noticePreview ?? '',
allMuted: (r.shutUpAllTimestamp ?? 0) > 0,
};
}
+41 -1
View File
@@ -7,6 +7,7 @@ import type {
OidbFriend,
OidbFriendCategory,
OidbRobotUinRangeResponse,
OidbSvcTrpcTcp0x88D_0Response,
OidbSvcTrpcTcp0xFD4_1Response,
OidbSvcTrpcTcp0xFE5_2Response,
OidbSvcTrpcTcp0xFE7_3Response,
@@ -99,6 +100,18 @@ function groupListPacket(body: OidbSvcTrpcTcp0xFE5_2Response): SendPacketResult
};
}
function groupDetailPacket(body: OidbSvcTrpcTcp0x88D_0Response): SendPacketResult {
return {
success: true,
gotResponse: true,
errorCode: 0,
errorMessage: '',
responseData: Buffer.from(
protobuf_encode<OidbBase<OidbSvcTrpcTcp0x88D_0Response>>({ body }),
),
};
}
function apiForPages(pages: OidbSvcTrpcTcp0xFD4_1Response[]) {
let index = 0;
const sendRawPacket = vi.fn(async (
@@ -150,7 +163,12 @@ describe('apis/contacts / group roster', () => {
const sendRawPacket = vi.fn(async () => groupListPacket({
groups: [{
groupUin: 123456789,
info: { groupName: 'Project', memberCount: 42, memberMax: 500 },
info: {
groupName: 'Project',
memberCount: 42,
memberMax: 500,
shutUpAllTimestamp: 4_294_967_295,
},
customInfo: { remark: ' My Project ' },
}],
}));
@@ -167,9 +185,31 @@ describe('apis/contacts / group roster', () => {
remark: ' My Project ',
memberCount: 42,
memberMax: 500,
allMuted: true,
})]);
expect(rememberGroups).toHaveBeenCalledWith(groups);
});
it('maps the group-wide mute timestamp from a single-group detail', async () => {
const sendRawPacket = vi.fn(async () => groupDetailPacket({
groupInfo: {
uin: 123456789n,
results: {
name: 'Muted Group',
shutUpAllTimestamp: 4_294_967_295,
},
},
}));
const api = new ContactsApi({ sendRawPacket, identity: {} } as any);
const detail = await api.fetchGroupDetail(123456789);
expect(detail).toEqual(expect.objectContaining({
groupId: 123456789,
groupName: 'Muted Group',
allMuted: true,
}));
});
});
describe('apis/contacts / categorized friend roster', () => {
+154 -4
View File
@@ -2130,11 +2130,11 @@
"name": "face_id",
"type": "int",
"required": true,
"role": "face_id",
"schema": {
"type": "integer",
"minimum": 0
},
"role": "face_id",
"desc": "QQ 系统表情编号"
},
{
@@ -2240,11 +2240,11 @@
"name": "face_id",
"type": "int",
"required": true,
"role": "face_id",
"schema": {
"type": "integer",
"minimum": 0
},
"role": "face_id",
"desc": "QQ 系统表情编号"
},
{
@@ -4143,6 +4143,59 @@
"name": "get_group_detail_info",
"aliases": [],
"summary": "获取群详细信息",
"returnsSchema": {
"type": "object",
"properties": {
"group_id": {
"type": "integer",
"description": "群号"
},
"group_name": {
"type": "string",
"description": "群名"
},
"group_remark": {
"type": "string",
"description": "当前账号设置的群备注"
},
"member_count": {
"type": "integer",
"description": "当前成员数"
},
"max_member_count": {
"type": "integer",
"description": "成员上限"
},
"group_create_time": {
"type": "integer",
"description": "建群时间戳(秒)"
},
"group_level": {
"type": "integer",
"description": "群等级"
},
"group_memo": {
"type": "string",
"description": "群简介 / 公告预览"
},
"group_all_shut": {
"type": "integer",
"enum": [
-1,
0
],
"description": "是否开启全员禁言(-1 开启,0 关闭)"
}
},
"required": [
"group_id",
"group_name",
"group_remark",
"member_count",
"max_member_count",
"group_all_shut"
]
},
"readOnly": true,
"params": [
{
@@ -4154,6 +4207,15 @@
"type": "integer",
"minimum": 1
}
},
{
"name": "no_cache",
"type": "bool",
"required": false,
"schema": {
"type": "boolean"
},
"default": false
}
],
"invariants": [],
@@ -4164,6 +4226,10 @@
"type": "integer",
"minimum": 1,
"x-role": "group_id"
},
"no_cache": {
"type": "boolean",
"default": false
}
},
"required": [
@@ -4715,6 +4781,14 @@
"group_memo": {
"type": "string",
"description": "群简介 / 公告预览"
},
"group_all_shut": {
"type": "integer",
"enum": [
-1,
0
],
"description": "是否开启全员禁言(-1 开启,0 关闭)"
}
},
"required": [
@@ -4722,7 +4796,8 @@
"group_name",
"group_remark",
"member_count",
"max_member_count"
"max_member_count",
"group_all_shut"
]
},
"readOnly": true,
@@ -4774,6 +4849,59 @@
"name": "get_group_info_ex",
"aliases": [],
"summary": "获取群信息(扩展)",
"returnsSchema": {
"type": "object",
"properties": {
"group_id": {
"type": "integer",
"description": "群号"
},
"group_name": {
"type": "string",
"description": "群名"
},
"group_remark": {
"type": "string",
"description": "当前账号设置的群备注"
},
"member_count": {
"type": "integer",
"description": "当前成员数"
},
"max_member_count": {
"type": "integer",
"description": "成员上限"
},
"group_create_time": {
"type": "integer",
"description": "建群时间戳(秒)"
},
"group_level": {
"type": "integer",
"description": "群等级"
},
"group_memo": {
"type": "string",
"description": "群简介 / 公告预览"
},
"group_all_shut": {
"type": "integer",
"enum": [
-1,
0
],
"description": "是否开启全员禁言(-1 开启,0 关闭)"
}
},
"required": [
"group_id",
"group_name",
"group_remark",
"member_count",
"max_member_count",
"group_all_shut"
]
},
"readOnly": true,
"params": [
{
@@ -4785,6 +4913,15 @@
"type": "integer",
"minimum": 1
}
},
{
"name": "no_cache",
"type": "bool",
"required": false,
"schema": {
"type": "boolean"
},
"default": false
}
],
"invariants": [],
@@ -4795,6 +4932,10 @@
"type": "integer",
"minimum": 1,
"x-role": "group_id"
},
"no_cache": {
"type": "boolean",
"default": false
}
},
"required": [
@@ -4845,6 +4986,14 @@
"group_memo": {
"type": "string",
"description": "群简介 / 公告预览"
},
"group_all_shut": {
"type": "integer",
"enum": [
-1,
0
],
"description": "是否开启全员禁言(-1 开启,0 关闭)"
}
},
"required": [
@@ -4852,7 +5001,8 @@
"group_name",
"group_remark",
"member_count",
"max_member_count"
"max_member_count",
"group_all_shut"
]
}
},
+154 -4
View File
@@ -2133,11 +2133,11 @@ export const ACTIONS: CatalogAction[] = [
"name": "face_id",
"type": "int",
"required": true,
"role": "face_id",
"schema": {
"type": "integer",
"minimum": 0
},
"role": "face_id",
"desc": "QQ 系统表情编号"
},
{
@@ -2243,11 +2243,11 @@ export const ACTIONS: CatalogAction[] = [
"name": "face_id",
"type": "int",
"required": true,
"role": "face_id",
"schema": {
"type": "integer",
"minimum": 0
},
"role": "face_id",
"desc": "QQ 系统表情编号"
},
{
@@ -4146,6 +4146,59 @@ export const ACTIONS: CatalogAction[] = [
"name": "get_group_detail_info",
"aliases": [],
"summary": "获取群详细信息",
"returnsSchema": {
"type": "object",
"properties": {
"group_id": {
"type": "integer",
"description": "群号"
},
"group_name": {
"type": "string",
"description": "群名"
},
"group_remark": {
"type": "string",
"description": "当前账号设置的群备注"
},
"member_count": {
"type": "integer",
"description": "当前成员数"
},
"max_member_count": {
"type": "integer",
"description": "成员上限"
},
"group_create_time": {
"type": "integer",
"description": "建群时间戳(秒)"
},
"group_level": {
"type": "integer",
"description": "群等级"
},
"group_memo": {
"type": "string",
"description": "群简介 / 公告预览"
},
"group_all_shut": {
"type": "integer",
"enum": [
-1,
0
],
"description": "是否开启全员禁言(-1 开启,0 关闭)"
}
},
"required": [
"group_id",
"group_name",
"group_remark",
"member_count",
"max_member_count",
"group_all_shut"
]
},
"readOnly": true,
"params": [
{
@@ -4157,6 +4210,15 @@ export const ACTIONS: CatalogAction[] = [
"type": "integer",
"minimum": 1
}
},
{
"name": "no_cache",
"type": "bool",
"required": false,
"schema": {
"type": "boolean"
},
"default": false
}
],
"invariants": [],
@@ -4167,6 +4229,10 @@ export const ACTIONS: CatalogAction[] = [
"type": "integer",
"minimum": 1,
"x-role": "group_id"
},
"no_cache": {
"type": "boolean",
"default": false
}
},
"required": [
@@ -4718,6 +4784,14 @@ export const ACTIONS: CatalogAction[] = [
"group_memo": {
"type": "string",
"description": "群简介 / 公告预览"
},
"group_all_shut": {
"type": "integer",
"enum": [
-1,
0
],
"description": "是否开启全员禁言(-1 开启,0 关闭)"
}
},
"required": [
@@ -4725,7 +4799,8 @@ export const ACTIONS: CatalogAction[] = [
"group_name",
"group_remark",
"member_count",
"max_member_count"
"max_member_count",
"group_all_shut"
]
},
"readOnly": true,
@@ -4777,6 +4852,59 @@ export const ACTIONS: CatalogAction[] = [
"name": "get_group_info_ex",
"aliases": [],
"summary": "获取群信息(扩展)",
"returnsSchema": {
"type": "object",
"properties": {
"group_id": {
"type": "integer",
"description": "群号"
},
"group_name": {
"type": "string",
"description": "群名"
},
"group_remark": {
"type": "string",
"description": "当前账号设置的群备注"
},
"member_count": {
"type": "integer",
"description": "当前成员数"
},
"max_member_count": {
"type": "integer",
"description": "成员上限"
},
"group_create_time": {
"type": "integer",
"description": "建群时间戳(秒)"
},
"group_level": {
"type": "integer",
"description": "群等级"
},
"group_memo": {
"type": "string",
"description": "群简介 / 公告预览"
},
"group_all_shut": {
"type": "integer",
"enum": [
-1,
0
],
"description": "是否开启全员禁言(-1 开启,0 关闭)"
}
},
"required": [
"group_id",
"group_name",
"group_remark",
"member_count",
"max_member_count",
"group_all_shut"
]
},
"readOnly": true,
"params": [
{
@@ -4788,6 +4916,15 @@ export const ACTIONS: CatalogAction[] = [
"type": "integer",
"minimum": 1
}
},
{
"name": "no_cache",
"type": "bool",
"required": false,
"schema": {
"type": "boolean"
},
"default": false
}
],
"invariants": [],
@@ -4798,6 +4935,10 @@ export const ACTIONS: CatalogAction[] = [
"type": "integer",
"minimum": 1,
"x-role": "group_id"
},
"no_cache": {
"type": "boolean",
"default": false
}
},
"required": [
@@ -4848,6 +4989,14 @@ export const ACTIONS: CatalogAction[] = [
"group_memo": {
"type": "string",
"description": "群简介 / 公告预览"
},
"group_all_shut": {
"type": "integer",
"enum": [
-1,
0
],
"description": "是否开启全员禁言(-1 开启,0 关闭)"
}
},
"required": [
@@ -4855,7 +5004,8 @@ export const ACTIONS: CatalogAction[] = [
"group_name",
"group_remark",
"member_count",
"max_member_count"
"max_member_count",
"group_all_shut"
]
}
},
+13 -4
View File
@@ -16,6 +16,7 @@ import {
type MessageMeta,
} from '../types';
import { defineAction, groupAction, groupUserAction, f } from '../action-kit';
import { groupInfoReturnsSchema } from './group-info';
import { GROUP_MESSAGE_EVENT, hashMessageIdInt32 } from '../message-id';
const DOWNLOAD_FILE_MAX_BYTES = 1024 * 1024 * 1024; // 1 GiB
@@ -1852,10 +1853,14 @@ export const actions = [
name: 'get_group_info_ex',
summary: '获取群信息(扩展)',
readOnly: true,
params: { group_id: f.groupId() },
returnsSchema: groupInfoReturnsSchema,
params: {
group_id: f.groupId(),
no_cache: f.bool().default(false),
},
run: async (p, ctx) => {
if (ctx.getGroupInfo) {
return okResponse(await ctx.getGroupInfo(p.group_id));
return okResponse(await ctx.getGroupInfo(p.group_id, p.no_cache));
}
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
},
@@ -1865,10 +1870,14 @@ export const actions = [
name: 'get_group_detail_info',
summary: '获取群详细信息',
readOnly: true,
params: { group_id: f.groupId() },
returnsSchema: groupInfoReturnsSchema,
params: {
group_id: f.groupId(),
no_cache: f.bool().default(false),
},
run: async (p, ctx) => {
if (ctx.getGroupInfo) {
return okResponse(await ctx.getGroupInfo(p.group_id));
return okResponse(await ctx.getGroupInfo(p.group_id, p.no_cache));
}
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
},
+26 -15
View File
@@ -3,6 +3,25 @@ import { asString } from '../api-handler';
import { RETCODE, failedResponse, okResponse } from '../types';
import { WebHonorType } from '@snowluma/protocol/web/group-honor';
export const groupInfoReturnsSchema = {
type: 'object',
properties: {
group_id: { type: 'integer', description: '群号' },
group_name: { type: 'string', description: '群名' },
group_remark: { type: 'string', description: '当前账号设置的群备注' },
member_count: { type: 'integer', description: '当前成员数' },
max_member_count: { type: 'integer', description: '成员上限' },
group_create_time: { type: 'integer', description: '建群时间戳(秒)' },
group_level: { type: 'integer', description: '群等级' },
group_memo: { type: 'string', description: '群简介 / 公告预览' },
group_all_shut: { type: 'integer', enum: [-1, 0], description: '是否开启全员禁言(-1 开启,0 关闭)' },
},
required: [
'group_id', 'group_name', 'group_remark', 'member_count',
'max_member_count', 'group_all_shut',
],
};
export const actions = [
defineAction({
name: 'get_group_list',
@@ -22,8 +41,12 @@ export const actions = [
group_create_time: { type: 'integer', description: '建群时间戳(秒)' },
group_level: { type: 'integer', description: '群等级(列表批量场景恒 0,详见 get_group_info)' },
group_memo: { type: 'string', description: '群简介 / 公告预览' },
group_all_shut: { type: 'integer', enum: [-1, 0], description: '是否开启全员禁言(-1 开启,0 关闭)' },
},
required: ['group_id', 'group_name', 'group_remark', 'member_count', 'max_member_count'],
required: [
'group_id', 'group_name', 'group_remark', 'member_count',
'max_member_count', 'group_all_shut',
],
},
},
params: { no_cache: f.bool().default(false) },
@@ -41,20 +64,7 @@ export const actions = [
summary: '获取群信息',
readOnly: true,
returns: '群信息对象。',
returnsSchema: {
type: 'object',
properties: {
group_id: { type: 'integer', description: '群号' },
group_name: { type: 'string', description: '群名' },
group_remark: { type: 'string', description: '当前账号设置的群备注' },
member_count: { type: 'integer', description: '当前成员数' },
max_member_count: { type: 'integer', description: '成员上限' },
group_create_time: { type: 'integer', description: '建群时间戳(秒)' },
group_level: { type: 'integer', description: '群等级' },
group_memo: { type: 'string', description: '群简介 / 公告预览' },
},
required: ['group_id', 'group_name', 'group_remark', 'member_count', 'max_member_count'],
},
returnsSchema: groupInfoReturnsSchema,
params: { no_cache: f.bool().default(false) },
run: async (p, ctx) => {
const groupId = p.group_id;
@@ -68,6 +78,7 @@ export const actions = [
group_create_time: 0,
group_level: 0,
group_memo: '',
group_all_shut: 0,
};
if (ctx.getGroupInfo) {
const info = await ctx.getGroupInfo(groupId, noCache);
+51 -15
View File
@@ -68,8 +68,13 @@ export async function getGroupList(
if (noCache || bridge.identity.groups.length === 0) {
await bridge.apis.contacts.fetchGroupList();
}
} catch {
// Use cached data.
} catch (err) {
if (noCache) throw err;
log.warn(
'group list refresh failed, using cached roster: uin=%s err=%s',
bridge.identity.uin,
err instanceof Error ? (err.stack ?? err.message) : String(err),
);
}
return bridge.identity.groups.map(g => ({
group_id: g.groupId,
@@ -83,24 +88,36 @@ export async function getGroupList(
group_create_time: g.createTime ?? 0,
group_level: g.level ?? 0,
group_memo: g.memo ?? '',
group_all_shut: g.allMuted ? -1 : 0,
}));
}
// group_level lives only in the 0x88D_0 detail. Memoize it (short TTL) so a
// joined-group get_group_info doesn't fetch the detail on every call (#197).
// group_level lives only in the per-group detail response. Keep its existing
// short cache, but read mutable group state from the roster refreshed above.
const GROUP_LEVEL_TTL_MS = 5 * 60 * 1000;
const groupLevelCache = new Map<number, { level: number; at: number }>();
async function getGroupLevel(bridge: BridgeInterface, groupId: number, noCache?: boolean): Promise<number> {
async function getGroupLevel(
bridge: BridgeInterface,
groupId: number,
noCache?: boolean,
): Promise<number> {
if (!noCache) {
const c = groupLevelCache.get(groupId);
if (c && Date.now() - c.at < GROUP_LEVEL_TTL_MS) return c.level;
const cached = groupLevelCache.get(groupId);
if (cached && Date.now() - cached.at < GROUP_LEVEL_TTL_MS) return cached.level;
}
try {
const detail = await bridge.apis.contacts.fetchGroupDetail(groupId);
const level = detail?.level ?? 0;
groupLevelCache.set(groupId, { level, at: Date.now() });
return level;
} catch {
} catch (err) {
if (noCache) throw err;
log.warn(
'group detail refresh failed, using roster metadata: uin=%s group=%d err=%s',
bridge.identity.uin,
groupId,
err instanceof Error ? (err.stack ?? err.message) : String(err),
);
return 0;
}
}
@@ -110,7 +127,11 @@ async function getGroupLevel(bridge: BridgeInterface, groupId: number, noCache?:
// here; this only memoizes the per-id server query so a burst of invites for the
// same group doesn't hammer 0x88D_0 (which would risk a rate-limit / kick).
const NON_MEMBER_GROUP_TTL_MS = 5 * 60 * 1000;
const nonMemberGroupCache = new Map<number, { info: JsonObject; at: number }>();
const nonMemberGroupCache = new Map<string, { info: JsonObject; at: number }>();
function nonMemberGroupCacheKey(bridge: BridgeInterface, groupId: number): string {
return `${bridge.identity.uin}:${groupId}`;
}
export async function getGroupInfo(
bridge: BridgeInterface,
@@ -120,8 +141,14 @@ export async function getGroupInfo(
if (noCache || !bridge.identity.findGroup(groupId)) {
try {
await bridge.apis.contacts.fetchGroupList();
} catch {
// Use cached data.
} catch (err) {
if (noCache) throw err;
log.warn(
'group list refresh failed, using cached roster: uin=%s group=%d err=%s',
bridge.identity.uin,
groupId,
err instanceof Error ? (err.stack ?? err.message) : String(err),
);
}
}
const g = bridge.identity.findGroup(groupId);
@@ -135,13 +162,15 @@ export async function getGroupInfo(
group_create_time: g.createTime ?? 0,
group_level: await getGroupLevel(bridge, groupId, noCache),
group_memo: g.memo ?? '',
group_all_shut: g.allMuted ? -1 : 0,
};
}
// Not a joined group — fall back to the by-id server lookup so a group invite
// can still resolve its name. Cached with a short TTL (skipped when noCache).
const cacheKey = nonMemberGroupCacheKey(bridge, groupId);
if (!noCache) {
const cached = nonMemberGroupCache.get(groupId);
const cached = nonMemberGroupCache.get(cacheKey);
if (cached && Date.now() - cached.at < NON_MEMBER_GROUP_TTL_MS) return { ...cached.info };
}
try {
@@ -156,12 +185,19 @@ export async function getGroupInfo(
group_create_time: detail.createTime ?? 0,
group_level: detail.level ?? 0,
group_memo: detail.memo ?? '',
group_all_shut: detail.allMuted ? -1 : 0,
};
nonMemberGroupCache.set(groupId, { info, at: Date.now() });
nonMemberGroupCache.set(cacheKey, { info, at: Date.now() });
return { ...info };
}
} catch {
// Server lookup failed (no such group / denied) — fall through to null.
} catch (err) {
if (noCache) throw err;
log.warn(
'non-member group lookup failed: uin=%s group=%d err=%s',
bridge.identity.uin,
groupId,
err instanceof Error ? (err.stack ?? err.message) : String(err),
);
}
return null;
}
+73 -5
View File
@@ -202,7 +202,7 @@ describe('onebot/contact-actions / getGroupFiles', () => {
describe('onebot/contact-actions / getGroupList', () => {
it('triggers fetch when the in-memory roster is empty', async () => {
const fetched = [{ ...makeGroup(100, 'Group A'), remark: '工作群' }];
const fetched = [{ ...makeGroup(100, 'Group A'), remark: '工作群', allMuted: true }];
// `groups` starts empty; the fetch callback flips it to mimic
// bridge.apis.contacts.fetchGroupList writing back through identity.rememberGroups.
let groups: QQGroupInfo[] = [];
@@ -219,6 +219,7 @@ describe('onebot/contact-actions / getGroupList', () => {
group_remark: '工作群',
member_count: 0, max_member_count: 500,
group_create_time: 0, group_level: 0, group_memo: '',
group_all_shut: -1,
}]);
});
@@ -242,14 +243,13 @@ describe('onebot/contact-actions / getGroupList', () => {
expect(bridge.apis.contacts.fetchGroupList).toHaveBeenCalledOnce();
});
it('serves the stale cache when the fetch path throws', async () => {
it('propagates fetch failures when noCache=true', async () => {
const cached = [makeGroup(400, 'Group D')];
const bridge = fakeBridge({
fetchGroupList: vi.fn(async () => { throw new Error('boom'); }),
identity: fakeIdentity({ groups: cached }),
});
const out = await getGroupList(bridge, true);
expect(out[0]).toMatchObject({ group_id: 400, group_name: 'Group D' });
await expect(getGroupList(bridge, true)).rejects.toThrow('boom');
});
});
@@ -259,6 +259,7 @@ describe('onebot/contact-actions / getGroupInfo', () => {
const findGroup = vi.fn((groupId: number) => groupId === 500 ? cached : null);
const bridge = fakeBridge({
fetchGroupList: vi.fn(async () => []),
fetchGroupDetail: vi.fn(async () => cached),
identity: fakeIdentity({ findGroup }),
});
const out = await getGroupInfo(bridge, 500);
@@ -270,6 +271,38 @@ describe('onebot/contact-actions / getGroupInfo', () => {
expect(bridge.apis.contacts.fetchGroupList).not.toHaveBeenCalled();
});
it('keeps joined-group mute state on the roster source across level-cache hits', async () => {
const cached = { ...makeGroup(510, 'Muted Group'), allMuted: true };
const fetchGroupDetail = vi.fn(async () => ({
...cached,
level: 6,
allMuted: false,
}));
const bridge = fakeBridge({
fetchGroupList: vi.fn(async () => []),
fetchGroupDetail,
identity: fakeIdentity({ findGroup: (groupId: number) => groupId === 510 ? cached : null }),
});
const first = await getGroupInfo(bridge, 510);
const second = await getGroupInfo(bridge, 510);
expect(first).toMatchObject({ group_level: 6, group_all_shut: -1 });
expect(second).toMatchObject({ group_level: 6, group_all_shut: -1 });
expect(fetchGroupDetail).toHaveBeenCalledTimes(1);
});
it('propagates detail refresh failures when noCache=true', async () => {
const cached = makeGroup(520, 'Refresh Group');
const bridge = fakeBridge({
fetchGroupList: vi.fn(async () => [cached]),
fetchGroupDetail: vi.fn(async () => { throw new Error('detail unavailable'); }),
identity: fakeIdentity({ findGroup: (groupId: number) => groupId === 520 ? cached : null }),
});
await expect(getGroupInfo(bridge, 520, true)).rejects.toThrow('detail unavailable');
});
it('triggers fetch when the group is unknown to the cache', async () => {
const cached = makeGroup(600, 'Group F');
let known = false;
@@ -277,6 +310,7 @@ describe('onebot/contact-actions / getGroupInfo', () => {
const fetchGroupList = vi.fn(async () => { known = true; return [cached]; });
const bridge = fakeBridge({
fetchGroupList,
fetchGroupDetail: vi.fn(async () => cached),
identity: fakeIdentity({ findGroup }),
});
const out = await getGroupInfo(bridge, 600);
@@ -294,7 +328,10 @@ describe('onebot/contact-actions / getGroupInfo', () => {
});
it('resolves a non-member group via the by-id server lookup (e.g. a group invite name)', async () => {
const fetchGroupDetail = vi.fn(async () => makeGroup(7100, '邀请来的群'));
const fetchGroupDetail = vi.fn(async () => ({
...makeGroup(7100, '邀请来的群'),
allMuted: true,
}));
const bridge = fakeBridge({
fetchGroupList: vi.fn(async () => []),
fetchGroupDetail,
@@ -306,6 +343,7 @@ describe('onebot/contact-actions / getGroupInfo', () => {
group_id: 7100,
group_name: '邀请来的群',
group_remark: '',
group_all_shut: -1,
});
});
@@ -334,6 +372,36 @@ describe('onebot/contact-actions / getGroupInfo', () => {
await getGroupInfo(bridge, 7300, true);
expect(fetchGroupDetail).toHaveBeenCalledTimes(2);
});
it('isolates non-member group details between accounts', async () => {
const groupId = 7400;
const firstFetch = vi.fn(async () => ({
...makeGroup(groupId, 'Account A View'),
allMuted: true,
}));
const secondFetch = vi.fn(async () => ({
...makeGroup(groupId, 'Account B View'),
allMuted: false,
}));
const firstBridge = fakeBridge({
fetchGroupList: vi.fn(async () => []),
fetchGroupDetail: firstFetch,
identity: fakeIdentity({ uin: '10001', findGroup: () => null }),
});
const secondBridge = fakeBridge({
fetchGroupList: vi.fn(async () => []),
fetchGroupDetail: secondFetch,
identity: fakeIdentity({ uin: '10002', findGroup: () => null }),
});
const first = await getGroupInfo(firstBridge, groupId);
const second = await getGroupInfo(secondBridge, groupId);
expect(first).toMatchObject({ group_name: 'Account A View', group_all_shut: -1 });
expect(second).toMatchObject({ group_name: 'Account B View', group_all_shut: 0 });
expect(firstFetch).toHaveBeenCalledOnce();
expect(secondFetch).toHaveBeenCalledOnce();
});
});
describe('onebot/contact-actions / getGroupMemberList', () => {
@@ -0,0 +1,47 @@
import { describe, expect, it, vi } from 'vitest';
import { ACTION_REGISTRY } from '../src/actions';
const getGroupInfo = ACTION_REGISTRY.actions.find(action => action.canonical === 'get_group_info')?.spec;
const getGroupList = ACTION_REGISTRY.actions.find(action => action.canonical === 'get_group_list')?.spec;
const getGroupInfoEx = ACTION_REGISTRY.actions.find(action => action.canonical === 'get_group_info_ex')?.spec;
const getGroupDetailInfo = ACTION_REGISTRY.actions.find(action => action.canonical === 'get_group_detail_info')?.spec;
if (!getGroupInfo || !getGroupList || !getGroupInfoEx || !getGroupDetailInfo) {
throw new Error('group info actions missing');
}
describe('group information actions', () => {
it('returns and documents the group-wide mute state', async () => {
const response = await getGroupInfo.toHandler({} as any)({ group_id: 123456 });
const infoSchema = getGroupInfo.describe().returnsSchema;
const listSchema = getGroupList.describe().returnsSchema;
expect(response).toMatchObject({
status: 'ok',
data: { group_id: 123456, group_all_shut: 0 },
});
expect(infoSchema?.properties).toHaveProperty('group_all_shut');
expect(infoSchema?.required).toContain('group_all_shut');
expect(listSchema?.items?.properties).toHaveProperty('group_all_shut');
expect(listSchema?.items?.required).toContain('group_all_shut');
});
it.each([
['get_group_info_ex', getGroupInfoEx],
['get_group_detail_info', getGroupDetailInfo],
])('%s exposes the shared group information result', async (_name, action) => {
const getGroupInfoResult = {
group_id: 123456,
group_name: 'Muted Group',
group_all_shut: -1,
};
const getGroupInfoProvider = vi.fn(async () => getGroupInfoResult);
const response = await action.toHandler({
getGroupInfo: getGroupInfoProvider,
} as any)({ group_id: 123456, no_cache: true });
expect(response).toMatchObject({ status: 'ok', data: getGroupInfoResult });
expect(getGroupInfoProvider).toHaveBeenCalledWith(123456, true);
expect(action.describe().returnsSchema?.properties).toHaveProperty('group_all_shut');
});
});
@@ -315,6 +315,7 @@ export interface OidbGroupDetailFlags {
question?: pb<24, bool>;
answer?: pb<25, string>;
maxAdminCount?: pb<29, string>;
shutUpAllTimestamp?: pb<59, bool>;
}
export interface OidbGroupDetailConfig {
uin?: pb<1, uint_64>;
+2
View File
@@ -82,6 +82,7 @@ export interface OidbSvcTrpcTcp0xFE5_2GroupInfo {
description?: pb<18, string>;
question?: pb<19, string>;
announcement?: pb<30, string>;
shutUpAllTimestamp?: pb<31, uint_32>;
}
export interface OidbSvcTrpcTcp0xFE5_2CustomInfo {
@@ -115,6 +116,7 @@ export interface OidbSvcTrpcTcp0x88D_0Results {
question?: pb<24, string>;
answer?: pb<25, string>;
maxAdminCount?: pb<29, uint_64>;
shutUpAllTimestamp?: pb<59, uint_32>;
}
export interface OidbSvcTrpcTcp0x88D_0ResponseGroupInfo {
uin?: pb<1, uint_64>;
@@ -33,6 +33,7 @@ export namespace FetchGroupDetail {
ownerUid: on, createTime: on, maxMemberCount: on, memberCount: on,
level: on, name: '', noticePreview: '', uin: on, lastSequence: on,
lastMessageTime: on, question: on, answer: '', maxAdminCount: '',
shutUpAllTimestamp: on,
},
},
});
+2
View File
@@ -57,6 +57,8 @@ export interface QQGroupInfo {
level?: number;
/** Group memo / announcement preview. '' when unknown (#197). */
memo?: string;
/** Whether the group currently has group-wide mute enabled. */
allMuted?: boolean;
}
export interface GroupRequestInfo {
@@ -3,13 +3,33 @@
// matching Lagrange's GetGroupInfoService) and the response decode.
import { describe, expect, it, vi } from 'vitest';
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import {
protobuf_decode,
protobuf_encode,
type pb,
type uint_32,
type uint_64,
} from '@snowluma/proton';
import type { OidbBase, OidbSvcTrpcTcp0x88D_0Response } from '@snowluma/proto-defs/oidb';
import type { OidbGroupDetailRequest } from '@snowluma/proto-defs/oidb-actions/base';
import type { SendPacketResult } from '@snowluma/common/packet-sender';
import { FetchGroupDetail } from '../../../src/oidb-services/contacts/fetch-group-detail';
interface GroupDetailResultsFixture {
name?: pb<15, string>;
shutUpAllTimestamp?: pb<59, uint_32>;
}
interface GroupDetailInfoFixture {
uin?: pb<1, uint_64>;
results?: pb<3, GroupDetailResultsFixture>;
}
interface GroupDetailResponseFixture {
groupInfo?: pb<1, GroupDetailInfoFixture>;
}
function makeSender(body?: OidbSvcTrpcTcp0x88D_0Response) {
const responseData = body !== undefined
? Buffer.from(protobuf_encode<OidbBase<OidbSvcTrpcTcp0x88D_0Response>>({ body }))
@@ -33,6 +53,8 @@ describe('FetchGroupDetail namespace', () => {
expect(out.config?.flags?.name).toBe(''); // string mask → request the name
expect(out.config?.flags?.memberCount).toBe(true);
expect(out.config?.flags?.maxMemberCount).toBe(true);
expect((out.config?.flags as { shutUpAllTimestamp?: boolean })?.shutUpAllTimestamp)
.toBe(true);
});
});
@@ -66,5 +88,28 @@ describe('FetchGroupDetail namespace', () => {
expect(out.groupInfo?.results?.memberCount).toBe(42n);
expect(out.groupInfo?.results?.maxMemberCount).toBe(500n);
});
it('decodes the group-wide mute timestamp from a detail response', async () => {
const responseData = Buffer.from(protobuf_encode<OidbBase<GroupDetailResponseFixture>>({
body: {
groupInfo: {
uin: 601692726n,
results: { name: 'Muted Group', shutUpAllTimestamp: 4_294_967_295 },
},
},
}));
const sender = makeSender();
sender.sendRawPacket.mockResolvedValue({
success: true,
gotResponse: true,
errorCode: 0,
errorMessage: '',
responseData,
});
const out = await FetchGroupDetail.invoke(sender, { groupUin: 601692726 });
expect(out.groupInfo?.results?.shutUpAllTimestamp).toBe(4_294_967_295);
});
});
});
@@ -1,11 +1,31 @@
import { describe, expect, it, vi } from 'vitest';
import { protobuf_decode } from '@snowluma/proton';
import {
protobuf_decode,
protobuf_encode,
type pb,
type pb_repeated,
type uint_32,
} from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { OidbGroupListRequest } from '@snowluma/proto-defs/oidb-actions/base';
import type { SendPacketResult } from '@snowluma/common/packet-sender';
import { FetchGroupList } from '../../../src/oidb-services/contacts/fetch-group-list';
interface GroupInfoFixture {
groupName?: pb<5, string>;
shutUpAllTimestamp?: pb<31, uint_32>;
}
interface GroupFixture {
groupUin?: pb<3, uint_32>;
info?: pb<4, GroupInfoFixture>;
}
interface GroupListFixture {
groups?: pb_repeated<2, GroupFixture>;
}
function makeSender() {
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: Buffer.alloc(0) };
return { sendRawPacket: vi.fn(async () => r) };
@@ -35,6 +55,7 @@ describe('FetchGroupList namespace', () => {
const env = protobuf_decode<OidbBase<OidbGroupListRequest>>(bytes);
expect(env.body?.config?.config1?.groupName).toBe(true);
expect(env.body?.config?.config1?.memberCount).toBe(true);
expect(env.body?.config?.config1?.field31).toBe(true);
expect(env.body?.config?.config2?.remark).toBe(true);
for (const field of ['field1', 'field2', 'field4', 'field5', 'field6', 'field7', 'field8'] as const) {
expect(env.body?.config?.config2?.[field] ?? false, field).toBe(false);
@@ -43,5 +64,28 @@ describe('FetchGroupList namespace', () => {
expect(env.body?.config?.config1?.field5002 ?? false).toBe(false);
expect(env.body?.config?.config1?.field5003 ?? false).toBe(false);
});
it('decodes the group-wide mute timestamp returned with the joined roster', async () => {
const responseData = Buffer.from(protobuf_encode<OidbBase<GroupListFixture>>({
body: {
groups: [{
groupUin: 123456789,
info: { groupName: 'Muted Group', shutUpAllTimestamp: 4_294_967_295 },
}],
},
}));
const sender = makeSender();
sender.sendRawPacket.mockResolvedValue({
success: true,
gotResponse: true,
errorCode: 0,
errorMessage: '',
responseData,
});
const out = await FetchGroupList.invoke(sender);
expect(out.groups?.[0]?.info?.shutUpAllTimestamp).toBe(4_294_967_295);
});
});
});
+10 -4
View File
@@ -466,12 +466,18 @@ export abstract class SnowLumaApiClient {
return this.call('get_clientkey', {}, options);
}
getGroupInfoEx(groupId: number, options?: RequestOptions) {
return this.call('get_group_info_ex', { group_id: groupId }, options);
getGroupInfoEx(groupId: number, options?: RequestOptions & { noCache?: boolean }) {
return this.call('get_group_info_ex', {
group_id: groupId,
no_cache: options?.noCache,
}, options);
}
getGroupDetailInfo(groupId: number, options?: RequestOptions) {
return this.call('get_group_detail_info', { group_id: groupId }, options);
getGroupDetailInfo(groupId: number, options?: RequestOptions & { noCache?: boolean }) {
return this.call('get_group_detail_info', {
group_id: groupId,
no_cache: options?.noCache,
}, options);
}
/** Calls any registered SnowLuma action and returns the response data. */
+2 -2
View File
@@ -232,8 +232,8 @@ export interface SnowLumaActionMap {
click_inline_keyboard_button: { params: JsonObject; data: JsonValue };
set_group_sign: { params: JsonObject; data: EmptyData };
send_group_sign: { params: JsonObject; data: EmptyData };
get_group_info_ex: { params: GroupIdParams; data: JsonObject };
get_group_detail_info: { params: GroupIdParams; data: JsonObject };
get_group_info_ex: { params: GetGroupInfoParams; data: JsonObject };
get_group_detail_info: { params: GetGroupInfoParams; data: JsonObject };
trans_group_file: { params: JsonObject; data: JsonValue };
rename_group_file: { params: JsonObject; data: JsonValue };
get_file: { params: GetMediaParams; data: JsonValue };
+17
View File
@@ -7,6 +7,23 @@ import {
} from '../src';
describe('SnowLumaHttpClient', () => {
it('maps extended group-info refresh options to OneBot field names', async () => {
const fetchImpl = vi.fn().mockImplementation(async () => new Response(JSON.stringify({
status: 'ok',
retcode: 0,
data: null,
})));
const client = new SnowLumaHttpClient({ fetch: fetchImpl });
await client.getGroupInfoEx(123456, { noCache: true });
await client.getGroupDetailInfo(123456, { noCache: true });
expect(fetchImpl.mock.calls.map((call) => JSON.parse((call[1] as RequestInit).body as string))).toEqual([
{ action: 'get_group_info_ex', params: { group_id: 123456, no_cache: true } },
{ action: 'get_group_detail_info', params: { group_id: 123456, no_cache: true } },
]);
});
it('maps system-face catalog helpers to their OneBot actions', async () => {
const fetchImpl = vi.fn().mockImplementation(async () => new Response(JSON.stringify({
status: 'ok',