mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
feat: Music sign
This commit is contained in:
parent
3b25c4987c
commit
c46a4c75b1
@ -1,11 +1,12 @@
|
|||||||
1. 修复图片URL,支持Win/Linux X64获取Rkey
|
1. 修复图片URL,支持Win/Linux X64获取rkey, arm64暂不支持
|
||||||
2. 支持了设置已读群/私聊消息接口
|
2. 支持了设置已读群/私聊消息接口
|
||||||
3. 支持了好友添加上报事件
|
3. 支持了好友添加上报事件
|
||||||
4. 重构了商城表情URL拼接
|
4. 商城表情上报URL
|
||||||
5. 重构了Core日志与服务调用部分
|
5. 重构了Core日志与服务调用部分, 日志可在`config/napcat_<QQ号>.json`中配置日志开关和等级
|
||||||
6. 适配最新版Win 9.9.9 23159 提升了兼容性
|
6. 适配最新版Win 9.9.9 23159 提升了兼容性
|
||||||
7. 表情回应api和上报
|
7. 表情回应api和上报
|
||||||
8. 支持获取Cookies 实现更加稳定 API: /get_cookies
|
8. 支持获取Cookies 实现更加稳定 API: /get_cookies
|
||||||
9. 新增wsHost和httpHost配置 CONFIG: New
|
9. 新增wsHost和httpHost配置 CONFIG: New
|
||||||
10. 新增获取官方Bot账号范围 API: /get_robot_uin_range
|
10. 新增获取官方Bot账号范围 API: /get_robot_uin_range
|
||||||
11. 新增设置自身在线状态 API: /set_online_status
|
11. 新增设置自身在线状态 API: /set_online_status
|
||||||
|
12. 修复视频所需的 ffmpeg 路径不正确导致视频封面和市场获取失败
|
||||||
|
@ -29,6 +29,7 @@ import { uri2local } from '@/common/utils/file';
|
|||||||
import { getFriend, getGroup, getGroupMember, getUidByUin, selfInfo } from '@/common/data';
|
import { getFriend, getGroup, getGroupMember, getUidByUin, selfInfo } from '@/common/data';
|
||||||
import { NTQQMsgApi } from '../../../core/src/apis';
|
import { NTQQMsgApi } from '../../../core/src/apis';
|
||||||
import { NTQQFileApi } from '../../../core/src/apis';
|
import { NTQQFileApi } from '../../../core/src/apis';
|
||||||
|
import { ob11Config } from '@/onebot11/config';
|
||||||
|
|
||||||
const ALLOW_SEND_TEMP_MSG = false;
|
const ALLOW_SEND_TEMP_MSG = false;
|
||||||
|
|
||||||
@ -89,6 +90,74 @@ export function convertMessage2List(message: OB11MessageMixType, autoEscape = fa
|
|||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function genMusicElement(url: string, audio: string, title: string, image: string | undefined, singer: string | undefined): Promise<SendArkElement | undefined> {
|
||||||
|
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[] = []) {
|
export async function createSendElements(messageData: OB11MessageData[], group: Group | undefined, ignoreTypes: OB11MessageDataType[] = []) {
|
||||||
const sendElements: SendMessageElement[] = [];
|
const sendElements: SendMessageElement[] = [];
|
||||||
const deleteAfterSentFiles: string[] = [];
|
const deleteAfterSentFiles: string[] = [];
|
||||||
@ -220,6 +289,24 @@ export async function createSendElements(messageData: OB11MessageData[], group:
|
|||||||
case OB11MessageDataType.markdown: {
|
case OB11MessageDataType.markdown: {
|
||||||
const content = sendMsg.data?.content;
|
const content = sendMsg.data?.content;
|
||||||
sendElements.push(SendMsgElementConstructor.markdown(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<OB11PostSendMsg, ReturnDataType> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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;
|
export default SendMsg;
|
||||||
|
@ -23,6 +23,7 @@ export interface OB11Config {
|
|||||||
debug: boolean;
|
debug: boolean;
|
||||||
heartInterval: number;
|
heartInterval: number;
|
||||||
token: string;
|
token: string;
|
||||||
|
musicSignUrl: string;
|
||||||
|
|
||||||
read(): OB11Config;
|
read(): OB11Config;
|
||||||
|
|
||||||
@ -49,6 +50,7 @@ class Config extends ConfigBase<OB11Config> implements OB11Config {
|
|||||||
enableLocalFile2Url = true;
|
enableLocalFile2Url = true;
|
||||||
heartInterval = 30000;
|
heartInterval = 30000;
|
||||||
token = '';
|
token = '';
|
||||||
|
musicSignUrl = '';
|
||||||
|
|
||||||
getConfigPath() {
|
getConfigPath() {
|
||||||
return path.join(this.getConfigDir(), `onebot11_${selfInfo.uin}.json`);
|
return path.join(this.getConfigDir(), `onebot11_${selfInfo.uin}.json`);
|
||||||
|
@ -38,13 +38,13 @@ export async function logMessage(ob11Message: OB11Message){
|
|||||||
msgChain += `[文件]${segment.data.file} `;
|
msgChain += `[文件]${segment.data.file} `;
|
||||||
}
|
}
|
||||||
else if (segment.type === 'json') {
|
else if (segment.type === 'json') {
|
||||||
msgChain += `\n[json]${segment.data}\n`;
|
msgChain += `\n[json]${JSON.stringify(segment.data)}\n`;
|
||||||
}
|
}
|
||||||
else if (segment.type === 'markdown') {
|
else if (segment.type === 'markdown') {
|
||||||
msgChain += `\n[json]${segment.data.content}\n`;
|
msgChain += `\n[json]${segment.data.content}\n`;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
msgChain += `${segment}`;
|
msgChain += `${JSON.stringify(segment)}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -208,7 +208,8 @@ export interface OB11MessageCustomMusic {
|
|||||||
audio: string,
|
audio: string,
|
||||||
title: string,
|
title: string,
|
||||||
content?: string,
|
content?: string,
|
||||||
image?: string
|
image?: string,
|
||||||
|
singer?: string,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user