Merge pull request #392 from Fripine/feat/more-music-types

feat: support more types of music cards
This commit is contained in:
手瓜一十雪 2024-09-21 15:00:59 +08:00 committed by GitHub
commit f49b94edb9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 22 deletions

View File

@ -1,14 +1,15 @@
export interface IdMusicSignPostData { export interface IdMusicSignPostData {
type: 'qq' | '163', type: 'qq' | '163' | 'kugou' | 'migu' | 'kuwo',
id: string | number, id: string | number,
} }
export interface CustomMusicSignPostData { export interface CustomMusicSignPostData {
type: 'custom', type: 'qq' | '163' | 'kugou' | 'migu' | 'kuwo' | 'custom',
id: undefined,
url: string, url: string,
audio: string, audio?: string,
title: string, title?: string,
image?: string, image: string,
singer?: string singer?: string
} }

View File

@ -547,32 +547,28 @@ export class OneBotMsgApi {
[OB11MessageDataType.music]: async ({ data }, context) => { [OB11MessageDataType.music]: async ({ data }, context) => {
// 保留, 直到...找到更好的解决方案 // 保留, 直到...找到更好的解决方案
if (data.type === 'custom') { if (data.id !== undefined) {
if (!['qq', '163', 'kugou', 'kuwo', 'migu'].includes(data.type)) {
this.core.context.logger.logError('音乐卡片type错误, 只支持qq、163、kugou、kuwo、migu当前type:', data.type);
return undefined;
}
} else {
if (!['qq', '163', 'kugou', 'kuwo', 'migu', 'custom'].includes(data.type)) {
this.core.context.logger.logError('音乐卡片type错误, 只支持qq、163、kugou、kuwo、migu、custom当前type:', data.type);
return undefined;
}
if (!data.url) { if (!data.url) {
this.core.context.logger.logError('自定义音卡缺少参数url'); this.core.context.logger.logError('自定义音卡缺少参数url');
return undefined; return undefined;
} }
if (!data.audio) { if (!data.image) {
this.core.context.logger.logError('自定义音卡缺少参数audio'); this.core.context.logger.logError('自定义音卡缺少参数image');
return undefined;
}
if (!data.title) {
this.core.context.logger.logError('自定义音卡缺少参数title');
return undefined;
}
} else {
if (!['qq', '163'].includes(data.type)) {
this.core.context.logger.logError('音乐卡片type错误, 只支持qq、163、custom当前type:', data.type);
return undefined;
}
if (!data.id) {
this.core.context.logger.logError('音乐卡片缺少参数id');
return undefined; return undefined;
} }
} }
let postData: IdMusicSignPostData | CustomMusicSignPostData; let postData: IdMusicSignPostData | CustomMusicSignPostData;
if (data.type === 'custom' && data.content) { if (data.id === undefined && data.content) {
const { content, ...others } = data; const { content, ...others } = data;
postData = { singer: content, ...others }; postData = { singer: content, ...others };
} else { } else {