fix(onebot): accept id-less custom music cards (#319)
This commit is contained in:
3 files changed
+74
-5
No files matched your search
@@ -729,6 +729,48 @@ describe('parseMessage', () => {
|
||||
expect(parsed.meta.contact.type).toBe('group');
|
||||
});
|
||||
|
||||
it('accepts id-less custom music data with a platform type for NapCat compatibility', async () => {
|
||||
const card = JSON.stringify({
|
||||
app: 'com.tencent.structmsg',
|
||||
view: 'music',
|
||||
prompt: '[音乐]光',
|
||||
});
|
||||
const fetchMock = vi.fn(async (_input: string | URL | Request, _init?: RequestInit) => ({
|
||||
ok: true,
|
||||
text: async () => card,
|
||||
}));
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
try {
|
||||
const result = await parseMessage(
|
||||
[{
|
||||
type: 'music',
|
||||
data: {
|
||||
type: '163',
|
||||
url: 'https://music.example/song/3402687142',
|
||||
audio: 'https://cdn.example/3402687142.mp3',
|
||||
title: '光',
|
||||
image: 'https://cdn.example/3402687142.jpg',
|
||||
content: '陈粒',
|
||||
},
|
||||
}] as any,
|
||||
false,
|
||||
);
|
||||
|
||||
expect(result).toEqual([{ type: 'json', text: card }]);
|
||||
expect(JSON.parse(String(fetchMock.mock.calls[0]?.[1]?.body))).toEqual({
|
||||
type: '163',
|
||||
url: 'https://music.example/song/3402687142',
|
||||
audio: 'https://cdn.example/3402687142.mp3',
|
||||
title: '光',
|
||||
image: 'https://cdn.example/3402687142.jpg',
|
||||
singer: '陈粒',
|
||||
});
|
||||
} finally {
|
||||
vi.unstubAllGlobals();
|
||||
}
|
||||
});
|
||||
|
||||
it('parses signed music cards and buildSendElems preserves non-ASCII JSON', async () => {
|
||||
const card = JSON.stringify({
|
||||
app: 'com.tencent.structmsg',
|
||||
|
||||
Reference in new issue
Block a user