chore: sendMsg

This commit is contained in:
手瓜一十雪 2024-08-09 17:53:06 +08:00
parent 3623b991ff
commit e5fd9c6366

View File

@ -15,7 +15,7 @@ async function handleOb11FileLikeMessage(
{ deleteAfterSentFiles }: MessageContext { deleteAfterSentFiles }: MessageContext
) { ) {
//有的奇怪的框架将url作为参数 而不是file 此时优先url 同时注意可能传入的是非file://开头的目录 By Mlikiowa //有的奇怪的框架将url作为参数 而不是file 此时优先url 同时注意可能传入的是非file://开头的目录 By Mlikiowa
const { path, isLocal, fileName, errMsg, success } = (await uri2local(coreContext.NapCatTempPath,inputdata?.url || inputdata.file)); const { path, isLocal, fileName, errMsg, success } = (await uri2local(coreContext.NapCatTempPath, inputdata?.url || inputdata.file));
if (!success) { if (!success) {
coreContext.context.logger.logError('文件下载失败', errMsg); coreContext.context.logger.logError('文件下载失败', errMsg);
@ -38,7 +38,7 @@ const _handlers: {
context: MessageContext context: MessageContext
) => Promise<SendMessageElement | undefined> ) => Promise<SendMessageElement | undefined>
} = { } = {
[OB11MessageDataType.text]: async (coreContext, { data: { text } }) => SendMsgElementConstructor.text(text), [OB11MessageDataType.text]: async (coreContext, { data: { text } }) => SendMsgElementConstructor.text(coreContext, text),
[OB11MessageDataType.at]: async (coreContext, { data: { qq: atQQ } }, context) => { [OB11MessageDataType.at]: async (coreContext, { data: { qq: atQQ } }, context) => {
if (!context.peer) return undefined; if (!context.peer) return undefined;
@ -46,10 +46,10 @@ const _handlers: {
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 // then the qq is a group member
const atMember = await getGroupMember(context.peer.peerUid, atQQ); // Mlikiowa V2.0.0 Refactor Todo
return atMember ? let uid = await coreContext.getApiContext().UserApi.getUidByUin(atQQ);
SendMsgElementConstructor.at(coreContext, atQQ, atMember.uid, AtType.atUser, atMember.cardName || atMember.nick) : if (!uid) throw new Error('Get Uid Error')
undefined; return SendMsgElementConstructor.at(coreContext, atQQ, uid, AtType.atUser, "");
}, },
[OB11MessageDataType.reply]: async (coreContext, { data: { id } }) => { [OB11MessageDataType.reply]: async (coreContext, { data: { id } }) => {
const replyMsgM = MessageUnique.getMsgIdAndPeerByShortId(parseInt(id)); const replyMsgM = MessageUnique.getMsgIdAndPeerByShortId(parseInt(id));
@ -64,19 +64,15 @@ const _handlers: {
undefined; undefined;
}, },
[OB11MessageDataType.face]: async (coreContext, { data: { id } }) => SendMsgElementConstructor.face(parseInt(id)), [OB11MessageDataType.face]: async (coreContext, { data: { id } }) => SendMsgElementConstructor.face(coreContext, parseInt(id)),
[OB11MessageDataType.mface]: async (coreContext, { [OB11MessageDataType.mface]: async (coreContext, {
data: { data: {
emoji_package_id, emoji_package_id, emoji_id, key, summary
emoji_id,
key,
summary
} }
}) => SendMsgElementConstructor.mface(coreContext, emoji_package_id, emoji_id, key, summary), }) => SendMsgElementConstructor.mface(coreContext, emoji_package_id, emoji_id, key, summary),
// File service // File service
[OB11MessageDataType.image]: async (coreContext, sendMsg, context) => { [OB11MessageDataType.image]: async (coreContext, sendMsg, context) => {
const PicEle = await SendMsgElementConstructor.pic( const PicEle = await SendMsgElementConstructor.pic(
coreContext, coreContext,
@ -86,9 +82,7 @@ const _handlers: {
); );
context.deleteAfterSentFiles.push(PicEle.picElement.sourcePath); context.deleteAfterSentFiles.push(PicEle.picElement.sourcePath);
return PicEle; return PicEle;
} }, // currently not supported
, // currently not supported
[OB11MessageDataType.file]: async (coreContext, sendMsg, context) => { [OB11MessageDataType.file]: async (coreContext, sendMsg, context) => {
const { path, fileName } = await handleOb11FileLikeMessage(coreContext, sendMsg, context); const { path, fileName } = await handleOb11FileLikeMessage(coreContext, sendMsg, context);
//logDebug('发送文件', path, fileName); //logDebug('发送文件', path, fileName);
@ -113,8 +107,7 @@ const _handlers: {
return videoEle; return videoEle;
}, },
[OB11MessageDataType.voice]: async (coreContext, sendMsg, context) => [OB11MessageDataType.voice]: async (coreContext, sendMsg, context) => SendMsgElementConstructor.ptt(coreContext, (await handleOb11FileLikeMessage(coreContext, sendMsg, context)).path),
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),
@ -170,7 +163,7 @@ const _handlers: {
const musicJson = await RequestUtil.HttpGetJson<any>(signUrl, 'POST', postData); const musicJson = await RequestUtil.HttpGetJson<any>(signUrl, 'POST', postData);
return SendMsgElementConstructor.ark(coreContext, musicJson); return SendMsgElementConstructor.ark(coreContext, musicJson);
} catch (e) { } catch (e) {
logError('生成音乐消息失败', e); coreContext.context.logger.logError('生成音乐消息失败', e);
} }
}, },
@ -184,6 +177,9 @@ const _handlers: {
[OB11MessageDataType.Location]: async (coreContext) => { [OB11MessageDataType.Location]: async (coreContext) => {
return SendMsgElementConstructor.location(coreContext); return SendMsgElementConstructor.location(coreContext);
},
[OB11MessageDataType.miniapp]: function (CoreContext: NapCatCore, sendMsg: never, context: MessageContext): Promise<SendMessageElement | undefined> {
throw new Error('Function not implemented.');
} }
}; };