build: 1.3.5-beta7

This commit is contained in:
手瓜一十雪 2024-05-12 22:57:32 +08:00
parent 76c91d226c
commit d11cef5907

View File

@ -152,179 +152,179 @@ export async function createSendElements(messageData: OB11MessageData[], group:
continue; continue;
} }
switch (sendMsg.type) { switch (sendMsg.type) {
case OB11MessageDataType.text: { case OB11MessageDataType.text: {
const text = sendMsg.data?.text; const text = sendMsg.data?.text;
if (text) { if (text) {
sendElements.push(SendMsgElementConstructor.text(sendMsg.data!.text)); sendElements.push(SendMsgElementConstructor.text(sendMsg.data!.text));
}
}
break;
case OB11MessageDataType.at: {
if (!group) {
continue;
}
let atQQ = sendMsg.data?.qq;
if (atQQ) {
atQQ = atQQ.toString();
if (atQQ === 'all') {
sendElements.push(SendMsgElementConstructor.at(atQQ, atQQ, AtType.atAll, '全体成员'));
}
else {
// const atMember = group?.members.find(m => m.uin == atQQ)
const atMember = await getGroupMember(group?.groupCode, atQQ);
if (atMember) {
sendElements.push(SendMsgElementConstructor.at(atQQ, atMember.uid, AtType.atUser, atMember.cardName || atMember.nick));
}
} }
} }
} break;
break; case OB11MessageDataType.at: {
case OB11MessageDataType.reply: { if (!group) {
const replyMsgId = sendMsg.data.id; continue;
if (replyMsgId) {
const replyMsg = await dbUtil.getMsgByShortId(parseInt(replyMsgId));
if (replyMsg) {
sendElements.push(SendMsgElementConstructor.reply(replyMsg.msgSeq, replyMsg.msgId, replyMsg.senderUin!, replyMsg.senderUin!));
} }
} let atQQ = sendMsg.data?.qq;
} if (atQQ) {
break; atQQ = atQQ.toString();
case OB11MessageDataType.face: { if (atQQ === 'all') {
const faceId = sendMsg.data?.id; sendElements.push(SendMsgElementConstructor.at(atQQ, atQQ, AtType.atAll, '全体成员'));
if (faceId) {
sendElements.push(SendMsgElementConstructor.face(parseInt(faceId)));
}
}
break;
case OB11MessageDataType.mface: {
sendElements.push(
SendMsgElementConstructor.mface(sendMsg.data.emoji_package_id, sendMsg.data.emoji_id, sendMsg.data.key, sendMsg.data.summary),
);
}
break;
case OB11MessageDataType.image:
case OB11MessageDataType.file:
case OB11MessageDataType.video:
case OB11MessageDataType.voice: {
let file = sendMsg.data?.file;
const payloadFileName = sendMsg.data?.name;
if (file) {
const cache = await dbUtil.getFileCacheByName(file);
if (cache) {
if (fs.existsSync(cache.path)) {
file = 'file://' + cache.path;
}
else if (cache.url) {
file = cache.url;
} }
else { else {
const fileMsg = await dbUtil.getMsgByLongId(cache.msgId); // const atMember = group?.members.find(m => m.uin == atQQ)
if (fileMsg) { const atMember = await getGroupMember(group?.groupCode, atQQ);
const downloadPath = await NTQQFileApi.downloadMedia(fileMsg.msgId, fileMsg.chatType, fileMsg.peerUid, if (atMember) {
cache.elementId, '', ''); sendElements.push(SendMsgElementConstructor.at(atQQ, atMember.uid, AtType.atUser, atMember.cardName || atMember.nick));
cache.path = downloadPath!; }
dbUtil.updateFileCache(cache).then(); }
}
}
break;
case OB11MessageDataType.reply: {
const replyMsgId = sendMsg.data.id;
if (replyMsgId) {
const replyMsg = await dbUtil.getMsgByShortId(parseInt(replyMsgId));
if (replyMsg) {
sendElements.push(SendMsgElementConstructor.reply(replyMsg.msgSeq, replyMsg.msgId, replyMsg.senderUin!, replyMsg.senderUin!));
}
}
}
break;
case OB11MessageDataType.face: {
const faceId = sendMsg.data?.id;
if (faceId) {
sendElements.push(SendMsgElementConstructor.face(parseInt(faceId)));
}
}
break;
case OB11MessageDataType.mface: {
sendElements.push(
SendMsgElementConstructor.mface(sendMsg.data.emoji_package_id, sendMsg.data.emoji_id, sendMsg.data.key, sendMsg.data.summary),
);
}
break;
case OB11MessageDataType.image:
case OB11MessageDataType.file:
case OB11MessageDataType.video:
case OB11MessageDataType.voice: {
let file = sendMsg.data?.file;
const payloadFileName = sendMsg.data?.name;
if (file) {
const cache = await dbUtil.getFileCacheByName(file);
if (cache) {
if (fs.existsSync(cache.path)) {
file = 'file://' + cache.path; file = 'file://' + cache.path;
} }
// await sleep(1000); else if (cache.url) {
file = cache.url;
// log('download result', downloadPath);
// log('下载完成后的msg', msg);
}
logDebug('找到文件缓存', file);
}
const { path, isLocal, fileName, errMsg } = (await uri2local(file));
if (errMsg) {
logError('文件下载失败', errMsg);
throw Error('文件下载失败' + errMsg);
// throw (errMsg);
// continue
}
if (path) {
if (!isLocal) { // 只删除http和base64转过来的文件
deleteAfterSentFiles.push(path);
}
if (sendMsg.type === OB11MessageDataType.file) {
logDebug('发送文件', path, payloadFileName || fileName);
sendElements.push(await SendMsgElementConstructor.file(path, payloadFileName || fileName));
}
else if (sendMsg.type === OB11MessageDataType.video) {
logDebug('发送视频', path, payloadFileName || fileName);
let thumb = sendMsg.data?.thumb;
if (thumb) {
const uri2LocalRes = await uri2local(thumb);
if (uri2LocalRes.success) {
thumb = uri2LocalRes.path;
}
} }
sendElements.push(await SendMsgElementConstructor.video(path, payloadFileName || fileName, thumb)); else {
const fileMsg = await dbUtil.getMsgByLongId(cache.msgId);
if (fileMsg) {
const downloadPath = await NTQQFileApi.downloadMedia(fileMsg.msgId, fileMsg.chatType, fileMsg.peerUid,
cache.elementId, '', '');
cache.path = downloadPath!;
dbUtil.updateFileCache(cache).then();
file = 'file://' + cache.path;
}
// await sleep(1000);
// log('download result', downloadPath);
// log('下载完成后的msg', msg);
}
logDebug('找到文件缓存', file);
} }
else if (sendMsg.type === OB11MessageDataType.voice) { const { path, isLocal, fileName, errMsg } = (await uri2local(file));
sendElements.push(await SendMsgElementConstructor.ptt(path)); if (errMsg) {
logError('文件下载失败', errMsg);
throw Error('文件下载失败' + errMsg);
// throw (errMsg);
// continue
} }
else if (sendMsg.type === OB11MessageDataType.image) { if (path) {
sendElements.push(await SendMsgElementConstructor.pic(path, sendMsg.data.summary || '', <PicSubType>parseInt(sendMsg.data?.subType?.toString() || '0'))); if (!isLocal) { // 只删除http和base64转过来的文件
deleteAfterSentFiles.push(path);
}
if (sendMsg.type === OB11MessageDataType.file) {
logDebug('发送文件', path, payloadFileName || fileName);
sendElements.push(await SendMsgElementConstructor.file(path, payloadFileName || fileName));
}
else if (sendMsg.type === OB11MessageDataType.video) {
logDebug('发送视频', path, payloadFileName || fileName);
let thumb = sendMsg.data?.thumb;
if (thumb) {
const uri2LocalRes = await uri2local(thumb);
if (uri2LocalRes.success) {
thumb = uri2LocalRes.path;
}
}
sendElements.push(await SendMsgElementConstructor.video(path, payloadFileName || fileName, thumb));
}
else if (sendMsg.type === OB11MessageDataType.voice) {
sendElements.push(await SendMsgElementConstructor.ptt(path));
}
else if (sendMsg.type === OB11MessageDataType.image) {
sendElements.push(await SendMsgElementConstructor.pic(path, sendMsg.data.summary || '', <PicSubType>parseInt(sendMsg.data?.subType?.toString() || '0')));
}
} }
} }
} }
} break;
break; case OB11MessageDataType.json: {
case OB11MessageDataType.json: { sendElements.push(SendMsgElementConstructor.ark(sendMsg.data.data));
sendElements.push(SendMsgElementConstructor.ark(sendMsg.data.data)); }
} break;
break; case OB11MessageDataType.dice: {
case OB11MessageDataType.dice: { const resultId = sendMsg.data?.result;
const resultId = sendMsg.data?.result; sendElements.push(SendMsgElementConstructor.dice(resultId));
sendElements.push(SendMsgElementConstructor.dice(resultId)); }
} break;
break; case OB11MessageDataType.RPS: {
case OB11MessageDataType.RPS: { const resultId = sendMsg.data?.result;
const resultId = sendMsg.data?.result; sendElements.push(SendMsgElementConstructor.rps(resultId));
sendElements.push(SendMsgElementConstructor.rps(resultId)); }
} break;
break; 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;
break; case OB11MessageDataType.music: {
case OB11MessageDataType.music: { const musicData = sendMsg.data;
const musicData = sendMsg.data; if (musicData.type === 'custom') {
if (musicData.type === 'custom') { if (!musicData.url) {
if (!musicData.url) { logError('自定义音卡缺少参数url');
logError('自定义音卡缺少参数url'); break;
break; }
if (!musicData.audio) {
logError('自定义音卡缺少参数audio');
break;
}
if (!musicData.title) {
logError('自定义音卡缺少参数title');
break;
}
} }
if (!musicData.audio) { else {
logError('自定义音卡缺少参数audio'); if (!['qq', '163'].includes(musicData.type)) {
break; logError('音乐卡片type错误, 只支持qq、163、custom当前type:', musicData.type);
break;
}
if (!musicData.id) {
logError('音乐卡片缺少参数id');
break;
}
} }
if (!musicData.title) { const postData = { ...sendMsg.data } as IdMusicSignPostData | CustomMusicSignPostData;
logError('自定义音卡缺少参数title'); if (sendMsg.data.type === 'custom' && sendMsg.data.content) {
break; (postData as CustomMusicSignPostData).singer = sendMsg.data.content;
delete (postData as OB11MessageCustomMusic['data']).content;
}
const musicMsgElement = await genMusicElement(postData);
logDebug('生成音乐消息', musicMsgElement);
if (musicMsgElement) {
sendElements.push(musicMsgElement);
} }
} }
else {
if (!['qq', '163'].includes(musicData.type)) {
logError('音乐卡片type错误, 只支持qq、163、custom当前type:', musicData.type);
break;
}
if (!musicData.id) {
logError('音乐卡片缺少参数id');
break;
}
}
const postData = { ...sendMsg.data } as IdMusicSignPostData | CustomMusicSignPostData;
if (sendMsg.data.type === 'custom' && sendMsg.data.content) {
(postData as CustomMusicSignPostData).singer = sendMsg.data.content;
delete (postData as OB11MessageCustomMusic['data']).content;
}
const musicMsgElement = await genMusicElement(postData);
logDebug('生成音乐消息', musicMsgElement);
if (musicMsgElement) {
sendElements.push(musicMsgElement);
}
}
} }
} }
@ -564,11 +564,15 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
logDebug(sendElementsSplit); logDebug(sendElementsSplit);
} }
// log("分割后的转发节点", sendElementsSplit) // log("分割后的转发节点", sendElementsSplit)
let MsgNodeList: Promise<RawMessage>[] = [];
for (const eles of sendElementsSplit) { for (const eles of sendElementsSplit) {
const nodeMsg = await sendMsg(selfPeer, eles, [], true); MsgNodeList.push(sendMsg(selfPeer, eles, [], true));
nodeMsgIds.push(nodeMsg.msgId); //await sleep(10);
await sleep(500); }
logDebug('转发节点生成成功', nodeMsg.msgId); for (const msgNode of MsgNodeList) {
let result = await msgNode;
nodeMsgIds.push(result.msgId);
logDebug('转发节点生成成功', result.msgId);
} }
deleteAfterSentFiles.map(f => fs.unlink(f, () => { deleteAfterSentFiles.map(f => fs.unlink(f, () => {
})); }));