fix(onebot): skip unusable reply segments

Keep delivering valid message content when a reply target cannot be resolved, while retaining strict validation for all other segments.

Fixes #339
This commit is contained in:
DrSmoothl committed 2026-08-09 17:25:48 +08:00
1 parent dbf654ad57
commit 129b091081
4 files changed
+40 -21

No files matched your search

+9 -4
View File
@@ -194,16 +194,21 @@ describe('parseMessage', () => {
[{ type: 'at', data: { qq: '123abc' } }] as any,
false,
)).rejects.toMatchObject({ code: 'INVALID_FIELD' });
await expect(parseMessage(
[{ type: 'reply', data: { id: '456junk' } }] as any,
false,
)).rejects.toMatchObject({ code: 'INVALID_FIELD' });
await expect(parseMessage(
[{ type: 'face', data: { id: 1.9 } }] as any,
false,
)).rejects.toMatchObject({ code: 'INVALID_FIELD' });
});
it('skips an unusable reply segment while preserving sendable content', async () => {
const result = await parseMessage([
{ type: 'reply', data: { id: 'notice-event-id' } },
{ type: 'text', data: { text: 'still sent' } },
] as any, false);
expect(result).toEqual([{ type: 'text', text: 'still sent' }]);
});
it('parses image segment', async () => {
const result = await parseMessage(
[{ type: 'image', data: { file: 'https://example.com/img.png' } }] as any,