mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
chore: Onebot context
This commit is contained in:
parent
c01d7dae2d
commit
b810040145
@ -12,7 +12,7 @@ export class GoCQHTTPHandleQuickAction extends BaseAction<Payload, null> {
|
|||||||
actionName = ActionName.GoCQHTTP_HandleQuickAction;
|
actionName = ActionName.GoCQHTTP_HandleQuickAction;
|
||||||
|
|
||||||
async _handle(payload: Payload): Promise<null> {
|
async _handle(payload: Payload): Promise<null> {
|
||||||
handleQuickOperation(this.CoreContext, payload.context, payload.operation).then().catch(this.CoreContext.context.logger.logError);
|
handleQuickOperation(this.CoreContext, this.OneBotContext, payload.context, payload.operation).then().catch(this.CoreContext.context.logger.logError);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import { RequestUtil } from '@/common/utils/request';
|
|||||||
import { MessageUnique } from '@/common/utils/MessageUnique';
|
import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||||
import { AtType, CustomMusicSignPostData, IdMusicSignPostData, NapCatCore, Peer, SendMessageElement } from '@/core';
|
import { AtType, CustomMusicSignPostData, IdMusicSignPostData, NapCatCore, Peer, SendMessageElement } from '@/core';
|
||||||
import { SendMsgElementConstructor } from '@/onebot/helper/msg';
|
import { SendMsgElementConstructor } from '@/onebot/helper/msg';
|
||||||
|
import { NapCatOneBot11Adapter } from '@/onebot';
|
||||||
|
|
||||||
export type MessageContext = {
|
export type MessageContext = {
|
||||||
deleteAfterSentFiles: string[],
|
deleteAfterSentFiles: string[],
|
||||||
@ -12,6 +13,7 @@ export type MessageContext = {
|
|||||||
|
|
||||||
async function handleOb11FileLikeMessage(
|
async function handleOb11FileLikeMessage(
|
||||||
coreContext: NapCatCore,
|
coreContext: NapCatCore,
|
||||||
|
obContext: NapCatOneBot11Adapter,
|
||||||
{ data: inputdata }: OB11MessageFileBase,
|
{ data: inputdata }: OB11MessageFileBase,
|
||||||
{ deleteAfterSentFiles }: MessageContext,
|
{ deleteAfterSentFiles }: MessageContext,
|
||||||
) {
|
) {
|
||||||
@ -39,15 +41,16 @@ async function handleOb11FileLikeMessage(
|
|||||||
const _handlers: {
|
const _handlers: {
|
||||||
[Key in OB11MessageDataType]: (
|
[Key in OB11MessageDataType]: (
|
||||||
CoreContext: NapCatCore,
|
CoreContext: NapCatCore,
|
||||||
|
obContext: NapCatOneBot11Adapter,
|
||||||
sendMsg: Extract<OB11MessageData, { type: Key }>,
|
sendMsg: Extract<OB11MessageData, { type: Key }>,
|
||||||
// This picks the correct message type out
|
// This picks the correct message type out
|
||||||
// How great the type system of TypeScript is!
|
// How great the type system of TypeScript is!
|
||||||
context: MessageContext,
|
context: MessageContext,
|
||||||
) => Promise<SendMessageElement | undefined>
|
) => Promise<SendMessageElement | undefined>
|
||||||
} = {
|
} = {
|
||||||
[OB11MessageDataType.text]: async (coreContext, { data: { text } }) => SendMsgElementConstructor.text(coreContext, text),
|
[OB11MessageDataType.text]: async (coreContext, obContext: NapCatOneBot11Adapter, { data: { text } }) => SendMsgElementConstructor.text(coreContext, text),
|
||||||
|
|
||||||
[OB11MessageDataType.at]: async (coreContext, { data: { qq: atQQ } }, context) => {
|
[OB11MessageDataType.at]: async (coreContext, obContext: NapCatOneBot11Adapter, { data: { qq: atQQ } }, context) => {
|
||||||
if (!context.peer) return undefined;
|
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, '全体成员');
|
||||||
@ -58,7 +61,7 @@ const _handlers: {
|
|||||||
if (!uid) throw new Error('Get Uid Error');
|
if (!uid) throw new Error('Get Uid Error');
|
||||||
return SendMsgElementConstructor.at(coreContext, atQQ, uid, AtType.atUser, '');
|
return SendMsgElementConstructor.at(coreContext, atQQ, uid, AtType.atUser, '');
|
||||||
},
|
},
|
||||||
[OB11MessageDataType.reply]: async (coreContext, { data: { id } }) => {
|
[OB11MessageDataType.reply]: async (coreContext, obContext: NapCatOneBot11Adapter, { data: { id } }) => {
|
||||||
const replyMsgM = MessageUnique.getMsgIdAndPeerByShortId(parseInt(id));
|
const replyMsgM = MessageUnique.getMsgIdAndPeerByShortId(parseInt(id));
|
||||||
if (!replyMsgM) {
|
if (!replyMsgM) {
|
||||||
coreContext.context.logger.logWarn('回复消息不存在', id);
|
coreContext.context.logger.logWarn('回复消息不存在', id);
|
||||||
@ -72,27 +75,27 @@ const _handlers: {
|
|||||||
undefined;
|
undefined;
|
||||||
},
|
},
|
||||||
|
|
||||||
[OB11MessageDataType.face]: async (coreContext, { data: { id } }) => SendMsgElementConstructor.face(coreContext, parseInt(id)),
|
[OB11MessageDataType.face]: async (coreContext, obContext: NapCatOneBot11Adapter, { data: { id } }) => SendMsgElementConstructor.face(coreContext, parseInt(id)),
|
||||||
|
|
||||||
[OB11MessageDataType.mface]: async (coreContext, {
|
[OB11MessageDataType.mface]: async (coreContext, obContext: NapCatOneBot11Adapter, {
|
||||||
data: {
|
data: {
|
||||||
emoji_package_id, emoji_id, key, summary,
|
emoji_package_id, 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, obContext: NapCatOneBot11Adapter, sendMsg, context) => {
|
||||||
const PicEle = await SendMsgElementConstructor.pic(
|
const PicEle = await SendMsgElementConstructor.pic(
|
||||||
coreContext,
|
coreContext,
|
||||||
(await handleOb11FileLikeMessage(coreContext, sendMsg, context)).path,
|
(await handleOb11FileLikeMessage(coreContext, obContext, sendMsg, context)).path,
|
||||||
sendMsg.data.summary || '',
|
sendMsg.data.summary || '',
|
||||||
sendMsg.data.subType || 0,
|
sendMsg.data.subType || 0,
|
||||||
);
|
);
|
||||||
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, obContext: NapCatOneBot11Adapter, sendMsg, context) => {
|
||||||
const { path, fileName } = await handleOb11FileLikeMessage(coreContext, sendMsg, context);
|
const { path, fileName } = await handleOb11FileLikeMessage(coreContext, obContext, sendMsg, context);
|
||||||
//logDebug('发送文件', path, fileName);
|
//logDebug('发送文件', path, fileName);
|
||||||
const FileEle = await SendMsgElementConstructor.file(coreContext, path, fileName);
|
const FileEle = await SendMsgElementConstructor.file(coreContext, path, fileName);
|
||||||
// 清除Upload的应该
|
// 清除Upload的应该
|
||||||
@ -100,8 +103,8 @@ const _handlers: {
|
|||||||
return FileEle;
|
return FileEle;
|
||||||
},
|
},
|
||||||
|
|
||||||
[OB11MessageDataType.video]: async (coreContext, sendMsg, context) => {
|
[OB11MessageDataType.video]: async (coreContext, obContext, sendMsg, context) => {
|
||||||
const { path, fileName } = await handleOb11FileLikeMessage(coreContext, sendMsg, context);
|
const { path, fileName } = await handleOb11FileLikeMessage(coreContext, obContext, sendMsg, context);
|
||||||
|
|
||||||
//logDebug('发送视频', path, fileName);
|
//logDebug('发送视频', path, fileName);
|
||||||
let thumb = sendMsg.data.thumb;
|
let thumb = sendMsg.data.thumb;
|
||||||
@ -115,17 +118,17 @@ const _handlers: {
|
|||||||
return videoEle;
|
return videoEle;
|
||||||
},
|
},
|
||||||
|
|
||||||
[OB11MessageDataType.voice]: async (coreContext, sendMsg, context) => SendMsgElementConstructor.ptt(coreContext, (await handleOb11FileLikeMessage(coreContext, sendMsg, context)).path),
|
[OB11MessageDataType.voice]: async (coreContext, obContext: NapCatOneBot11Adapter, sendMsg, context) => SendMsgElementConstructor.ptt(coreContext, (await handleOb11FileLikeMessage(coreContext, obContext, sendMsg, context)).path),
|
||||||
|
|
||||||
[OB11MessageDataType.json]: async (coreContext, { data: { data } }) => SendMsgElementConstructor.ark(coreContext, data),
|
[OB11MessageDataType.json]: async (coreContext, obContext: NapCatOneBot11Adapter, { data: { data } }) => SendMsgElementConstructor.ark(coreContext, data),
|
||||||
|
|
||||||
[OB11MessageDataType.dice]: async (coreContext, { data: { result } }) => SendMsgElementConstructor.dice(coreContext, result),
|
[OB11MessageDataType.dice]: async (coreContext, obContext: NapCatOneBot11Adapter, { data: { result } }) => SendMsgElementConstructor.dice(coreContext, result),
|
||||||
|
|
||||||
[OB11MessageDataType.RPS]: async (coreContext, { data: { result } }) => SendMsgElementConstructor.rps(coreContext, result),
|
[OB11MessageDataType.RPS]: async (coreContext, obContext: NapCatOneBot11Adapter, { data: { result } }) => SendMsgElementConstructor.rps(coreContext, result),
|
||||||
|
|
||||||
[OB11MessageDataType.markdown]: async (coreContext, { data: { content } }) => SendMsgElementConstructor.markdown(coreContext, content),
|
[OB11MessageDataType.markdown]: async (coreContext, obContext: NapCatOneBot11Adapter, { data: { content } }) => SendMsgElementConstructor.markdown(coreContext, content),
|
||||||
|
|
||||||
[OB11MessageDataType.music]: async (coreContext, { data }) => {
|
[OB11MessageDataType.music]: async (coreContext, obContext: NapCatOneBot11Adapter, { data }) => {
|
||||||
// 保留, 直到...找到更好的解决方案
|
// 保留, 直到...找到更好的解决方案
|
||||||
if (data.type === 'custom') {
|
if (data.type === 'custom') {
|
||||||
if (!data.url) {
|
if (!data.url) {
|
||||||
@ -159,7 +162,7 @@ const _handlers: {
|
|||||||
postData = data;
|
postData = data;
|
||||||
}
|
}
|
||||||
// Mlikiowa V2.0.0 Refactor Todo
|
// Mlikiowa V2.0.0 Refactor Todo
|
||||||
const signUrl = '';
|
const signUrl = obContext.configLoader.configData.musicSignUrl;
|
||||||
if (!signUrl) {
|
if (!signUrl) {
|
||||||
if (data.type === 'qq') {
|
if (data.type === 'qq') {
|
||||||
//const musicJson = (await SignMusicWrapper(data.id.toString())).data.arkResult.slice(0, -1);
|
//const musicJson = (await SignMusicWrapper(data.id.toString())).data.arkResult.slice(0, -1);
|
||||||
@ -175,18 +178,18 @@ const _handlers: {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
[OB11MessageDataType.node]: async (coreContext) => undefined,
|
[OB11MessageDataType.node]: async (coreContext, obContext: NapCatOneBot11Adapter) => undefined,
|
||||||
|
|
||||||
[OB11MessageDataType.forward]: async (coreContext) => undefined,
|
[OB11MessageDataType.forward]: async (coreContext, obContext: NapCatOneBot11Adapter) => undefined,
|
||||||
|
|
||||||
[OB11MessageDataType.xml]: async (coreContext) => undefined,
|
[OB11MessageDataType.xml]: async (coreContext, obContext: NapCatOneBot11Adapter) => undefined,
|
||||||
|
|
||||||
[OB11MessageDataType.poke]: async (coreContext) => undefined,
|
[OB11MessageDataType.poke]: async (coreContext, obContext: NapCatOneBot11Adapter) => undefined,
|
||||||
|
|
||||||
[OB11MessageDataType.Location]: async (coreContext) => {
|
[OB11MessageDataType.Location]: async (coreContext, obContext: NapCatOneBot11Adapter) => {
|
||||||
return SendMsgElementConstructor.location(coreContext);
|
return SendMsgElementConstructor.location(coreContext);
|
||||||
},
|
},
|
||||||
[OB11MessageDataType.miniapp]: function(CoreContext: NapCatCore, sendMsg: never, context: MessageContext): Promise<SendMessageElement | undefined> {
|
[OB11MessageDataType.miniapp]: function (CoreContext: NapCatCore, obContext: NapCatOneBot11Adapter, sendMsg: never, context: MessageContext): Promise<SendMessageElement | undefined> {
|
||||||
throw new Error('Function not implemented.');
|
throw new Error('Function not implemented.');
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -194,6 +197,7 @@ const _handlers: {
|
|||||||
const handlers = <{
|
const handlers = <{
|
||||||
[Key in OB11MessageDataType]: (
|
[Key in OB11MessageDataType]: (
|
||||||
coreContext: NapCatCore,
|
coreContext: NapCatCore,
|
||||||
|
obContext: NapCatOneBot11Adapter,
|
||||||
sendMsg: OB11MessageData,
|
sendMsg: OB11MessageData,
|
||||||
context: MessageContext,
|
context: MessageContext,
|
||||||
) => Promise<SendMessageElement | undefined>
|
) => Promise<SendMessageElement | undefined>
|
||||||
@ -201,6 +205,7 @@ const handlers = <{
|
|||||||
|
|
||||||
export default async function createSendElements(
|
export default async function createSendElements(
|
||||||
CoreContext: NapCatCore,
|
CoreContext: NapCatCore,
|
||||||
|
obContext: NapCatOneBot11Adapter,
|
||||||
messageData: OB11MessageData[],
|
messageData: OB11MessageData[],
|
||||||
peer: Peer,
|
peer: Peer,
|
||||||
ignoreTypes: OB11MessageDataType[] = [],
|
ignoreTypes: OB11MessageDataType[] = [],
|
||||||
@ -213,6 +218,7 @@ export default async function createSendElements(
|
|||||||
}
|
}
|
||||||
const callResult = handlers[sendMsg.type](
|
const callResult = handlers[sendMsg.type](
|
||||||
CoreContext,
|
CoreContext,
|
||||||
|
obContext,
|
||||||
sendMsg,
|
sendMsg,
|
||||||
{ peer, deleteAfterSentFiles },
|
{ peer, deleteAfterSentFiles },
|
||||||
)?.catch(undefined);
|
)?.catch(undefined);
|
||||||
@ -225,6 +231,7 @@ export default async function createSendElements(
|
|||||||
|
|
||||||
export async function createSendElementsParallel(
|
export async function createSendElementsParallel(
|
||||||
CoreContext: NapCatCore,
|
CoreContext: NapCatCore,
|
||||||
|
obContext: NapCatOneBot11Adapter,
|
||||||
messageData: OB11MessageData[],
|
messageData: OB11MessageData[],
|
||||||
peer: Peer,
|
peer: Peer,
|
||||||
ignoreTypes: OB11MessageDataType[] = [],
|
ignoreTypes: OB11MessageDataType[] = [],
|
||||||
@ -234,7 +241,7 @@ export async function createSendElementsParallel(
|
|||||||
await Promise.all(
|
await Promise.all(
|
||||||
messageData.map(async sendMsg => ignoreTypes.includes(sendMsg.type) ?
|
messageData.map(async sendMsg => ignoreTypes.includes(sendMsg.type) ?
|
||||||
undefined :
|
undefined :
|
||||||
handlers[sendMsg.type](CoreContext, sendMsg, { peer, deleteAfterSentFiles })),
|
handlers[sendMsg.type](CoreContext, obContext, sendMsg, { peer, deleteAfterSentFiles })),
|
||||||
).then(
|
).then(
|
||||||
results => results.filter(
|
results => results.filter(
|
||||||
element => element !== undefined,
|
element => element !== undefined,
|
||||||
|
@ -3,6 +3,7 @@ import { MessageUnique } from '@/common/utils/MessageUnique';
|
|||||||
import { OB11MessageDataType, OB11MessageNode } from '@/onebot/types';
|
import { OB11MessageDataType, OB11MessageNode } from '@/onebot/types';
|
||||||
import createSendElements from './create-send-elements';
|
import createSendElements from './create-send-elements';
|
||||||
import { normalize, sendMsg } from '../SendMsg/index';
|
import { normalize, sendMsg } from '../SendMsg/index';
|
||||||
|
import { NapCatOneBot11Adapter } from '@/onebot';
|
||||||
|
|
||||||
async function cloneMsg(coreContext: NapCatCore, msg: RawMessage): Promise<RawMessage | undefined> {
|
async function cloneMsg(coreContext: NapCatCore, msg: RawMessage): Promise<RawMessage | undefined> {
|
||||||
const selfPeer = {
|
const selfPeer = {
|
||||||
@ -30,7 +31,7 @@ async function cloneMsg(coreContext: NapCatCore, msg: RawMessage): Promise<RawMe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handleForwardNode(coreContext: NapCatCore, destPeer: Peer, messageNodes: OB11MessageNode[]): Promise<RawMessage | null> {
|
export async function handleForwardNode(coreContext: NapCatCore, obContext: NapCatOneBot11Adapter, destPeer: Peer, messageNodes: OB11MessageNode[]): Promise<RawMessage | null> {
|
||||||
const NTQQMsgApi = coreContext.apis.MsgApi;
|
const NTQQMsgApi = coreContext.apis.MsgApi;
|
||||||
const selfPeer = {
|
const selfPeer = {
|
||||||
chatType: ChatType.friend,
|
chatType: ChatType.friend,
|
||||||
@ -59,7 +60,7 @@ export async function handleForwardNode(coreContext: NapCatCore, destPeer: Peer,
|
|||||||
logger.logError('子消息中包含非node消息 跳过不合法部分');
|
logger.logError('子消息中包含非node消息 跳过不合法部分');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const nodeMsg = await handleForwardNode(coreContext, selfPeer, OB11Data.filter(e => e.type === OB11MessageDataType.node));
|
const nodeMsg = await handleForwardNode(coreContext, obContext, selfPeer, OB11Data.filter(e => e.type === OB11MessageDataType.node));
|
||||||
if (nodeMsg) {
|
if (nodeMsg) {
|
||||||
nodeMsgIds.push(nodeMsg.msgId);
|
nodeMsgIds.push(nodeMsg.msgId);
|
||||||
MessageUnique.createMsg(selfPeer, nodeMsg.msgId);
|
MessageUnique.createMsg(selfPeer, nodeMsg.msgId);
|
||||||
@ -67,7 +68,7 @@ export async function handleForwardNode(coreContext: NapCatCore, destPeer: Peer,
|
|||||||
//完成子卡片生成跳过后续
|
//完成子卡片生成跳过后续
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const { sendElements } = await createSendElements(coreContext, OB11Data, destPeer);
|
const { sendElements } = await createSendElements(coreContext, obContext, OB11Data, destPeer);
|
||||||
//拆分消息
|
//拆分消息
|
||||||
const MixElement = sendElements.filter(element => element.elementType !== ElementType.FILE && element.elementType !== ElementType.VIDEO);
|
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 SingleElement = sendElements.filter(element => element.elementType === ElementType.FILE || element.elementType === ElementType.VIDEO).map(e => [e]);
|
||||||
|
@ -156,7 +156,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (getSpecialMsgNum(payload, OB11MessageDataType.node)) {
|
if (getSpecialMsgNum(payload, OB11MessageDataType.node)) {
|
||||||
const returnMsg = await handleForwardNode(this.CoreContext, peer, messages as OB11MessageNode[]);
|
const returnMsg = await handleForwardNode(this.CoreContext, this.OneBotContext, peer, messages as OB11MessageNode[]);
|
||||||
if (returnMsg) {
|
if (returnMsg) {
|
||||||
const msgShortId = MessageUnique.createMsg({
|
const msgShortId = MessageUnique.createMsg({
|
||||||
guildId: '',
|
guildId: '',
|
||||||
@ -176,7 +176,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
}
|
}
|
||||||
// log("send msg:", peer, sendElements)
|
// log("send msg:", peer, sendElements)
|
||||||
|
|
||||||
const { sendElements, deleteAfterSentFiles } = await createSendElements(this.CoreContext, messages, peer);
|
const { sendElements, deleteAfterSentFiles } = await createSendElements(this.CoreContext, this.OneBotContext, messages, peer);
|
||||||
//console.log(peer, JSON.stringify(sendElements,null,2));
|
//console.log(peer, JSON.stringify(sendElements,null,2));
|
||||||
const returnMsg = await sendMsg(this.CoreContext, peer, sendElements, deleteAfterSentFiles);
|
const returnMsg = await sendMsg(this.CoreContext, peer, sendElements, deleteAfterSentFiles);
|
||||||
return { message_id: returnMsg!.id! };
|
return { message_id: returnMsg!.id! };
|
||||||
|
@ -14,8 +14,9 @@ import {
|
|||||||
} from '../types';
|
} from '../types';
|
||||||
import { isNull } from '@/common/utils/helper';
|
import { isNull } from '@/common/utils/helper';
|
||||||
import { createSendElements, normalize, sendMsg } from '../action/msg/SendMsg';
|
import { createSendElements, normalize, sendMsg } from '../action/msg/SendMsg';
|
||||||
|
import { NapCatOneBot11Adapter } from '..';
|
||||||
|
|
||||||
async function handleMsg(coreContext: NapCatCore, msg: OB11Message, quickAction: QuickAction) {
|
async function handleMsg(coreContext: NapCatCore, obContext: NapCatOneBot11Adapter, msg: OB11Message, quickAction: QuickAction) {
|
||||||
msg = msg as OB11Message;
|
msg = msg as OB11Message;
|
||||||
const reply = quickAction.reply;
|
const reply = quickAction.reply;
|
||||||
const peer: Peer = {
|
const peer: Peer = {
|
||||||
@ -52,7 +53,7 @@ async function handleMsg(coreContext: NapCatCore, msg: OB11Message, quickAction:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
replyMessage = replyMessage.concat(normalize(reply, quickAction.auto_escape));
|
replyMessage = replyMessage.concat(normalize(reply, quickAction.auto_escape));
|
||||||
const { sendElements, deleteAfterSentFiles } = await createSendElements(coreContext, replyMessage, peer);
|
const { sendElements, deleteAfterSentFiles } = await createSendElements(coreContext, obContext, replyMessage, peer);
|
||||||
sendMsg(coreContext, peer, sendElements, deleteAfterSentFiles, false).then().catch(coreContext.context.logger.logError);
|
sendMsg(coreContext, peer, sendElements, deleteAfterSentFiles, false).then().catch(coreContext.context.logger.logError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -73,9 +74,9 @@ async function handleFriendRequest(coreContext: NapCatCore, request: OB11FriendR
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handleQuickOperation(coreContext: NapCatCore, context: QuickActionEvent, quickAction: QuickAction) {
|
export async function handleQuickOperation(coreContext: NapCatCore, obContext: NapCatOneBot11Adapter, context: QuickActionEvent, quickAction: QuickAction) {
|
||||||
if (context.post_type === 'message') {
|
if (context.post_type === 'message') {
|
||||||
handleMsg(coreContext, context as OB11Message, quickAction).then().catch(coreContext.context.logger.logError);
|
handleMsg(coreContext, obContext, context as OB11Message, quickAction).then().catch(coreContext.context.logger.logError);
|
||||||
}
|
}
|
||||||
if (context.post_type === 'request') {
|
if (context.post_type === 'request') {
|
||||||
const friendRequest = context as OB11FriendRequestEvent;
|
const friendRequest = context as OB11FriendRequestEvent;
|
||||||
|
@ -4,6 +4,7 @@ import { LogWrapper } from '@/common/utils/log';
|
|||||||
import { QuickAction, QuickActionEvent } from '../types';
|
import { QuickAction, QuickActionEvent } from '../types';
|
||||||
import { NapCatCore } from '@/core';
|
import { NapCatCore } from '@/core';
|
||||||
import { handleQuickOperation } from '../helper/quick';
|
import { handleQuickOperation } from '../helper/quick';
|
||||||
|
import { NapCatOneBot11Adapter } from '..';
|
||||||
|
|
||||||
export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter {
|
export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter {
|
||||||
logger: LogWrapper;
|
logger: LogWrapper;
|
||||||
@ -12,7 +13,8 @@ export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter {
|
|||||||
constructor(
|
constructor(
|
||||||
public url: string,
|
public url: string,
|
||||||
public secret: string | undefined,
|
public secret: string | undefined,
|
||||||
public coreContext: NapCatCore
|
public coreContext: NapCatCore,
|
||||||
|
public obContext: NapCatOneBot11Adapter
|
||||||
) {
|
) {
|
||||||
this.logger = coreContext.context.logger;
|
this.logger = coreContext.context.logger;
|
||||||
}
|
}
|
||||||
@ -46,7 +48,7 @@ export class OB11ActiveHttpAdapter implements IOB11NetworkAdapter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
handleQuickOperation(this.coreContext, event as QuickActionEvent, resJson).then().catch(this.logger.logError);
|
handleQuickOperation(this.coreContext, this.obContext, event as QuickActionEvent, resJson).then().catch(this.logger.logError);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
this.logger.logError('新消息事件HTTP上报返回快速操作失败', e);
|
this.logger.logError('新消息事件HTTP上报返回快速操作失败', e);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user