mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
refactor: rename function convertMessage2List
to normalize
This commit is contained in:
parent
bed3e1289b
commit
b5dbd9d59b
2
src/core
2
src/core
@ -1 +1 @@
|
||||
Subproject commit b1351835673f86d445d244fd515560bfcd0b7adb
|
||||
Subproject commit ed10e0fc9f4b98ad2b677c8862f5cc817a5560ba
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user