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 { OB11PostSendMsg } from '../../types';
|
||||||
import { ActionName } from '../types';
|
import { ActionName } from '../types';
|
||||||
|
|
||||||
@ -6,7 +6,7 @@ export class GoCQHTTPSendForwardMsg extends SendMsg {
|
|||||||
actionName = ActionName.GoCQHTTP_SendForwardMsg;
|
actionName = ActionName.GoCQHTTP_SendForwardMsg;
|
||||||
|
|
||||||
protected async check(payload: OB11PostSendMsg) {
|
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);
|
return super.check(payload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -17,4 +17,4 @@ export class GoCQHTTPSendPrivateForwardMsg extends GoCQHTTPSendForwardMsg {
|
|||||||
|
|
||||||
export class GoCQHTTPSendGroupForwardMsg extends GoCQHTTPSendForwardMsg {
|
export class GoCQHTTPSendGroupForwardMsg extends GoCQHTTPSendForwardMsg {
|
||||||
actionName = ActionName.GoCQHTTP_SendGroupForwardMsg;
|
actionName = ActionName.GoCQHTTP_SendGroupForwardMsg;
|
||||||
}
|
}
|
||||||
|
@ -72,22 +72,13 @@ export interface ReturnDataType {
|
|||||||
message_id: number;
|
message_id: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function convertMessage2List(message: OB11MessageMixType, autoEscape = false) {
|
// Normalizes a mixed type (CQCode/a single segment/segment array) into a segment array.
|
||||||
if (typeof message === 'string') {
|
export function normalize(message: OB11MessageMixType, autoEscape = false): OB11MessageData[] {
|
||||||
if (autoEscape === true) {
|
return typeof message === 'string' ? (
|
||||||
message = [{
|
autoEscape ?
|
||||||
type: OB11MessageDataType.text,
|
[{ type: OB11MessageDataType.text, data: { text: message } }] :
|
||||||
data: {
|
decodeCQCode(message)
|
||||||
text: message
|
) : Array.isArray(message) ? message : [message];
|
||||||
}
|
|
||||||
}];
|
|
||||||
} else {
|
|
||||||
message = decodeCQCode(message.toString());
|
|
||||||
}
|
|
||||||
} else if (!Array.isArray(message)) {
|
|
||||||
message = [message];
|
|
||||||
}
|
|
||||||
return message;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function sendMsg(peer: Peer, sendElements: SendMessageElement[], deleteAfterSentFiles: string[], waitComplete = true) {
|
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 { ob11Config } from '@/onebot11/config';
|
||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
import { ChatType, Group, GroupRequestOperateTypes, Peer } from '@/core/entities';
|
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 { OB11FriendRequestEvent } from '../event/request/OB11FriendRequest';
|
||||||
import { OB11GroupRequestEvent } from '../event/request/OB11GroupRequest';
|
import { OB11GroupRequestEvent } from '../event/request/OB11GroupRequest';
|
||||||
import { isNull } from '@/common/utils/helper';
|
import { isNull } from '@/common/utils/helper';
|
||||||
@ -138,7 +138,7 @@ export function postOB11Event(msg: PostEventType, reportSelf = false, postWs = t
|
|||||||
} as OB11MessageAt);
|
} 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);
|
const { sendElements, deleteAfterSentFiles } = await createSendElements(replyMessage, group);
|
||||||
sendMsg(peer, sendElements, deleteAfterSentFiles, false).then();
|
sendMsg(peer, sendElements, deleteAfterSentFiles, false).then();
|
||||||
} else if (resJson.delete) {
|
} else if (resJson.delete) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user