feat(onebot): expose group member mute expiry
Return the mute expiry timestamp from group member list and detail actions, using zero when no active mute is available. Keep the public action descriptions and generated MCP catalog aligned, and cover muted, unmuted, and unavailable member responses. Refs #314
This commit is contained in:
@@ -5080,6 +5080,10 @@
|
||||
"type": "integer",
|
||||
"description": "最后发言时间戳(秒)"
|
||||
},
|
||||
"shut_up_timestamp": {
|
||||
"type": "integer",
|
||||
"description": "禁言结束时间戳(秒,未禁言时为 0)"
|
||||
},
|
||||
"level": {
|
||||
"type": "string",
|
||||
"description": "群等级"
|
||||
@@ -5235,6 +5239,10 @@
|
||||
"type": "integer",
|
||||
"description": "最后发言时间戳(秒)"
|
||||
},
|
||||
"shut_up_timestamp": {
|
||||
"type": "integer",
|
||||
"description": "禁言结束时间戳(秒,未禁言时为 0)"
|
||||
},
|
||||
"level": {
|
||||
"type": "string",
|
||||
"description": "群等级"
|
||||
|
||||
@@ -5083,6 +5083,10 @@ export const ACTIONS: CatalogAction[] = [
|
||||
"type": "integer",
|
||||
"description": "最后发言时间戳(秒)"
|
||||
},
|
||||
"shut_up_timestamp": {
|
||||
"type": "integer",
|
||||
"description": "禁言结束时间戳(秒,未禁言时为 0)"
|
||||
},
|
||||
"level": {
|
||||
"type": "string",
|
||||
"description": "群等级"
|
||||
@@ -5238,6 +5242,10 @@ export const ACTIONS: CatalogAction[] = [
|
||||
"type": "integer",
|
||||
"description": "最后发言时间戳(秒)"
|
||||
},
|
||||
"shut_up_timestamp": {
|
||||
"type": "integer",
|
||||
"description": "禁言结束时间戳(秒,未禁言时为 0)"
|
||||
},
|
||||
"level": {
|
||||
"type": "string",
|
||||
"description": "群等级"
|
||||
|
||||
@@ -107,6 +107,7 @@ export const actions = [
|
||||
age: { type: 'integer', description: '年龄' },
|
||||
join_time: { type: 'integer', description: '入群时间戳(秒)' },
|
||||
last_sent_time: { type: 'integer', description: '最后发言时间戳(秒)' },
|
||||
shut_up_timestamp: { type: 'integer', description: '禁言结束时间戳(秒,未禁言时为 0)' },
|
||||
level: { type: 'string', description: '群等级' },
|
||||
role: { type: 'string', enum: ['owner', 'admin', 'member'], description: '角色' },
|
||||
title: { type: 'string', description: '专属头衔' },
|
||||
@@ -146,6 +147,7 @@ export const actions = [
|
||||
age: { type: 'integer', description: '年龄' },
|
||||
join_time: { type: 'integer', description: '入群时间戳(秒)' },
|
||||
last_sent_time: { type: 'integer', description: '最后发言时间戳(秒)' },
|
||||
shut_up_timestamp: { type: 'integer', description: '禁言结束时间戳(秒,未禁言时为 0)' },
|
||||
level: { type: 'string', description: '群等级' },
|
||||
role: { type: 'string', enum: ['owner', 'admin', 'member'], description: '角色' },
|
||||
title: { type: 'string', description: '专属头衔' },
|
||||
@@ -167,6 +169,7 @@ export const actions = [
|
||||
group_id: groupId, user_id: userId, nickname: '', card: '',
|
||||
is_robot: false,
|
||||
sex: 'unknown', age: 0, join_time: 0, last_sent_time: 0,
|
||||
shut_up_timestamp: 0,
|
||||
level: '0', role: 'member', title: '',
|
||||
});
|
||||
}
|
||||
@@ -174,6 +177,7 @@ export const actions = [
|
||||
group_id: groupId, user_id: userId, nickname: '', card: '',
|
||||
is_robot: false,
|
||||
sex: 'unknown', age: 0, join_time: 0, last_sent_time: 0,
|
||||
shut_up_timestamp: 0,
|
||||
level: '0', role: 'member', title: '',
|
||||
});
|
||||
},
|
||||
|
||||
@@ -431,6 +431,7 @@ function formatGroupMember(
|
||||
age: 0,
|
||||
join_time: member.joinTime,
|
||||
last_sent_time: member.lastSentTime,
|
||||
shut_up_timestamp: member.shutUpTime,
|
||||
level: String(member.level),
|
||||
role: member.role,
|
||||
title: member.title,
|
||||
|
||||
@@ -1,15 +1,42 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import type { GroupMemberInfo } from '@snowluma/protocol/qq-info';
|
||||
|
||||
import { ACTION_REGISTRY } from '../src/actions';
|
||||
import {
|
||||
getGroupMemberInfo as readGroupMemberInfo,
|
||||
getGroupMemberList as readGroupMemberList,
|
||||
} from '../src/modules/contact-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) {
|
||||
const getGroupMemberList = ACTION_REGISTRY.actions.find(action => action.canonical === 'get_group_member_list')?.spec;
|
||||
const getGroupMemberInfo = ACTION_REGISTRY.actions.find(action => action.canonical === 'get_group_member_info')?.spec;
|
||||
if (
|
||||
!getGroupInfo || !getGroupList || !getGroupInfoEx || !getGroupDetailInfo
|
||||
|| !getGroupMemberList || !getGroupMemberInfo
|
||||
) {
|
||||
throw new Error('group info actions missing');
|
||||
}
|
||||
|
||||
function makeMember(overrides: Partial<GroupMemberInfo>): GroupMemberInfo {
|
||||
return {
|
||||
uin: 654321,
|
||||
uid: 'u_member',
|
||||
nickname: 'Member',
|
||||
card: '',
|
||||
isRobot: false,
|
||||
role: 'member',
|
||||
level: 1,
|
||||
title: '',
|
||||
joinTime: 0,
|
||||
lastSentTime: 0,
|
||||
shutUpTime: 0,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe('group information actions', () => {
|
||||
it('returns and documents the group-wide mute state', async () => {
|
||||
const response = await getGroupInfo.toHandler({} as any)({ group_id: 123456 });
|
||||
@@ -44,4 +71,49 @@ describe('group information actions', () => {
|
||||
expect(getGroupInfoProvider).toHaveBeenCalledWith(123456, true);
|
||||
expect(action.describe().returnsSchema?.properties).toHaveProperty('group_all_shut');
|
||||
});
|
||||
|
||||
it('returns and documents member mute expiry across member actions', async () => {
|
||||
const mutedUntil = 2_000_000_000;
|
||||
const member = makeMember({ nickname: 'Muted Member', shutUpTime: mutedUntil });
|
||||
const bridge = {
|
||||
identity: {
|
||||
uin: '123456',
|
||||
findGroupMember: (groupId: number, userId: number) =>
|
||||
groupId === 123456 && userId === member.uin ? member : null,
|
||||
},
|
||||
apis: { contacts: { fetchGroupMemberList: vi.fn(async () => [member]) } },
|
||||
} as any;
|
||||
const listResponse = await getGroupMemberList.toHandler({
|
||||
getGroupMemberList: (groupId: number, noCache?: boolean) =>
|
||||
readGroupMemberList(bridge, groupId, noCache),
|
||||
} as any)({ group_id: 123456 });
|
||||
const infoResponse = await getGroupMemberInfo.toHandler({
|
||||
getGroupMemberInfo: (groupId: number, userId: number, noCache?: boolean) =>
|
||||
readGroupMemberInfo(bridge, groupId, userId, noCache),
|
||||
} as any)({ group_id: 123456, user_id: member.uin });
|
||||
|
||||
expect(listResponse).toMatchObject({
|
||||
status: 'ok',
|
||||
data: [{ user_id: member.uin, shut_up_timestamp: mutedUntil }],
|
||||
});
|
||||
expect(infoResponse).toMatchObject({
|
||||
status: 'ok',
|
||||
data: { user_id: member.uin, shut_up_timestamp: mutedUntil },
|
||||
});
|
||||
expect(getGroupMemberList.describe().returnsSchema?.items?.properties)
|
||||
.toHaveProperty('shut_up_timestamp');
|
||||
expect(getGroupMemberInfo.describe().returnsSchema?.properties)
|
||||
.toHaveProperty('shut_up_timestamp');
|
||||
});
|
||||
|
||||
it('returns a zero mute expiry when the member is unavailable', async () => {
|
||||
const response = await getGroupMemberInfo.toHandler({
|
||||
getGroupMemberInfo: vi.fn(async () => null),
|
||||
} as any)({ group_id: 123456, user_id: 654323 });
|
||||
|
||||
expect(response).toMatchObject({
|
||||
status: 'ok',
|
||||
data: { user_id: 654323, shut_up_timestamp: 0 },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user