fix(onebot): expose group descriptions separately (#491)
Expose group descriptions without replacing the existing group memo behavior. Fixes #490 Refs #491
This commit is contained in:
10 files changed
+170
-1
No files matched your search
@@ -272,6 +272,10 @@ export class ContactsApi {
|
|||||||
// is not in the list (0x88D_0 detail only), so it stays undefined here.
|
// is not in the list (0x88D_0 detail only), so it stays undefined here.
|
||||||
createTime: raw.info?.createdTime ?? 0,
|
createTime: raw.info?.createdTime ?? 0,
|
||||||
memo: raw.info?.announcement || raw.info?.description || '',
|
memo: raw.info?.announcement || raw.info?.description || '',
|
||||||
|
// #490: expose the description alongside `memo`. QQ fills in either
|
||||||
|
// field alone, so folding both into `memo` made the description
|
||||||
|
// unreachable whenever an announcement was also set.
|
||||||
|
description: raw.info?.description ?? '',
|
||||||
allMuted: isGroupAllMuted(raw.info?.shutUpAllTimestamp),
|
allMuted: isGroupAllMuted(raw.info?.shutUpAllTimestamp),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -299,7 +303,9 @@ export class ContactsApi {
|
|||||||
memberMax: Number(r.maxMemberCount ?? 0n),
|
memberMax: Number(r.maxMemberCount ?? 0n),
|
||||||
members: new Map(),
|
members: new Map(),
|
||||||
// #197: the detail is the only source of `level`; it also carries
|
// #197: the detail is the only source of `level`; it also carries
|
||||||
// createTime + the notice preview (memo).
|
// createTime + the notice preview (memo). `description` is deliberately
|
||||||
|
// left unset — 0x88D_0 has no description tag, so for a group the bot
|
||||||
|
// hasn't joined there is nothing to report (#490).
|
||||||
createTime: Number(r.createTime ?? 0n),
|
createTime: Number(r.createTime ?? 0n),
|
||||||
level: Number(r.level ?? 0n),
|
level: Number(r.level ?? 0n),
|
||||||
memo: r.noticePreview ?? '',
|
memo: r.noticePreview ?? '',
|
||||||
|
|||||||
@@ -249,6 +249,63 @@ describe('apis/contacts / group roster', () => {
|
|||||||
expect(rememberGroups).toHaveBeenCalledWith(groups);
|
expect(rememberGroups).toHaveBeenCalledWith(groups);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// #490: `memo` prefers the announcement, so a group with both fields set used
|
||||||
|
// to lose its description entirely. The description must stay readable.
|
||||||
|
it('keeps the group description readable when an announcement is also set (#490)', async () => {
|
||||||
|
const sendRawPacket = vi.fn(async () => groupListPacket({
|
||||||
|
groups: [{
|
||||||
|
groupUin: 123456789,
|
||||||
|
info: {
|
||||||
|
groupName: 'Both Set',
|
||||||
|
description: '简介正文',
|
||||||
|
announcement: '公告正文',
|
||||||
|
},
|
||||||
|
}],
|
||||||
|
}));
|
||||||
|
const api = new ContactsApi({
|
||||||
|
sendRawPacket,
|
||||||
|
identity: { rememberGroups: vi.fn() },
|
||||||
|
} as any);
|
||||||
|
|
||||||
|
const [group] = await api.fetchGroupList();
|
||||||
|
|
||||||
|
expect(group?.memo).toBe('公告正文');
|
||||||
|
expect(group?.description).toBe('简介正文');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('reports the description for a group that has no announcement (#490)', async () => {
|
||||||
|
const sendRawPacket = vi.fn(async () => groupListPacket({
|
||||||
|
groups: [{
|
||||||
|
groupUin: 123456789,
|
||||||
|
info: { groupName: 'Description Only', description: '只有简介' },
|
||||||
|
}],
|
||||||
|
}));
|
||||||
|
const api = new ContactsApi({
|
||||||
|
sendRawPacket,
|
||||||
|
identity: { rememberGroups: vi.fn() },
|
||||||
|
} as any);
|
||||||
|
|
||||||
|
const [group] = await api.fetchGroupList();
|
||||||
|
|
||||||
|
// memo still falls back to the description (unchanged pre-#490 behaviour).
|
||||||
|
expect(group?.memo).toBe('只有简介');
|
||||||
|
expect(group?.description).toBe('只有简介');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('leaves the description unset on a non-member detail lookup (#490)', async () => {
|
||||||
|
const sendRawPacket = vi.fn(async () => groupDetailPacket({
|
||||||
|
groupInfo: { uin: 123456789n, results: { name: 'Not Joined', noticePreview: '公告预览' } },
|
||||||
|
}));
|
||||||
|
const api = new ContactsApi({ sendRawPacket, identity: {} } as any);
|
||||||
|
|
||||||
|
const detail = await api.fetchGroupDetail(123456789);
|
||||||
|
|
||||||
|
// 0x88D_0 has no description tag, so there is nothing to expose — the field
|
||||||
|
// must stay absent rather than echo the announcement preview.
|
||||||
|
expect(detail?.memo).toBe('公告预览');
|
||||||
|
expect(detail?.description).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
it('maps the group-wide mute timestamp from a single-group detail', async () => {
|
it('maps the group-wide mute timestamp from a single-group detail', async () => {
|
||||||
const sendRawPacket = vi.fn(async () => groupDetailPacket({
|
const sendRawPacket = vi.fn(async () => groupDetailPacket({
|
||||||
groupInfo: {
|
groupInfo: {
|
||||||
|
|||||||
@@ -4428,6 +4428,10 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "群简介 / 公告预览"
|
"description": "群简介 / 公告预览"
|
||||||
},
|
},
|
||||||
|
"group_description": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "群简介(公告不算;未加入的群为空)"
|
||||||
|
},
|
||||||
"group_all_shut": {
|
"group_all_shut": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"enum": [
|
"enum": [
|
||||||
@@ -5036,6 +5040,10 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "群简介 / 公告预览"
|
"description": "群简介 / 公告预览"
|
||||||
},
|
},
|
||||||
|
"group_description": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "群简介(公告不算;未加入的群为空)"
|
||||||
|
},
|
||||||
"group_all_shut": {
|
"group_all_shut": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"enum": [
|
"enum": [
|
||||||
@@ -5138,6 +5146,10 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "群简介 / 公告预览"
|
"description": "群简介 / 公告预览"
|
||||||
},
|
},
|
||||||
|
"group_description": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "群简介(公告不算;未加入的群为空)"
|
||||||
|
},
|
||||||
"group_all_shut": {
|
"group_all_shut": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"enum": [
|
"enum": [
|
||||||
@@ -5241,6 +5253,10 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "群简介 / 公告预览"
|
"description": "群简介 / 公告预览"
|
||||||
},
|
},
|
||||||
|
"group_description": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "群简介(公告不算;未加入的群为空)"
|
||||||
|
},
|
||||||
"group_all_shut": {
|
"group_all_shut": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"enum": [
|
"enum": [
|
||||||
|
|||||||
@@ -4431,6 +4431,10 @@ export const ACTIONS: CatalogAction[] = [
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "群简介 / 公告预览"
|
"description": "群简介 / 公告预览"
|
||||||
},
|
},
|
||||||
|
"group_description": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "群简介(公告不算;未加入的群为空)"
|
||||||
|
},
|
||||||
"group_all_shut": {
|
"group_all_shut": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"enum": [
|
"enum": [
|
||||||
@@ -5039,6 +5043,10 @@ export const ACTIONS: CatalogAction[] = [
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "群简介 / 公告预览"
|
"description": "群简介 / 公告预览"
|
||||||
},
|
},
|
||||||
|
"group_description": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "群简介(公告不算;未加入的群为空)"
|
||||||
|
},
|
||||||
"group_all_shut": {
|
"group_all_shut": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"enum": [
|
"enum": [
|
||||||
@@ -5141,6 +5149,10 @@ export const ACTIONS: CatalogAction[] = [
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "群简介 / 公告预览"
|
"description": "群简介 / 公告预览"
|
||||||
},
|
},
|
||||||
|
"group_description": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "群简介(公告不算;未加入的群为空)"
|
||||||
|
},
|
||||||
"group_all_shut": {
|
"group_all_shut": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"enum": [
|
"enum": [
|
||||||
@@ -5244,6 +5256,10 @@ export const ACTIONS: CatalogAction[] = [
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "群简介 / 公告预览"
|
"description": "群简介 / 公告预览"
|
||||||
},
|
},
|
||||||
|
"group_description": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "群简介(公告不算;未加入的群为空)"
|
||||||
|
},
|
||||||
"group_all_shut": {
|
"group_all_shut": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"enum": [
|
"enum": [
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ export const groupInfoReturnsSchema = {
|
|||||||
group_create_time: { type: 'integer', description: '建群时间戳(秒)' },
|
group_create_time: { type: 'integer', description: '建群时间戳(秒)' },
|
||||||
group_level: { type: 'integer', description: '群等级' },
|
group_level: { type: 'integer', description: '群等级' },
|
||||||
group_memo: { type: 'string', description: '群简介 / 公告预览' },
|
group_memo: { type: 'string', description: '群简介 / 公告预览' },
|
||||||
|
group_description: { type: 'string', description: '群简介(公告不算;未加入的群为空)' },
|
||||||
group_all_shut: { type: 'integer', enum: [-1, 0], description: '是否开启全员禁言(-1 开启,0 关闭)' },
|
group_all_shut: { type: 'integer', enum: [-1, 0], description: '是否开启全员禁言(-1 开启,0 关闭)' },
|
||||||
},
|
},
|
||||||
required: [
|
required: [
|
||||||
@@ -40,6 +41,7 @@ export const actions = [
|
|||||||
group_create_time: { type: 'integer', description: '建群时间戳(秒)' },
|
group_create_time: { type: 'integer', description: '建群时间戳(秒)' },
|
||||||
group_level: { type: 'integer', description: '群等级(列表批量场景恒 0,详见 get_group_info)' },
|
group_level: { type: 'integer', description: '群等级(列表批量场景恒 0,详见 get_group_info)' },
|
||||||
group_memo: { type: 'string', description: '群简介 / 公告预览' },
|
group_memo: { type: 'string', description: '群简介 / 公告预览' },
|
||||||
|
group_description: { type: 'string', description: '群简介(公告不算;未加入的群为空)' },
|
||||||
group_all_shut: { type: 'integer', enum: [-1, 0], description: '是否开启全员禁言(-1 开启,0 关闭)' },
|
group_all_shut: { type: 'integer', enum: [-1, 0], description: '是否开启全员禁言(-1 开启,0 关闭)' },
|
||||||
},
|
},
|
||||||
required: [
|
required: [
|
||||||
@@ -77,6 +79,7 @@ export const actions = [
|
|||||||
group_create_time: 0,
|
group_create_time: 0,
|
||||||
group_level: 0,
|
group_level: 0,
|
||||||
group_memo: '',
|
group_memo: '',
|
||||||
|
group_description: '',
|
||||||
group_all_shut: 0,
|
group_all_shut: 0,
|
||||||
};
|
};
|
||||||
if (ctx.getGroupInfo) {
|
if (ctx.getGroupInfo) {
|
||||||
|
|||||||
@@ -101,6 +101,9 @@ export async function getGroupList(
|
|||||||
group_create_time: g.createTime ?? 0,
|
group_create_time: g.createTime ?? 0,
|
||||||
group_level: g.level ?? 0,
|
group_level: g.level ?? 0,
|
||||||
group_memo: g.memo ?? '',
|
group_memo: g.memo ?? '',
|
||||||
|
// #490: the description is its own field; group_memo prefers the
|
||||||
|
// announcement, so it can't be used to recover the description.
|
||||||
|
group_description: g.description ?? '',
|
||||||
group_all_shut: g.allMuted ? -1 : 0,
|
group_all_shut: g.allMuted ? -1 : 0,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@@ -175,6 +178,7 @@ export async function getGroupInfo(
|
|||||||
group_create_time: g.createTime ?? 0,
|
group_create_time: g.createTime ?? 0,
|
||||||
group_level: await getGroupLevel(bridge, groupId, noCache),
|
group_level: await getGroupLevel(bridge, groupId, noCache),
|
||||||
group_memo: g.memo ?? '',
|
group_memo: g.memo ?? '',
|
||||||
|
group_description: g.description ?? '',
|
||||||
group_all_shut: g.allMuted ? -1 : 0,
|
group_all_shut: g.allMuted ? -1 : 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -198,6 +202,10 @@ export async function getGroupInfo(
|
|||||||
group_create_time: detail.createTime ?? 0,
|
group_create_time: detail.createTime ?? 0,
|
||||||
group_level: detail.level ?? 0,
|
group_level: detail.level ?? 0,
|
||||||
group_memo: detail.memo ?? '',
|
group_memo: detail.memo ?? '',
|
||||||
|
// #490: always '' here — the non-member detail lookup has no
|
||||||
|
// description to read (see QQGroupInfo.description). The key is still
|
||||||
|
// returned so the response shape doesn't change with membership.
|
||||||
|
group_description: detail.description ?? '',
|
||||||
group_all_shut: detail.allMuted ? -1 : 0,
|
group_all_shut: detail.allMuted ? -1 : 0,
|
||||||
};
|
};
|
||||||
nonMemberGroupCache.set(cacheKey, { info, at: Date.now() });
|
nonMemberGroupCache.set(cacheKey, { info, at: Date.now() });
|
||||||
|
|||||||
@@ -228,10 +228,44 @@ describe('onebot/contact-actions / getGroupList', () => {
|
|||||||
group_remark: '工作群',
|
group_remark: '工作群',
|
||||||
member_count: 0, max_member_count: 500,
|
member_count: 0, max_member_count: 500,
|
||||||
group_create_time: 0, group_level: 0, group_memo: '',
|
group_create_time: 0, group_level: 0, group_memo: '',
|
||||||
|
group_description: '',
|
||||||
group_all_shut: -1,
|
group_all_shut: -1,
|
||||||
}]);
|
}]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// #490: group_description must carry the description itself, not a copy of
|
||||||
|
// group_memo (which prefers the announcement).
|
||||||
|
it('exposes the group description separately from the memo (#490)', async () => {
|
||||||
|
const fetched = [{
|
||||||
|
...makeGroup(150, 'Both Set'),
|
||||||
|
memo: '公告正文',
|
||||||
|
description: '简介正文',
|
||||||
|
}];
|
||||||
|
const bridge = fakeBridge({
|
||||||
|
fetchGroupList: vi.fn(async () => fetched),
|
||||||
|
identity: fakeIdentity({ groups: fetched }),
|
||||||
|
});
|
||||||
|
|
||||||
|
const out = await getGroupList(bridge);
|
||||||
|
|
||||||
|
expect(out[0]).toMatchObject({
|
||||||
|
group_memo: '公告正文',
|
||||||
|
group_description: '简介正文',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('reports an empty group_description when QQ returns no description (#490)', async () => {
|
||||||
|
const fetched = [makeGroup(160, 'No Description')];
|
||||||
|
const bridge = fakeBridge({
|
||||||
|
fetchGroupList: vi.fn(async () => fetched),
|
||||||
|
identity: fakeIdentity({ groups: fetched }),
|
||||||
|
});
|
||||||
|
|
||||||
|
const out = await getGroupList(bridge);
|
||||||
|
|
||||||
|
expect(out[0]).toMatchObject({ group_memo: '', group_description: '' });
|
||||||
|
});
|
||||||
|
|
||||||
it('skips fetch when cache is populated and noCache is omitted', async () => {
|
it('skips fetch when cache is populated and noCache is omitted', async () => {
|
||||||
const cached = [makeGroup(200, 'Group B')];
|
const cached = [makeGroup(200, 'Group B')];
|
||||||
const bridge = fakeBridge({
|
const bridge = fakeBridge({
|
||||||
|
|||||||
@@ -117,6 +117,23 @@ describe('group information actions', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// #490: group_memo prefers the announcement, so the group description needs
|
||||||
|
// its own documented field.
|
||||||
|
it('documents the group description on both group-info results', async () => {
|
||||||
|
const infoSchema = getGroupInfo.describe().returnsSchema;
|
||||||
|
const listSchema = getGroupList.describe().returnsSchema;
|
||||||
|
|
||||||
|
expect(infoSchema?.properties).toHaveProperty('group_description');
|
||||||
|
expect(listSchema?.items?.properties).toHaveProperty('group_description');
|
||||||
|
// Never required: only the group list carries it, so a non-member lookup
|
||||||
|
// legitimately returns ''.
|
||||||
|
expect(infoSchema?.required ?? []).not.toContain('group_description');
|
||||||
|
|
||||||
|
// The no-provider fallback must still carry the key.
|
||||||
|
const response = await getGroupInfo.toHandler({} as any)({ group_id: 123456 });
|
||||||
|
expect(response).toMatchObject({ status: 'ok', data: { group_description: '' } });
|
||||||
|
});
|
||||||
|
|
||||||
it('documents qidian flags on both member-list and single-member results', () => {
|
it('documents qidian flags on both member-list and single-member results', () => {
|
||||||
const listSchema = getGroupMemberList.describe().returnsSchema;
|
const listSchema = getGroupMemberList.describe().returnsSchema;
|
||||||
const infoSchema = getGroupMemberInfo.describe().returnsSchema;
|
const infoSchema = getGroupMemberInfo.describe().returnsSchema;
|
||||||
|
|||||||
@@ -730,6 +730,7 @@ describe('buildApiContext contact reads', () => {
|
|||||||
group_create_time: 100,
|
group_create_time: 100,
|
||||||
group_level: 2,
|
group_level: 2,
|
||||||
group_memo: 'rules',
|
group_memo: 'rules',
|
||||||
|
group_description: '',
|
||||||
group_all_shut: -1,
|
group_all_shut: -1,
|
||||||
}]);
|
}]);
|
||||||
expect(fetchGroupList).not.toHaveBeenCalled();
|
expect(fetchGroupList).not.toHaveBeenCalled();
|
||||||
@@ -758,6 +759,7 @@ describe('buildApiContext contact reads', () => {
|
|||||||
group_create_time: 0,
|
group_create_time: 0,
|
||||||
group_level: 6,
|
group_level: 6,
|
||||||
group_memo: '',
|
group_memo: '',
|
||||||
|
group_description: '',
|
||||||
group_all_shut: 0,
|
group_all_shut: 0,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -77,6 +77,16 @@ export interface QQGroupInfo {
|
|||||||
level?: number;
|
level?: number;
|
||||||
/** Group memo / announcement preview. '' when unknown (#197). */
|
/** Group memo / announcement preview. '' when unknown (#197). */
|
||||||
memo?: string;
|
memo?: string;
|
||||||
|
/**
|
||||||
|
* Group description (群简介 — `0xFE5_2` tag 18). '' when unknown.
|
||||||
|
*
|
||||||
|
* Kept apart from `memo` on purpose (#490): `memo` prefers the announcement,
|
||||||
|
* and QQ commonly has only one of the two set, so `memo` alone cannot tell a
|
||||||
|
* description from an announcement. Only the group list carries it — the
|
||||||
|
* `0x88D_0` detail has no description tag, so this stays undefined for a
|
||||||
|
* group the account hasn't joined.
|
||||||
|
*/
|
||||||
|
description?: string;
|
||||||
/** Whether group-wide mute is currently in effect (expire still in the future). */
|
/** Whether group-wide mute is currently in effect (expire still in the future). */
|
||||||
allMuted?: boolean;
|
allMuted?: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user