diff --git a/src/core b/src/core index b1351835..ed10e0fc 160000 --- a/src/core +++ b/src/core @@ -1 +1 @@ -Subproject commit b1351835673f86d445d244fd515560bfcd0b7adb +Subproject commit ed10e0fc9f4b98ad2b677c8862f5cc817a5560ba diff --git a/src/onebot11/action/go-cqhttp/SendForwardMsg.ts b/src/onebot11/action/go-cqhttp/SendForwardMsg.ts index a2c2ce34..f866816e 100644 --- a/src/onebot11/action/go-cqhttp/SendForwardMsg.ts +++ b/src/onebot11/action/go-cqhttp/SendForwardMsg.ts @@ -1,4 +1,4 @@ -import SendMsg, { convertMessage2List } from '../msg/SendMsg'; +import SendMsg, { normalize } from '../msg/SendMsg'; import { OB11PostSendMsg } from '../../types'; import { ActionName } from '../types'; @@ -6,7 +6,7 @@ export class GoCQHTTPSendForwardMsg extends SendMsg { actionName = ActionName.GoCQHTTP_SendForwardMsg; protected async check(payload: OB11PostSendMsg) { - if (payload.messages) payload.message = convertMessage2List(payload.messages); + if (payload.messages) payload.message = normalize(payload.messages); return super.check(payload); } } @@ -17,4 +17,4 @@ export class GoCQHTTPSendPrivateForwardMsg extends GoCQHTTPSendForwardMsg { export class GoCQHTTPSendGroupForwardMsg extends GoCQHTTPSendForwardMsg { actionName = ActionName.GoCQHTTP_SendGroupForwardMsg; -} \ No newline at end of file +} diff --git a/src/onebot11/action/msg/SendMsg/index.ts b/src/onebot11/action/msg/SendMsg/index.ts index 18cf2e0f..904ef011 100644 --- a/src/onebot11/action/msg/SendMsg/index.ts +++ b/src/onebot11/action/msg/SendMsg/index.ts @@ -72,22 +72,13 @@ export interface ReturnDataType { message_id: number; } -export function convertMessage2List(message: OB11MessageMixType, autoEscape = false) { - if (typeof message === 'string') { - if (autoEscape === true) { - message = [{ - type: OB11MessageDataType.text, - data: { - text: message - } - }]; - } else { - message = decodeCQCode(message.toString()); - } - } else if (!Array.isArray(message)) { - message = [message]; - } - return message; +// 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]; } export async function sendMsg(peer: Peer, sendElements: SendMessageElement[], deleteAfterSentFiles: string[], waitComplete = true) { diff --git a/src/onebot11/server/postOB11Event.ts b/src/onebot11/server/postOB11Event.ts index 58a13515..f7137b06 100644 --- a/src/onebot11/server/postOB11Event.ts +++ b/src/onebot11/server/postOB11Event.ts @@ -7,7 +7,7 @@ import { log, logDebug, logError } from '@/common/utils/log'; import { ob11Config } from '@/onebot11/config'; import crypto from 'crypto'; import { ChatType, Group, GroupRequestOperateTypes, Peer } from '@/core/entities'; -import { convertMessage2List, createSendElements, sendMsg } from '../action/msg/SendMsg'; +import { normalize, createSendElements, sendMsg } from '../action/msg/SendMsg'; import { OB11FriendRequestEvent } from '../event/request/OB11FriendRequest'; import { OB11GroupRequestEvent } from '../event/request/OB11GroupRequest'; import { isNull } from '@/common/utils/helper'; @@ -138,7 +138,7 @@ export function postOB11Event(msg: PostEventType, reportSelf = false, postWs = t } as OB11MessageAt); } } - replyMessage = replyMessage.concat(convertMessage2List(reply, resJson.auto_escape)); + replyMessage = replyMessage.concat(normalize(reply, resJson.auto_escape)); const { sendElements, deleteAfterSentFiles } = await createSendElements(replyMessage, group); sendMsg(peer, sendElements, deleteAfterSentFiles, false).then(); } else if (resJson.delete) {