feat(onebot): implement get_group_shut_list via member shutUpTime

Derive the muted-member list from the TTL-cached group member list
(shutUpTime = absolute expiry epoch seconds), replacing the placeholder
that always returned []. NapCat-shaped output {user_id,nickname,shut_up_time}.
This commit is contained in:
DrSmoothl committed 2026-06-17 23:57:12 +08:00
1 parent 16920b4444
commit 8144dd9c27
2 files changed
+38 -13

No files matched your search

+12 -7
View File
@@ -705,15 +705,20 @@ export const actions = [
},
}),
// get_group_shut_list 依赖尚未封装的 oidb。
// 这里遵循 NapCat 约定返回空列表,避免调用方出错。
defineAction({
// get_group_shut_list — SnowLuma 无独立"禁言列表"cmd,按成员列表的
// shutUpTime 字段(绝对到期时间戳,秒)派生:保留仍在禁言中的成员。
// 走带 TTL 缓存的 fetchGroupMemberList(风控友好),与 NapCat 返回形状对齐。
groupAction({
name: 'get_group_shut_list',
summary: '获取群禁言列表(占位)',
summary: '获取群禁言列表',
readOnly: true,
params: {},
run: async () => {
return okResponse([]);
run: async (p, ctx) => {
const members = await ctx.bridge.apis.contacts.fetchGroupMemberList(p.group_id);
const nowSec = Math.floor(Date.now() / 1000);
const list = members
.filter((m) => (m.shutUpTime ?? 0) > nowSec)
.map((m) => ({ user_id: m.uin, nickname: m.nickname, shut_up_time: m.shutUpTime }));
return okResponse(list);
},
}),
+26 -6
View File
@@ -350,12 +350,6 @@ describe('extended-actions / get_group_ignore_add_request', () => {
});
});
describe('extended-actions / get_group_shut_list', () => {
it('returns empty list (oidb not yet wrapped)', async () => {
const res = await makeHandler(fakeCtx(fakeBridge())).handle('get_group_shut_list', {});
expect(res).toEqual({ status: 'ok', retcode: 0, data: [] });
});
});
// ─── Tier 1: delete_group_folder alias ───
@@ -620,3 +614,29 @@ describe('extended-actions / set_group_portrait', () => {
expect(res).toMatchObject({ status: 'failed', retcode: 100, wording: 'highway 500' });
});
});
// ─── Wave 1: get_group_shut_list ───
describe('extended-actions / get_group_shut_list', () => {
it('returns only currently-muted members in NapCat shape', async () => {
const nowSec = Math.floor(Date.now() / 1000);
const fetchGroupMemberList = vi.fn(async () => [
{ uin: 111, uid: 'u1', nickname: 'muted', card: '', role: 'member', level: 1, title: '', joinTime: 0, lastSentTime: 0, shutUpTime: nowSec + 3600 },
{ uin: 222, uid: 'u2', nickname: 'free', card: '', role: 'member', level: 1, title: '', joinTime: 0, lastSentTime: 0, shutUpTime: 0 },
{ uin: 333, uid: 'u3', nickname: 'expired', card: '', role: 'member', level: 1, title: '', joinTime: 0, lastSentTime: 0, shutUpTime: nowSec - 3600 },
]);
const bridge = fakeBridge({ fetchGroupMemberList: fetchGroupMemberList as any });
const res = await makeHandler(fakeCtx(bridge)).handle('get_group_shut_list', { group_id: 12345 });
expect(res.status).toBe('ok');
expect(fetchGroupMemberList).toHaveBeenCalledWith(12345);
expect(res.data).toEqual([
{ user_id: 111, nickname: 'muted', shut_up_time: nowSec + 3600 },
]);
});
it('rejects missing group_id', async () => {
const bridge = fakeBridge({ fetchGroupMemberList: vi.fn() as any });
const res = await makeHandler(fakeCtx(bridge)).handle('get_group_shut_list', {});
expect(res).toMatchObject({ status: 'failed', retcode: 1400 });
});
});