diff --git a/CHANGELOG.md b/CHANGELOG.md index bad5a961..9bf4ba1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,12 @@ -1. 修复图片URL,支持Win/Linux X64获取Rkey +1. 修复图片URL,支持Win/Linux X64获取rkey, arm64暂不支持 2. 支持了设置已读群/私聊消息接口 3. 支持了好友添加上报事件 -4. 重构了商城表情URL拼接 -5. 重构了Core日志与服务调用部分 +4. 商城表情上报URL +5. 重构了Core日志与服务调用部分, 日志可在`config/napcat_.json`中配置日志开关和等级 6. 适配最新版Win 9.9.9 23159 提升了兼容性 7. 表情回应api和上报 8. 支持获取Cookies 实现更加稳定 API: /get_cookies 9. 新增wsHost和httpHost配置 CONFIG: New 10. 新增获取官方Bot账号范围 API: /get_robot_uin_range 11. 新增设置自身在线状态 API: /set_online_status +12. 修复视频所需的 ffmpeg 路径不正确导致视频封面和市场获取失败 diff --git a/src/onebot11/action/msg/SendMsg.ts b/src/onebot11/action/msg/SendMsg.ts index 01e76987..ff44eab2 100644 --- a/src/onebot11/action/msg/SendMsg.ts +++ b/src/onebot11/action/msg/SendMsg.ts @@ -29,6 +29,7 @@ import { uri2local } from '@/common/utils/file'; import { getFriend, getGroup, getGroupMember, getUidByUin, selfInfo } from '@/common/data'; import { NTQQMsgApi } from '../../../core/src/apis'; import { NTQQFileApi } from '../../../core/src/apis'; +import { ob11Config } from '@/onebot11/config'; const ALLOW_SEND_TEMP_MSG = false; @@ -89,6 +90,74 @@ export function convertMessage2List(message: OB11MessageMixType, autoEscape = fa return message; } +async function genMusicElement(url: string, audio: string, title: string, image: string | undefined, singer: string | undefined): Promise { + const getMusicJson = new Promise((resolve, reject) => { + const postData = { + url, + audio, + title, + image, + singer + }; + fetch(ob11Config.musicSignUrl, { + method: 'POST', // 指定请求方法为 POST + headers: { + 'Content-Type': 'application/json' // 设置请求头,指明发送的数据类型为 JSON + }, + body: JSON.stringify(postData) // 将 JavaScript 对象转换为 JSON 字符串作为请求体 + }) + .then(response => { + if (!response.ok) { + reject(response.statusText); // 请求失败,返回错误信息 + } + return response.json(); // 解析 JSON 格式的响应体 + }) + .then(data => { + logDebug('音乐消息生成成功', data); + resolve(data); + }) + .catch(error => { + reject(error); + }); + }); + // const musicJson = { + // app: 'com.tencent.structmsg', + // config: { + // ctime: 1709689928, + // forward: 1, + // token: '5c1e4905f926dd3a64a4bd3841460351', + // type: 'normal' + // }, + // extra: { app_type: 1, appid: 100497308, uin: selfInfo.uin }, + // meta: { + // news: { + // action: '', + // android_pkg_name: '', + // app_type: 1, + // appid: 100497308, + // ctime: 1709689928, + // desc: content || title, + // jumpUrl: url, + // musicUrl: audio, + // preview: image, + // source_icon: 'https://p.qpic.cn/qqconnect/0/app_100497308_1626060999/100?max-age=2592000&t=0', + // source_url: '', + // tag: 'QQ音乐', + // title: title, + // uin: selfInfo.uin, + // } + // }, + // prompt: content || title, + // ver: '0.0.0.1', + // view: 'news' + // }; + try{ + const musicJson = await getMusicJson; + return SendMsgElementConstructor.ark(musicJson); + }catch (e) { + logError('生成音乐消息失败', e); + } +} export async function createSendElements(messageData: OB11MessageData[], group: Group | undefined, ignoreTypes: OB11MessageDataType[] = []) { const sendElements: SendMessageElement[] = []; const deleteAfterSentFiles: string[] = []; @@ -220,6 +289,24 @@ export async function createSendElements(messageData: OB11MessageData[], group: case OB11MessageDataType.markdown: { const content = sendMsg.data?.content; sendElements.push(SendMsgElementConstructor.markdown(content)); + }break; + case OB11MessageDataType.music:{ + const musicData = sendMsg.data; + if (musicData.type !== 'custom') { + logError('只支持custom类型的音乐卡片', musicData.type); + break; + } + else{ + try { + const musicMsgElement = await genMusicElement(musicData.url, musicData.audio, musicData.title, musicData.image, musicData.singer); + logDebug('生成音乐消息', musicMsgElement); + if (musicMsgElement) { + sendElements.push(musicMsgElement); + } + } catch (e) { + logError('生成音乐消息失败', e); + } + } } } @@ -527,41 +614,7 @@ export class SendMsg extends BaseAction { } - private genMusicElement(url: string, audio: string, title: string, content: string, image: string): SendArkElement { - const musicJson = { - app: 'com.tencent.structmsg', - config: { - ctime: 1709689928, - forward: 1, - token: '5c1e4905f926dd3a64a4bd3841460351', - type: 'normal' - }, - extra: { app_type: 1, appid: 100497308, uin: selfInfo.uin }, - meta: { - news: { - action: '', - android_pkg_name: '', - app_type: 1, - appid: 100497308, - ctime: 1709689928, - desc: content || title, - jumpUrl: url, - musicUrl: audio, - preview: image, - source_icon: 'https://p.qpic.cn/qqconnect/0/app_100497308_1626060999/100?max-age=2592000&t=0', - source_url: '', - tag: 'QQ音乐', - title: title, - uin: selfInfo.uin, - } - }, - prompt: content || title, - ver: '0.0.0.1', - view: 'news' - }; - return SendMsgElementConstructor.ark(musicJson); - } } export default SendMsg; diff --git a/src/onebot11/config.ts b/src/onebot11/config.ts index 84414292..ef2e654d 100644 --- a/src/onebot11/config.ts +++ b/src/onebot11/config.ts @@ -23,6 +23,7 @@ export interface OB11Config { debug: boolean; heartInterval: number; token: string; + musicSignUrl: string; read(): OB11Config; @@ -49,6 +50,7 @@ class Config extends ConfigBase implements OB11Config { enableLocalFile2Url = true; heartInterval = 30000; token = ''; + musicSignUrl = ''; getConfigPath() { return path.join(this.getConfigDir(), `onebot11_${selfInfo.uin}.json`); diff --git a/src/onebot11/log.ts b/src/onebot11/log.ts index 3f8c9f84..d4ff1ea9 100644 --- a/src/onebot11/log.ts +++ b/src/onebot11/log.ts @@ -38,13 +38,13 @@ export async function logMessage(ob11Message: OB11Message){ msgChain += `[文件]${segment.data.file} `; } else if (segment.type === 'json') { - msgChain += `\n[json]${segment.data}\n`; + msgChain += `\n[json]${JSON.stringify(segment.data)}\n`; } else if (segment.type === 'markdown') { msgChain += `\n[json]${segment.data.content}\n`; } else { - msgChain += `${segment}`; + msgChain += `${JSON.stringify(segment)}`; } } } diff --git a/src/onebot11/types.ts b/src/onebot11/types.ts index 2e238773..4265f2aa 100644 --- a/src/onebot11/types.ts +++ b/src/onebot11/types.ts @@ -208,7 +208,8 @@ export interface OB11MessageCustomMusic { audio: string, title: string, content?: string, - image?: string + image?: string, + singer?: string, } }