fix(onebot): resolve signed-int32 reply ids
Reply segments treated negative message_id hashes as invalid, so quotes against those events were dropped.
This commit is contained in:
2 files changed
+33
-2
No files matched your search
@@ -211,7 +211,8 @@ export const ELEMENT_CODECS = {
|
|||||||
log.warn('could not quote the target message');
|
log.warn('could not quote the target message');
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (id <= 0) {
|
// message_id is a signed int32 hash; only 0 is invalid (#371).
|
||||||
|
if (id === 0) {
|
||||||
log.warn('could not quote the target message');
|
log.warn('could not quote the target message');
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -246,7 +247,10 @@ export const ELEMENT_CODECS = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Backward-compatible path: allow direct seq reply IDs.
|
// Backward-compatible path: allow direct seq reply IDs.
|
||||||
return id > 0 ? { type: 'reply', replySeq: id } : null;
|
// A negative OneBot id is never a QQ sequence.
|
||||||
|
if (id > 0) return { type: 'reply', replySeq: id };
|
||||||
|
log.warn('could not quote the target message');
|
||||||
|
return null;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -666,6 +666,33 @@ describe('parseMessage', () => {
|
|||||||
expect(result[0].replySeq).toBe(100);
|
expect(result[0].replySeq).toBe(100);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('resolves a signed-int32 message_id to the stored reply sequence (#371)', async () => {
|
||||||
|
const result = await parseMessage(
|
||||||
|
[
|
||||||
|
{ type: 'reply', data: { id: -188861750 } },
|
||||||
|
{ type: 'text', data: { text: '测试成功' } },
|
||||||
|
] as any,
|
||||||
|
false,
|
||||||
|
{ resolveReplySequence: (id) => id === -188861750 ? 4242 : null },
|
||||||
|
);
|
||||||
|
expect(result).toEqual([
|
||||||
|
{ type: 'reply', replySeq: 4242, replyMessageId: -188861750 },
|
||||||
|
{ type: 'text', text: '测试成功' },
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not treat an unresolved negative message_id as a QQ sequence (#371)', async () => {
|
||||||
|
const result = await parseMessage(
|
||||||
|
[
|
||||||
|
{ type: 'reply', data: { id: -188861750 } },
|
||||||
|
{ type: 'text', data: { text: '测试成功' } },
|
||||||
|
] as any,
|
||||||
|
false,
|
||||||
|
{ resolveReplySequence: () => null },
|
||||||
|
);
|
||||||
|
expect(result).toEqual([{ type: 'text', text: '测试成功' }]);
|
||||||
|
});
|
||||||
|
|
||||||
it('parses share as json card', async () => {
|
it('parses share as json card', async () => {
|
||||||
const result = await parseMessage(
|
const result = await parseMessage(
|
||||||
[{ type: 'share', data: { url: 'https://example.com', title: 'Test' } }] as any,
|
[{ type: 'share', data: { url: 'https://example.com', title: 'Test' } }] as any,
|
||||||
|
|||||||
Reference in new issue
Block a user