chore: run eslint --fix in onebot module
This commit is contained in:
1 parent
714f8327ea
commit
5990e0c2eb
110 files changed
+3830
-3827
No files matched your search
@@ -1,36 +1,36 @@
|
||||
import { OB11MessageData } from '@/onebot/types';
|
||||
|
||||
function checkSendMessage(sendMsgList: OB11MessageData[]) {
|
||||
function checkUri(uri: string): boolean {
|
||||
const pattern = /^(file:\/\/|http:\/\/|https:\/\/|base64:\/\/)/;
|
||||
return pattern.test(uri);
|
||||
}
|
||||
|
||||
for (const msg of sendMsgList) {
|
||||
if (msg['type'] && msg['data']) {
|
||||
const type = msg['type'];
|
||||
const data = msg['data'];
|
||||
if (type === 'text' && !data['text']) {
|
||||
return 400;
|
||||
} else if (['image', 'voice', 'record'].includes(type)) {
|
||||
if (!data['file']) {
|
||||
return 400;
|
||||
} else {
|
||||
if (checkUri(data['file'])) {
|
||||
return 200;
|
||||
} else {
|
||||
return 400;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (type === 'at' && !data['qq']) {
|
||||
return 400;
|
||||
} else if (type === 'reply' && !data['id']) {
|
||||
return 400;
|
||||
}
|
||||
} else {
|
||||
return 400;
|
||||
function checkUri(uri: string): boolean {
|
||||
const pattern = /^(file:\/\/|http:\/\/|https:\/\/|base64:\/\/)/;
|
||||
return pattern.test(uri);
|
||||
}
|
||||
}
|
||||
return 200;
|
||||
|
||||
for (const msg of sendMsgList) {
|
||||
if (msg['type'] && msg['data']) {
|
||||
const type = msg['type'];
|
||||
const data = msg['data'];
|
||||
if (type === 'text' && !data['text']) {
|
||||
return 400;
|
||||
} else if (['image', 'voice', 'record'].includes(type)) {
|
||||
if (!data['file']) {
|
||||
return 400;
|
||||
} else {
|
||||
if (checkUri(data['file'])) {
|
||||
return 200;
|
||||
} else {
|
||||
return 400;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (type === 'at' && !data['qq']) {
|
||||
return 400;
|
||||
} else if (type === 'reply' && !data['id']) {
|
||||
return 400;
|
||||
}
|
||||
} else {
|
||||
return 400;
|
||||
}
|
||||
}
|
||||
return 200;
|
||||
}
|
||||
@@ -10,23 +10,23 @@ export type MessageContext = {
|
||||
peer: Peer
|
||||
}
|
||||
async function handleOb11FileLikeMessage(
|
||||
coreContext: NapCatCore,
|
||||
{ data: inputdata }: OB11MessageFileBase,
|
||||
{ deleteAfterSentFiles }: MessageContext
|
||||
coreContext: NapCatCore,
|
||||
{ data: inputdata }: OB11MessageFileBase,
|
||||
{ deleteAfterSentFiles }: MessageContext
|
||||
) {
|
||||
//有的奇怪的框架将url作为参数 而不是file 此时优先url 同时注意可能传入的是非file://开头的目录 By Mlikiowa
|
||||
const { path, isLocal, fileName, errMsg, success } = (await uri2local(coreContext.NapCatTempPath, inputdata?.url || inputdata.file));
|
||||
//有的奇怪的框架将url作为参数 而不是file 此时优先url 同时注意可能传入的是非file://开头的目录 By Mlikiowa
|
||||
const { path, isLocal, fileName, errMsg, success } = (await uri2local(coreContext.NapCatTempPath, inputdata?.url || inputdata.file));
|
||||
|
||||
if (!success) {
|
||||
coreContext.context.logger.logError('文件下载失败', errMsg);
|
||||
throw Error('文件下载失败' + errMsg);
|
||||
}
|
||||
if (!success) {
|
||||
coreContext.context.logger.logError('文件下载失败', errMsg);
|
||||
throw Error('文件下载失败' + errMsg);
|
||||
}
|
||||
|
||||
if (!isLocal) { // 只删除http和base64转过来的文件
|
||||
deleteAfterSentFiles.push(path);
|
||||
}
|
||||
if (!isLocal) { // 只删除http和base64转过来的文件
|
||||
deleteAfterSentFiles.push(path);
|
||||
}
|
||||
|
||||
return { path, fileName: inputdata.name || fileName };
|
||||
return { path, fileName: inputdata.name || fileName };
|
||||
}
|
||||
|
||||
const _handlers: {
|
||||
@@ -38,149 +38,150 @@ const _handlers: {
|
||||
context: MessageContext
|
||||
) => Promise<SendMessageElement | undefined>
|
||||
} = {
|
||||
[OB11MessageDataType.text]: async (coreContext, { data: { text } }) => SendMsgElementConstructor.text(coreContext, text),
|
||||
[OB11MessageDataType.text]: async (coreContext, { data: { text } }) => SendMsgElementConstructor.text(coreContext, text),
|
||||
|
||||
[OB11MessageDataType.at]: async (coreContext, { data: { qq: atQQ } }, context) => {
|
||||
if (!context.peer) return undefined;
|
||||
[OB11MessageDataType.at]: async (coreContext, { data: { qq: atQQ } }, context) => {
|
||||
if (!context.peer) return undefined;
|
||||
|
||||
if (atQQ === 'all') return SendMsgElementConstructor.at(coreContext, atQQ, atQQ, AtType.atAll, '全体成员');
|
||||
if (atQQ === 'all') return SendMsgElementConstructor.at(coreContext, atQQ, atQQ, AtType.atAll, '全体成员');
|
||||
|
||||
// then the qq is a group member
|
||||
// Mlikiowa V2.0.0 Refactor Todo
|
||||
let uid = await coreContext.getApiContext().UserApi.getUidByUin(atQQ);
|
||||
if (!uid) throw new Error('Get Uid Error')
|
||||
return SendMsgElementConstructor.at(coreContext, atQQ, uid, AtType.atUser, "");
|
||||
},
|
||||
[OB11MessageDataType.reply]: async (coreContext, { data: { id } }) => {
|
||||
const replyMsgM = MessageUnique.getMsgIdAndPeerByShortId(parseInt(id));
|
||||
if (!replyMsgM) {
|
||||
coreContext.context.logger.logWarn('回复消息不存在', id);
|
||||
return undefined;
|
||||
}
|
||||
const NTQQMsgApi = coreContext.getApiContext().MsgApi;
|
||||
const replyMsg = (await NTQQMsgApi.getMsgsByMsgId(replyMsgM?.Peer!, [replyMsgM?.MsgId!])).msgList[0];
|
||||
return replyMsg ?
|
||||
SendMsgElementConstructor.reply(coreContext, replyMsg.msgSeq, replyMsg.msgId, replyMsg.senderUin!, replyMsg.senderUin!) :
|
||||
undefined;
|
||||
},
|
||||
// then the qq is a group member
|
||||
// Mlikiowa V2.0.0 Refactor Todo
|
||||
const uid = await coreContext.getApiContext().UserApi.getUidByUin(atQQ);
|
||||
if (!uid) throw new Error('Get Uid Error');
|
||||
return SendMsgElementConstructor.at(coreContext, atQQ, uid, AtType.atUser, "");
|
||||
},
|
||||
[OB11MessageDataType.reply]: async (coreContext, { data: { id } }) => {
|
||||
const replyMsgM = MessageUnique.getMsgIdAndPeerByShortId(parseInt(id));
|
||||
if (!replyMsgM) {
|
||||
coreContext.context.logger.logWarn('回复消息不存在', id);
|
||||
return undefined;
|
||||
}
|
||||
const NTQQMsgApi = coreContext.getApiContext().MsgApi;
|
||||
const replyMsg = (await NTQQMsgApi.getMsgsByMsgId(
|
||||
replyMsgM.Peer, [replyMsgM.MsgId!])).msgList[0];
|
||||
return replyMsg ?
|
||||
SendMsgElementConstructor.reply(coreContext, replyMsg.msgSeq, replyMsg.msgId, replyMsg.senderUin!, replyMsg.senderUin!) :
|
||||
undefined;
|
||||
},
|
||||
|
||||
[OB11MessageDataType.face]: async (coreContext, { data: { id } }) => SendMsgElementConstructor.face(coreContext, parseInt(id)),
|
||||
[OB11MessageDataType.face]: async (coreContext, { data: { id } }) => SendMsgElementConstructor.face(coreContext, parseInt(id)),
|
||||
|
||||
[OB11MessageDataType.mface]: async (coreContext, {
|
||||
data: {
|
||||
emoji_package_id, emoji_id, key, summary
|
||||
}
|
||||
}) => SendMsgElementConstructor.mface(coreContext, emoji_package_id, emoji_id, key, summary),
|
||||
[OB11MessageDataType.mface]: async (coreContext, {
|
||||
data: {
|
||||
emoji_package_id, emoji_id, key, summary
|
||||
}
|
||||
}) => SendMsgElementConstructor.mface(coreContext, emoji_package_id, emoji_id, key, summary),
|
||||
|
||||
// File service
|
||||
[OB11MessageDataType.image]: async (coreContext, sendMsg, context) => {
|
||||
const PicEle = await SendMsgElementConstructor.pic(
|
||||
coreContext,
|
||||
(await handleOb11FileLikeMessage(coreContext, sendMsg, context)).path,
|
||||
sendMsg.data.summary || '',
|
||||
sendMsg.data.subType || 0
|
||||
);
|
||||
context.deleteAfterSentFiles.push(PicEle.picElement.sourcePath);
|
||||
return PicEle;
|
||||
}, // currently not supported
|
||||
[OB11MessageDataType.file]: async (coreContext, sendMsg, context) => {
|
||||
const { path, fileName } = await handleOb11FileLikeMessage(coreContext, sendMsg, context);
|
||||
//logDebug('发送文件', path, fileName);
|
||||
const FileEle = await SendMsgElementConstructor.file(coreContext, path, fileName);
|
||||
// 清除Upload的应该
|
||||
// context.deleteAfterSentFiles.push(fileName || FileEle.fileElement.filePath);
|
||||
return FileEle;
|
||||
},
|
||||
// File service
|
||||
[OB11MessageDataType.image]: async (coreContext, sendMsg, context) => {
|
||||
const PicEle = await SendMsgElementConstructor.pic(
|
||||
coreContext,
|
||||
(await handleOb11FileLikeMessage(coreContext, sendMsg, context)).path,
|
||||
sendMsg.data.summary || '',
|
||||
sendMsg.data.subType || 0
|
||||
);
|
||||
context.deleteAfterSentFiles.push(PicEle.picElement.sourcePath);
|
||||
return PicEle;
|
||||
}, // currently not supported
|
||||
[OB11MessageDataType.file]: async (coreContext, sendMsg, context) => {
|
||||
const { path, fileName } = await handleOb11FileLikeMessage(coreContext, sendMsg, context);
|
||||
//logDebug('发送文件', path, fileName);
|
||||
const FileEle = await SendMsgElementConstructor.file(coreContext, path, fileName);
|
||||
// 清除Upload的应该
|
||||
// context.deleteAfterSentFiles.push(fileName || FileEle.fileElement.filePath);
|
||||
return FileEle;
|
||||
},
|
||||
|
||||
[OB11MessageDataType.video]: async (coreContext, sendMsg, context) => {
|
||||
const { path, fileName } = await handleOb11FileLikeMessage(coreContext, sendMsg, context);
|
||||
[OB11MessageDataType.video]: async (coreContext, sendMsg, context) => {
|
||||
const { path, fileName } = await handleOb11FileLikeMessage(coreContext, sendMsg, context);
|
||||
|
||||
//logDebug('发送视频', path, fileName);
|
||||
let thumb = sendMsg.data.thumb;
|
||||
if (thumb) {
|
||||
const uri2LocalRes = await uri2local(coreContext.NapCatTempPath, thumb);
|
||||
if (uri2LocalRes.success) thumb = uri2LocalRes.path;
|
||||
}
|
||||
const videoEle = await SendMsgElementConstructor.video(coreContext, path, fileName, thumb);
|
||||
//未测试
|
||||
context.deleteAfterSentFiles.push(videoEle.videoElement.filePath);
|
||||
return videoEle;
|
||||
},
|
||||
//logDebug('发送视频', path, fileName);
|
||||
let thumb = sendMsg.data.thumb;
|
||||
if (thumb) {
|
||||
const uri2LocalRes = await uri2local(coreContext.NapCatTempPath, thumb);
|
||||
if (uri2LocalRes.success) thumb = uri2LocalRes.path;
|
||||
}
|
||||
const videoEle = await SendMsgElementConstructor.video(coreContext, path, fileName, thumb);
|
||||
//未测试
|
||||
context.deleteAfterSentFiles.push(videoEle.videoElement.filePath);
|
||||
return videoEle;
|
||||
},
|
||||
|
||||
[OB11MessageDataType.voice]: async (coreContext, sendMsg, context) => SendMsgElementConstructor.ptt(coreContext, (await handleOb11FileLikeMessage(coreContext, sendMsg, context)).path),
|
||||
[OB11MessageDataType.voice]: async (coreContext, sendMsg, context) => SendMsgElementConstructor.ptt(coreContext, (await handleOb11FileLikeMessage(coreContext, sendMsg, context)).path),
|
||||
|
||||
[OB11MessageDataType.json]: async (coreContext, { data: { data } }) => SendMsgElementConstructor.ark(coreContext, data),
|
||||
[OB11MessageDataType.json]: async (coreContext, { data: { data } }) => SendMsgElementConstructor.ark(coreContext, data),
|
||||
|
||||
[OB11MessageDataType.dice]: async (coreContext, { data: { result } }) => SendMsgElementConstructor.dice(coreContext, result),
|
||||
[OB11MessageDataType.dice]: async (coreContext, { data: { result } }) => SendMsgElementConstructor.dice(coreContext, result),
|
||||
|
||||
[OB11MessageDataType.RPS]: async (coreContext, { data: { result } }) => SendMsgElementConstructor.rps(coreContext, result),
|
||||
[OB11MessageDataType.RPS]: async (coreContext, { data: { result } }) => SendMsgElementConstructor.rps(coreContext, result),
|
||||
|
||||
[OB11MessageDataType.markdown]: async (coreContext, { data: { content } }) => SendMsgElementConstructor.markdown(coreContext, content),
|
||||
[OB11MessageDataType.markdown]: async (coreContext, { data: { content } }) => SendMsgElementConstructor.markdown(coreContext, content),
|
||||
|
||||
[OB11MessageDataType.music]: async (coreContext, { data }) => {
|
||||
[OB11MessageDataType.music]: async (coreContext, { data }) => {
|
||||
// 保留, 直到...找到更好的解决方案
|
||||
if (data.type === 'custom') {
|
||||
if (!data.url) {
|
||||
coreContext.context.logger.logError('自定义音卡缺少参数url');
|
||||
return undefined;
|
||||
}
|
||||
if (!data.audio) {
|
||||
coreContext.context.logger.logError('自定义音卡缺少参数audio');
|
||||
return undefined;
|
||||
}
|
||||
if (!data.title) {
|
||||
coreContext.context.logger.logError('自定义音卡缺少参数title');
|
||||
return undefined;
|
||||
}
|
||||
} else {
|
||||
if (!['qq', '163'].includes(data.type)) {
|
||||
coreContext.context.logger.logError('音乐卡片type错误, 只支持qq、163、custom,当前type:', data.type);
|
||||
return undefined;
|
||||
}
|
||||
if (!data.id) {
|
||||
coreContext.context.logger.logError('音乐卡片缺少参数id');
|
||||
return undefined;
|
||||
}
|
||||
if (data.type === 'custom') {
|
||||
if (!data.url) {
|
||||
coreContext.context.logger.logError('自定义音卡缺少参数url');
|
||||
return undefined;
|
||||
}
|
||||
if (!data.audio) {
|
||||
coreContext.context.logger.logError('自定义音卡缺少参数audio');
|
||||
return undefined;
|
||||
}
|
||||
if (!data.title) {
|
||||
coreContext.context.logger.logError('自定义音卡缺少参数title');
|
||||
return undefined;
|
||||
}
|
||||
} else {
|
||||
if (!['qq', '163'].includes(data.type)) {
|
||||
coreContext.context.logger.logError('音乐卡片type错误, 只支持qq、163、custom,当前type:', data.type);
|
||||
return undefined;
|
||||
}
|
||||
if (!data.id) {
|
||||
coreContext.context.logger.logError('音乐卡片缺少参数id');
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
let postData: IdMusicSignPostData | CustomMusicSignPostData;
|
||||
if (data.type === 'custom' && data.content) {
|
||||
const { content, ...others } = data;
|
||||
postData = { singer: content, ...others };
|
||||
} else {
|
||||
postData = data;
|
||||
}
|
||||
// Mlikiowa V2.0.0 Refactor Todo
|
||||
const signUrl = "";
|
||||
if (!signUrl) {
|
||||
if (data.type === 'qq') {
|
||||
//const musicJson = (await SignMusicWrapper(data.id.toString())).data.arkResult.slice(0, -1);
|
||||
//return SendMsgElementConstructor.ark(musicJson);
|
||||
}
|
||||
throw Error('音乐消息签名地址未配置');
|
||||
}
|
||||
try {
|
||||
const musicJson = await RequestUtil.HttpGetJson<any>(signUrl, 'POST', postData);
|
||||
return SendMsgElementConstructor.ark(coreContext, musicJson);
|
||||
} catch (e) {
|
||||
coreContext.context.logger.logError('生成音乐消息失败', e);
|
||||
}
|
||||
},
|
||||
|
||||
[OB11MessageDataType.node]: async (coreContext) => undefined,
|
||||
|
||||
[OB11MessageDataType.forward]: async (coreContext) => undefined,
|
||||
|
||||
[OB11MessageDataType.xml]: async (coreContext) => undefined,
|
||||
|
||||
[OB11MessageDataType.poke]: async (coreContext) => undefined,
|
||||
|
||||
[OB11MessageDataType.Location]: async (coreContext) => {
|
||||
return SendMsgElementConstructor.location(coreContext);
|
||||
},
|
||||
[OB11MessageDataType.miniapp]: function (CoreContext: NapCatCore, sendMsg: never, context: MessageContext): Promise<SendMessageElement | undefined> {
|
||||
throw new Error('Function not implemented.');
|
||||
}
|
||||
|
||||
let postData: IdMusicSignPostData | CustomMusicSignPostData;
|
||||
if (data.type === 'custom' && data.content) {
|
||||
const { content, ...others } = data;
|
||||
postData = { singer: content, ...others };
|
||||
} else {
|
||||
postData = data;
|
||||
}
|
||||
// Mlikiowa V2.0.0 Refactor Todo
|
||||
const signUrl = "";
|
||||
if (!signUrl) {
|
||||
if (data.type === 'qq') {
|
||||
//const musicJson = (await SignMusicWrapper(data.id.toString())).data.arkResult.slice(0, -1);
|
||||
//return SendMsgElementConstructor.ark(musicJson);
|
||||
}
|
||||
throw Error('音乐消息签名地址未配置');
|
||||
}
|
||||
try {
|
||||
const musicJson = await RequestUtil.HttpGetJson<any>(signUrl, 'POST', postData);
|
||||
return SendMsgElementConstructor.ark(coreContext, musicJson);
|
||||
} catch (e) {
|
||||
coreContext.context.logger.logError('生成音乐消息失败', e);
|
||||
}
|
||||
},
|
||||
|
||||
[OB11MessageDataType.node]: async (coreContext) => undefined,
|
||||
|
||||
[OB11MessageDataType.forward]: async (coreContext) => undefined,
|
||||
|
||||
[OB11MessageDataType.xml]: async (coreContext) => undefined,
|
||||
|
||||
[OB11MessageDataType.poke]: async (coreContext) => undefined,
|
||||
|
||||
[OB11MessageDataType.Location]: async (coreContext) => {
|
||||
return SendMsgElementConstructor.location(coreContext);
|
||||
},
|
||||
[OB11MessageDataType.miniapp]: function (CoreContext: NapCatCore, sendMsg: never, context: MessageContext): Promise<SendMessageElement | undefined> {
|
||||
throw new Error('Function not implemented.');
|
||||
}
|
||||
};
|
||||
|
||||
const handlers = <{
|
||||
@@ -192,46 +193,46 @@ const handlers = <{
|
||||
}>_handlers;
|
||||
|
||||
export default async function createSendElements(
|
||||
CoreContext: NapCatCore,
|
||||
messageData: OB11MessageData[],
|
||||
peer: Peer,
|
||||
ignoreTypes: OB11MessageDataType[] = []
|
||||
CoreContext: NapCatCore,
|
||||
messageData: OB11MessageData[],
|
||||
peer: Peer,
|
||||
ignoreTypes: OB11MessageDataType[] = []
|
||||
) {
|
||||
const deleteAfterSentFiles: string[] = [];
|
||||
const callResultList: Array<Promise<SendMessageElement | undefined>> = [];
|
||||
for (const sendMsg of messageData) {
|
||||
if (ignoreTypes.includes(sendMsg.type)) {
|
||||
continue;
|
||||
const deleteAfterSentFiles: string[] = [];
|
||||
const callResultList: Array<Promise<SendMessageElement | undefined>> = [];
|
||||
for (const sendMsg of messageData) {
|
||||
if (ignoreTypes.includes(sendMsg.type)) {
|
||||
continue;
|
||||
}
|
||||
const callResult = handlers[sendMsg.type](
|
||||
CoreContext,
|
||||
sendMsg,
|
||||
{ peer, deleteAfterSentFiles }
|
||||
)?.catch(undefined);
|
||||
callResultList.push(callResult);
|
||||
}
|
||||
const callResult = handlers[sendMsg.type](
|
||||
CoreContext,
|
||||
sendMsg,
|
||||
{ peer, deleteAfterSentFiles }
|
||||
)?.catch(undefined);
|
||||
callResultList.push(callResult);
|
||||
}
|
||||
const ret = await Promise.all(callResultList);
|
||||
const sendElements: SendMessageElement[] = ret.filter(ele => ele) as SendMessageElement[];
|
||||
return { sendElements, deleteAfterSentFiles };
|
||||
const ret = await Promise.all(callResultList);
|
||||
const sendElements: SendMessageElement[] = ret.filter(ele => ele) as SendMessageElement[];
|
||||
return { sendElements, deleteAfterSentFiles };
|
||||
}
|
||||
|
||||
export async function createSendElementsParallel(
|
||||
CoreContext: NapCatCore,
|
||||
messageData: OB11MessageData[],
|
||||
peer: Peer,
|
||||
ignoreTypes: OB11MessageDataType[] = []
|
||||
CoreContext: NapCatCore,
|
||||
messageData: OB11MessageData[],
|
||||
peer: Peer,
|
||||
ignoreTypes: OB11MessageDataType[] = []
|
||||
) {
|
||||
const deleteAfterSentFiles: string[] = [];
|
||||
const sendElements = <SendMessageElement[]>(
|
||||
const deleteAfterSentFiles: string[] = [];
|
||||
const sendElements = <SendMessageElement[]>(
|
||||
await Promise.all(
|
||||
messageData.map(async sendMsg => ignoreTypes.includes(sendMsg.type) ?
|
||||
undefined :
|
||||
handlers[sendMsg.type](CoreContext, sendMsg, { peer, deleteAfterSentFiles }))
|
||||
messageData.map(async sendMsg => ignoreTypes.includes(sendMsg.type) ?
|
||||
undefined :
|
||||
handlers[sendMsg.type](CoreContext, sendMsg, { peer, deleteAfterSentFiles }))
|
||||
).then(
|
||||
results => results.filter(
|
||||
element => element !== undefined
|
||||
)
|
||||
results => results.filter(
|
||||
element => element !== undefined
|
||||
)
|
||||
)
|
||||
);
|
||||
return { sendElements, deleteAfterSentFiles };
|
||||
return { sendElements, deleteAfterSentFiles };
|
||||
}
|
||||
@@ -2,118 +2,118 @@ import { ChatType, ElementType, NapCatCore, Peer, RawMessage, SendMessageElement
|
||||
import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||
import { OB11MessageDataType, OB11MessageNode } from '@/onebot/types';
|
||||
import createSendElements from './create-send-elements';
|
||||
import { normalize, sendMsg } from "../SendMsg/index"
|
||||
import { normalize, sendMsg } from "../SendMsg/index";
|
||||
async function cloneMsg(coreContext: NapCatCore, msg: RawMessage): Promise<RawMessage | undefined> {
|
||||
const selfPeer = {
|
||||
chatType: ChatType.friend,
|
||||
peerUid: coreContext.selfInfo.uid
|
||||
};
|
||||
const logger = coreContext.context.logger;
|
||||
const NTQQMsgApi = coreContext.getApiContext().MsgApi;
|
||||
//logDebug('克隆的目标消息', msg);
|
||||
const selfPeer = {
|
||||
chatType: ChatType.friend,
|
||||
peerUid: coreContext.selfInfo.uid
|
||||
};
|
||||
const logger = coreContext.context.logger;
|
||||
const NTQQMsgApi = coreContext.getApiContext().MsgApi;
|
||||
//logDebug('克隆的目标消息', msg);
|
||||
|
||||
const sendElements: SendMessageElement[] = [];
|
||||
const sendElements: SendMessageElement[] = [];
|
||||
|
||||
for (const element of msg.elements) {
|
||||
sendElements.push(element as SendMessageElement);
|
||||
}
|
||||
for (const element of msg.elements) {
|
||||
sendElements.push(element as SendMessageElement);
|
||||
}
|
||||
|
||||
if (sendElements.length === 0) {
|
||||
logger.logDebug('需要clone的消息无法解析,将会忽略掉', msg);
|
||||
}
|
||||
try {
|
||||
const nodeMsg = await NTQQMsgApi.sendMsg(selfPeer, sendElements, true);
|
||||
return nodeMsg;
|
||||
} catch (e) {
|
||||
logger.logError(e, '克隆转发消息失败,将忽略本条消息', msg);
|
||||
}
|
||||
if (sendElements.length === 0) {
|
||||
logger.logDebug('需要clone的消息无法解析,将会忽略掉', msg);
|
||||
}
|
||||
try {
|
||||
const nodeMsg = await NTQQMsgApi.sendMsg(selfPeer, sendElements, true);
|
||||
return nodeMsg;
|
||||
} catch (e) {
|
||||
logger.logError(e, '克隆转发消息失败,将忽略本条消息', msg);
|
||||
}
|
||||
}
|
||||
|
||||
export async function handleForwardNode(coreContext: NapCatCore, destPeer: Peer, messageNodes: OB11MessageNode[]): Promise<RawMessage | null> {
|
||||
const NTQQMsgApi = coreContext.getApiContext().MsgApi;
|
||||
const selfPeer = {
|
||||
chatType: ChatType.friend,
|
||||
peerUid: coreContext.selfInfo.uid
|
||||
};
|
||||
let nodeMsgIds: string[] = [];
|
||||
const logger = coreContext.context.logger;
|
||||
for (const messageNode of messageNodes) {
|
||||
const nodeId = messageNode.data.id;
|
||||
if (nodeId) {
|
||||
//对Mgsid和OB11ID混用情况兜底
|
||||
const nodeMsg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(nodeId)) || MessageUnique.getPeerByMsgId(nodeId);
|
||||
if (!nodeMsg) {
|
||||
logger.logError('转发消息失败,未找到消息', nodeId);
|
||||
continue;
|
||||
}
|
||||
nodeMsgIds.push(nodeMsg.MsgId);
|
||||
const NTQQMsgApi = coreContext.getApiContext().MsgApi;
|
||||
const selfPeer = {
|
||||
chatType: ChatType.friend,
|
||||
peerUid: coreContext.selfInfo.uid
|
||||
};
|
||||
let nodeMsgIds: string[] = [];
|
||||
const logger = coreContext.context.logger;
|
||||
for (const messageNode of messageNodes) {
|
||||
const nodeId = messageNode.data.id;
|
||||
if (nodeId) {
|
||||
//对Mgsid和OB11ID混用情况兜底
|
||||
const nodeMsg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(nodeId)) || MessageUnique.getPeerByMsgId(nodeId);
|
||||
if (!nodeMsg) {
|
||||
logger.logError('转发消息失败,未找到消息', nodeId);
|
||||
continue;
|
||||
}
|
||||
nodeMsgIds.push(nodeMsg.MsgId);
|
||||
} else {
|
||||
// 自定义的消息
|
||||
try {
|
||||
const OB11Data = normalize(messageNode.data.content);
|
||||
//筛选node消息
|
||||
const isNodeMsg = OB11Data.filter(e => e.type === OB11MessageDataType.node).length;//找到子转发消息
|
||||
if (isNodeMsg !== 0) {
|
||||
if (isNodeMsg !== OB11Data.length) { logger.logError('子消息中包含非node消息 跳过不合法部分'); continue; }
|
||||
const nodeMsg = await handleForwardNode(coreContext, selfPeer, OB11Data.filter(e => e.type === OB11MessageDataType.node));
|
||||
if (nodeMsg) { nodeMsgIds.push(nodeMsg.msgId); MessageUnique.createMsg(selfPeer, nodeMsg.msgId); }
|
||||
//完成子卡片生成跳过后续
|
||||
continue;
|
||||
}
|
||||
const { sendElements } = await createSendElements(coreContext,OB11Data, destPeer);
|
||||
//拆分消息
|
||||
const MixElement = sendElements.filter(element => element.elementType !== ElementType.FILE && element.elementType !== ElementType.VIDEO);
|
||||
const SingleElement = sendElements.filter(element => element.elementType === ElementType.FILE || element.elementType === ElementType.VIDEO).map(e => [e]);
|
||||
const AllElement: SendMessageElement[][] = [MixElement, ...SingleElement].filter(e => e !== undefined && e.length !== 0);
|
||||
const MsgNodeList: Promise<RawMessage | undefined>[] = [];
|
||||
for (const sendElementsSplitElement of AllElement) {
|
||||
MsgNodeList.push(sendMsg(coreContext,selfPeer, sendElementsSplitElement, [], true).catch(e => new Promise((resolve, reject) => { resolve(undefined); })));
|
||||
}
|
||||
(await Promise.allSettled(MsgNodeList)).map((result) => {
|
||||
if (result.status === 'fulfilled' && result.value) {
|
||||
nodeMsgIds.push(result.value.msgId);
|
||||
MessageUnique.createMsg(selfPeer, result.value.msgId);
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
logger.logDebug('生成转发消息节点失败', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
const nodeMsgArray: Array<RawMessage> = [];
|
||||
let srcPeer: Peer | undefined = undefined;
|
||||
let needSendSelf = false;
|
||||
//检测是否处于同一个Peer 不在同一个peer则全部消息由自身发送
|
||||
for (const msgId of nodeMsgIds) {
|
||||
const nodeMsgPeer = MessageUnique.getPeerByMsgId(msgId);
|
||||
if (!nodeMsgPeer) {
|
||||
logger.logError('转发消息失败,未找到消息', msgId);
|
||||
continue;
|
||||
}
|
||||
const nodeMsg = (await NTQQMsgApi.getMsgsByMsgId(nodeMsgPeer.Peer, [msgId])).msgList[0];
|
||||
srcPeer = srcPeer ?? { chatType: nodeMsg.chatType, peerUid: nodeMsg.peerUid };
|
||||
if (srcPeer.peerUid !== nodeMsg.peerUid) {
|
||||
needSendSelf = true;
|
||||
}
|
||||
nodeMsgArray.push(nodeMsg);
|
||||
}
|
||||
nodeMsgIds = nodeMsgArray.map(msg => msg.msgId);
|
||||
let retMsgIds: string[] = [];
|
||||
if (needSendSelf) {
|
||||
for (const [index, msg] of nodeMsgArray.entries()) {
|
||||
if (msg.peerUid === coreContext.selfInfo.uid) continue;
|
||||
const ClonedMsg = await cloneMsg(coreContext, msg);
|
||||
if (ClonedMsg) retMsgIds.push(ClonedMsg.msgId);
|
||||
}
|
||||
} else {
|
||||
// 自定义的消息
|
||||
try {
|
||||
let OB11Data = normalize(messageNode.data.content);
|
||||
//筛选node消息
|
||||
let isNodeMsg = OB11Data.filter(e => e.type === OB11MessageDataType.node).length;//找到子转发消息
|
||||
if (isNodeMsg !== 0) {
|
||||
if (isNodeMsg !== OB11Data.length) { logger.logError('子消息中包含非node消息 跳过不合法部分'); continue; }
|
||||
const nodeMsg = await handleForwardNode(coreContext, selfPeer, OB11Data.filter(e => e.type === OB11MessageDataType.node));
|
||||
if (nodeMsg) { nodeMsgIds.push(nodeMsg.msgId); MessageUnique.createMsg(selfPeer, nodeMsg.msgId) };
|
||||
//完成子卡片生成跳过后续
|
||||
continue;
|
||||
}
|
||||
const { sendElements } = await createSendElements(coreContext,OB11Data, destPeer);
|
||||
//拆分消息
|
||||
let MixElement = sendElements.filter(element => element.elementType !== ElementType.FILE && element.elementType !== ElementType.VIDEO);
|
||||
let SingleElement = sendElements.filter(element => element.elementType === ElementType.FILE || element.elementType === ElementType.VIDEO).map(e => [e]);
|
||||
let AllElement: SendMessageElement[][] = [MixElement, ...SingleElement].filter(e => e !== undefined && e.length !== 0);
|
||||
const MsgNodeList: Promise<RawMessage | undefined>[] = [];
|
||||
for (const sendElementsSplitElement of AllElement) {
|
||||
MsgNodeList.push(sendMsg(coreContext,selfPeer, sendElementsSplitElement, [], true).catch(e => new Promise((resolve, reject) => { resolve(undefined) })));
|
||||
}
|
||||
(await Promise.allSettled(MsgNodeList)).map((result) => {
|
||||
if (result.status === 'fulfilled' && result.value) {
|
||||
nodeMsgIds.push(result.value.msgId);
|
||||
MessageUnique.createMsg(selfPeer, result.value.msgId);
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
logger.logDebug('生成转发消息节点失败', e);
|
||||
}
|
||||
retMsgIds = nodeMsgIds;
|
||||
}
|
||||
}
|
||||
const nodeMsgArray: Array<RawMessage> = [];
|
||||
let srcPeer: Peer | undefined = undefined;
|
||||
let needSendSelf = false;
|
||||
//检测是否处于同一个Peer 不在同一个peer则全部消息由自身发送
|
||||
for (let msgId of nodeMsgIds) {
|
||||
const nodeMsgPeer = MessageUnique.getPeerByMsgId(msgId);
|
||||
if (!nodeMsgPeer) {
|
||||
logger.logError('转发消息失败,未找到消息', msgId);
|
||||
continue;
|
||||
if (nodeMsgIds.length === 0) throw Error('转发消息失败,生成节点为空');
|
||||
try {
|
||||
logger.logDebug('开发转发', srcPeer, destPeer, nodeMsgIds);
|
||||
return await NTQQMsgApi.multiForwardMsg(srcPeer!, destPeer, nodeMsgIds);
|
||||
} catch (e) {
|
||||
logger.logError('forward failed', e);
|
||||
return null;
|
||||
}
|
||||
const nodeMsg = (await NTQQMsgApi.getMsgsByMsgId(nodeMsgPeer.Peer, [msgId])).msgList[0];
|
||||
srcPeer = srcPeer ?? { chatType: nodeMsg.chatType, peerUid: nodeMsg.peerUid };
|
||||
if (srcPeer.peerUid !== nodeMsg.peerUid) {
|
||||
needSendSelf = true;
|
||||
}
|
||||
nodeMsgArray.push(nodeMsg);
|
||||
}
|
||||
nodeMsgIds = nodeMsgArray.map(msg => msg.msgId);
|
||||
let retMsgIds: string[] = [];
|
||||
if (needSendSelf) {
|
||||
for (const [index, msg] of nodeMsgArray.entries()) {
|
||||
if (msg.peerUid === coreContext.selfInfo.uid) continue;
|
||||
const ClonedMsg = await cloneMsg(coreContext, msg);
|
||||
if (ClonedMsg) retMsgIds.push(ClonedMsg.msgId);
|
||||
}
|
||||
} else {
|
||||
retMsgIds = nodeMsgIds;
|
||||
}
|
||||
if (nodeMsgIds.length === 0) throw Error('转发消息失败,生成节点为空');
|
||||
try {
|
||||
logger.logDebug('开发转发', srcPeer, destPeer, nodeMsgIds);
|
||||
return await NTQQMsgApi.multiForwardMsg(srcPeer!, destPeer, nodeMsgIds);
|
||||
} catch (e) {
|
||||
logger.logError('forward failed', e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
|
||||
import {
|
||||
OB11MessageData,
|
||||
OB11MessageDataType,
|
||||
OB11MessageMixType,
|
||||
OB11MessageNode,
|
||||
OB11PostSendMsg
|
||||
OB11MessageData,
|
||||
OB11MessageDataType,
|
||||
OB11MessageMixType,
|
||||
OB11MessageNode,
|
||||
OB11PostSendMsg
|
||||
} from '@/onebot/types';
|
||||
import { ActionName, BaseCheckResult } from '@/onebot/action/types';
|
||||
import fs from 'node:fs';
|
||||
@@ -26,147 +26,147 @@ export enum ContextMode {
|
||||
}
|
||||
// Normalizes a mixed type (CQCode/a single segment/segment array) into a segment array.
|
||||
export function normalize(message: OB11MessageMixType, autoEscape = false): OB11MessageData[] {
|
||||
return typeof message === 'string' ? (
|
||||
autoEscape ?
|
||||
[{ type: OB11MessageDataType.text, data: { text: message } }] :
|
||||
decodeCQCode(message)
|
||||
) : Array.isArray(message) ? message : [message];
|
||||
return typeof message === 'string' ? (
|
||||
autoEscape ?
|
||||
[{ type: OB11MessageDataType.text, data: { text: message } }] :
|
||||
decodeCQCode(message)
|
||||
) : Array.isArray(message) ? message : [message];
|
||||
}
|
||||
|
||||
export { createSendElements };
|
||||
|
||||
export async function sendMsg(coreContext: NapCatCore, peer: Peer, sendElements: SendMessageElement[], deleteAfterSentFiles: string[], waitComplete = true) {
|
||||
const NTQQMsgApi = coreContext.getApiContext().MsgApi;
|
||||
const logger = coreContext.context.logger;
|
||||
if (!sendElements.length) {
|
||||
throw ('消息体无法解析, 请检查是否发送了不支持的消息类型');
|
||||
}
|
||||
let totalSize = 0;
|
||||
let timeout = 10000;
|
||||
try {
|
||||
for (const fileElement of sendElements) {
|
||||
if (fileElement.elementType === ElementType.PTT) {
|
||||
totalSize += fs.statSync(fileElement.pttElement.filePath).size;
|
||||
}
|
||||
if (fileElement.elementType === ElementType.FILE) {
|
||||
totalSize += fs.statSync(fileElement.fileElement.filePath).size;
|
||||
}
|
||||
if (fileElement.elementType === ElementType.VIDEO) {
|
||||
totalSize += fs.statSync(fileElement.videoElement.filePath).size;
|
||||
}
|
||||
if (fileElement.elementType === ElementType.PIC) {
|
||||
totalSize += fs.statSync(fileElement.picElement.sourcePath).size;
|
||||
}
|
||||
const NTQQMsgApi = coreContext.getApiContext().MsgApi;
|
||||
const logger = coreContext.context.logger;
|
||||
if (!sendElements.length) {
|
||||
throw ('消息体无法解析, 请检查是否发送了不支持的消息类型');
|
||||
}
|
||||
//且 PredictTime ((totalSize / 1024 / 512) * 1000)不等于Nan
|
||||
const PredictTime = totalSize / 1024 / 256 * 1000;
|
||||
if (!Number.isNaN(PredictTime)) {
|
||||
timeout += PredictTime;// 10S Basic Timeout + PredictTime( For File 512kb/s )
|
||||
let totalSize = 0;
|
||||
let timeout = 10000;
|
||||
try {
|
||||
for (const fileElement of sendElements) {
|
||||
if (fileElement.elementType === ElementType.PTT) {
|
||||
totalSize += fs.statSync(fileElement.pttElement.filePath).size;
|
||||
}
|
||||
if (fileElement.elementType === ElementType.FILE) {
|
||||
totalSize += fs.statSync(fileElement.fileElement.filePath).size;
|
||||
}
|
||||
if (fileElement.elementType === ElementType.VIDEO) {
|
||||
totalSize += fs.statSync(fileElement.videoElement.filePath).size;
|
||||
}
|
||||
if (fileElement.elementType === ElementType.PIC) {
|
||||
totalSize += fs.statSync(fileElement.picElement.sourcePath).size;
|
||||
}
|
||||
}
|
||||
//且 PredictTime ((totalSize / 1024 / 512) * 1000)不等于Nan
|
||||
const PredictTime = totalSize / 1024 / 256 * 1000;
|
||||
if (!Number.isNaN(PredictTime)) {
|
||||
timeout += PredictTime;// 10S Basic Timeout + PredictTime( For File 512kb/s )
|
||||
}
|
||||
} catch (e) {
|
||||
logger.logError('发送消息计算预计时间异常', e);
|
||||
}
|
||||
} catch (e) {
|
||||
logger.logError('发送消息计算预计时间异常', e);
|
||||
}
|
||||
const returnMsg = await NTQQMsgApi.sendMsg(peer, sendElements, waitComplete, timeout);
|
||||
try {
|
||||
const returnMsg = await NTQQMsgApi.sendMsg(peer, sendElements, waitComplete, timeout);
|
||||
try {
|
||||
returnMsg!.id = MessageUnique.createMsg({ chatType: peer.chatType, guildId: '', peerUid: peer.peerUid }, returnMsg!.msgId);
|
||||
} catch (e: any) {
|
||||
logger.logDebug('发送消息id获取失败', e);
|
||||
} catch (e: any) {
|
||||
logger.logDebug('发送消息id获取失败', e);
|
||||
returnMsg!.id = 0;
|
||||
}
|
||||
deleteAfterSentFiles.map((f) => { fsPromise.unlink(f).then().catch(e => logger.logError('发送消息删除文件失败', e)); });
|
||||
return returnMsg;
|
||||
}
|
||||
deleteAfterSentFiles.map((f) => { fsPromise.unlink(f).then().catch(e => logger.logError('发送消息删除文件失败', e)); });
|
||||
return returnMsg;
|
||||
}
|
||||
|
||||
async function createContext(coreContext: NapCatCore, payload: OB11PostSendMsg, contextMode: ContextMode): Promise<Peer> {
|
||||
// This function determines the type of message by the existence of user_id / group_id,
|
||||
// not message_type.
|
||||
// This redundant design of Ob11 here should be blamed.
|
||||
const NTQQGroupApi = coreContext.getApiContext().GroupApi;
|
||||
const NTQQFriendApi = coreContext.getApiContext().FriendApi;
|
||||
const NTQQUserApi = coreContext.getApiContext().UserApi;
|
||||
if ((contextMode === ContextMode.Group || contextMode === ContextMode.Normal) && payload.group_id) {
|
||||
const group = (await NTQQGroupApi.getGroups()).find(e => e.groupCode == payload.group_id?.toString())
|
||||
return {
|
||||
chatType: ChatType.group,
|
||||
peerUid: payload.group_id.toString()
|
||||
};
|
||||
}
|
||||
if ((contextMode === ContextMode.Private || contextMode === ContextMode.Normal) && payload.user_id) {
|
||||
const Uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
|
||||
const isBuddy = await NTQQFriendApi.isBuddy(Uid!);
|
||||
//console.log("[调试代码] UIN:", payload.user_id, " UID:", Uid, " IsBuddy:", isBuddy);
|
||||
return {
|
||||
chatType: isBuddy ? ChatType.friend : ChatType.temp,
|
||||
peerUid: Uid!
|
||||
};
|
||||
}
|
||||
throw '请指定 group_id 或 user_id';
|
||||
// This function determines the type of message by the existence of user_id / group_id,
|
||||
// not message_type.
|
||||
// This redundant design of Ob11 here should be blamed.
|
||||
const NTQQGroupApi = coreContext.getApiContext().GroupApi;
|
||||
const NTQQFriendApi = coreContext.getApiContext().FriendApi;
|
||||
const NTQQUserApi = coreContext.getApiContext().UserApi;
|
||||
if ((contextMode === ContextMode.Group || contextMode === ContextMode.Normal) && payload.group_id) {
|
||||
const group = (await NTQQGroupApi.getGroups()).find(e => e.groupCode == payload.group_id?.toString());
|
||||
return {
|
||||
chatType: ChatType.group,
|
||||
peerUid: payload.group_id.toString()
|
||||
};
|
||||
}
|
||||
if ((contextMode === ContextMode.Private || contextMode === ContextMode.Normal) && payload.user_id) {
|
||||
const Uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
|
||||
const isBuddy = await NTQQFriendApi.isBuddy(Uid!);
|
||||
//console.log("[调试代码] UIN:", payload.user_id, " UID:", Uid, " IsBuddy:", isBuddy);
|
||||
return {
|
||||
chatType: isBuddy ? ChatType.friend : ChatType.temp,
|
||||
peerUid: Uid!
|
||||
};
|
||||
}
|
||||
throw '请指定 group_id 或 user_id';
|
||||
}
|
||||
|
||||
function getSpecialMsgNum(payload: OB11PostSendMsg, msgType: OB11MessageDataType): number {
|
||||
if (Array.isArray(payload.message)) {
|
||||
return payload.message.filter(msg => msg.type == msgType).length;
|
||||
}
|
||||
return 0;
|
||||
if (Array.isArray(payload.message)) {
|
||||
return payload.message.filter(msg => msg.type == msgType).length;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||
actionName = ActionName.SendMsg;
|
||||
contextMode = ContextMode.Normal;
|
||||
actionName = ActionName.SendMsg;
|
||||
contextMode = ContextMode.Normal;
|
||||
|
||||
protected async check(payload: OB11PostSendMsg): Promise<BaseCheckResult> {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi;
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const messages = normalize(payload.message);
|
||||
const nodeElementLength = getSpecialMsgNum(payload, OB11MessageDataType.node);
|
||||
if (nodeElementLength > 0 && nodeElementLength != messages.length) {
|
||||
return { valid: false, message: '转发消息不能和普通消息混在一起发送,转发需要保证message只有type为node的元素' };
|
||||
protected async check(payload: OB11PostSendMsg): Promise<BaseCheckResult> {
|
||||
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
|
||||
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi;
|
||||
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
|
||||
const messages = normalize(payload.message);
|
||||
const nodeElementLength = getSpecialMsgNum(payload, OB11MessageDataType.node);
|
||||
if (nodeElementLength > 0 && nodeElementLength != messages.length) {
|
||||
return { valid: false, message: '转发消息不能和普通消息混在一起发送,转发需要保证message只有type为node的元素' };
|
||||
}
|
||||
// if (payload.message_type !== 'private' && payload.group_id && !(await getGroup(payload.group_id))) {
|
||||
// return { valid: false, message: `群${payload.group_id}不存在` };
|
||||
// }
|
||||
if (payload.user_id && payload.message_type !== 'group') {
|
||||
const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
|
||||
const isBuddy = await NTQQFriendApi.isBuddy(uid!);
|
||||
// 此处有问题
|
||||
if (!isBuddy) {
|
||||
//return { valid: false, message: '异常消息' };
|
||||
}
|
||||
}
|
||||
return { valid: true };
|
||||
}
|
||||
// if (payload.message_type !== 'private' && payload.group_id && !(await getGroup(payload.group_id))) {
|
||||
// return { valid: false, message: `群${payload.group_id}不存在` };
|
||||
// }
|
||||
if (payload.user_id && payload.message_type !== 'group') {
|
||||
const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
|
||||
const isBuddy = await NTQQFriendApi.isBuddy(uid!);
|
||||
// 此处有问题
|
||||
if (!isBuddy) {
|
||||
//return { valid: false, message: '异常消息' };
|
||||
}
|
||||
|
||||
protected async _handle(payload: OB11PostSendMsg): Promise<{ message_id: number }> {
|
||||
const peer = await createContext(this.CoreContext, payload, this.contextMode);
|
||||
|
||||
const messages = normalize(
|
||||
payload.message,
|
||||
payload.auto_escape === true || payload.auto_escape === 'true'
|
||||
);
|
||||
|
||||
if (getSpecialMsgNum(payload, OB11MessageDataType.node)) {
|
||||
const returnMsg = await handleForwardNode(this.CoreContext,peer, messages as OB11MessageNode[]);
|
||||
if (returnMsg) {
|
||||
const msgShortId = MessageUnique.createMsg({ guildId: '', peerUid: peer.peerUid, chatType: peer.chatType }, returnMsg!.msgId);
|
||||
return { message_id: msgShortId! };
|
||||
} else {
|
||||
throw Error('发送转发消息失败');
|
||||
}
|
||||
} else {
|
||||
// if (getSpecialMsgNum(payload, OB11MessageDataType.music)) {
|
||||
// const music: OB11MessageCustomMusic = messages[0] as OB11MessageCustomMusic;
|
||||
// if (music) {
|
||||
// }
|
||||
// }
|
||||
}
|
||||
// log("send msg:", peer, sendElements)
|
||||
|
||||
const { sendElements, deleteAfterSentFiles } = await createSendElements(this.CoreContext, messages, peer);
|
||||
//console.log(peer, JSON.stringify(sendElements,null,2));
|
||||
const returnMsg = await sendMsg(this.CoreContext, peer, sendElements, deleteAfterSentFiles);
|
||||
return { message_id: returnMsg!.id! };
|
||||
}
|
||||
return { valid: true };
|
||||
}
|
||||
|
||||
protected async _handle(payload: OB11PostSendMsg): Promise<{ message_id: number }> {
|
||||
const peer = await createContext(this.CoreContext, payload, this.contextMode);
|
||||
|
||||
const messages = normalize(
|
||||
payload.message,
|
||||
payload.auto_escape === true || payload.auto_escape === 'true'
|
||||
);
|
||||
|
||||
if (getSpecialMsgNum(payload, OB11MessageDataType.node)) {
|
||||
const returnMsg = await handleForwardNode(this.CoreContext,peer, messages as OB11MessageNode[]);
|
||||
if (returnMsg) {
|
||||
const msgShortId = MessageUnique.createMsg({ guildId: '', peerUid: peer.peerUid, chatType: peer.chatType }, returnMsg!.msgId);
|
||||
return { message_id: msgShortId! };
|
||||
} else {
|
||||
throw Error('发送转发消息失败');
|
||||
}
|
||||
} else {
|
||||
// if (getSpecialMsgNum(payload, OB11MessageDataType.music)) {
|
||||
// const music: OB11MessageCustomMusic = messages[0] as OB11MessageCustomMusic;
|
||||
// if (music) {
|
||||
// }
|
||||
// }
|
||||
}
|
||||
// log("send msg:", peer, sendElements)
|
||||
|
||||
const { sendElements, deleteAfterSentFiles } = await createSendElements(this.CoreContext, messages, peer);
|
||||
//console.log(peer, JSON.stringify(sendElements,null,2));
|
||||
const returnMsg = await sendMsg(this.CoreContext, peer, sendElements, deleteAfterSentFiles);
|
||||
return { message_id: returnMsg!.id! };
|
||||
}
|
||||
}
|
||||
|
||||
export default SendMsg;
|
||||
Reference in new issue
Block a user