Revert "try fix"

This reverts commit 35419ade29.
This commit is contained in:
手瓜一十雪 2024-08-12 23:03:58 +08:00
parent 35419ade29
commit 9b458958b8

View File

@ -108,26 +108,16 @@ export class LogWrapper {
_log(level: LogLevel, ...args: any[]) { _log(level: LogLevel, ...args: any[]) {
try { if (this.consoleLogEnabled) {
if (this.consoleLogEnabled) { this.loggerConsole[level](this.formatMsg(args));
this.loggerConsole[level](this.formatMsg(args)); }
} if (this.fileLogEnabled) {
if (this.fileLogEnabled) { this.loggerFile[level](this.formatMsg(args).replace(this.colorEscape, ''));
this.loggerFile[level](this.formatMsg(args).replace(this.colorEscape, ''));
}
} catch (error) {
if (error.code === 'EPIPE') {
console.error('EPIPE error occurred. Reconfiguring log4js.');
log4js.shutdown(() => {
log4js.configure(this.logConfig);
});
} else {
throw error;
}
} }
} }
log(...args: any[]) { log(...args: any[]) {
// info 等级
this._log(LogLevel.INFO, ...args); this._log(LogLevel.INFO, ...args);
} }
@ -149,7 +139,9 @@ export class LogWrapper {
logMessage(msg: RawMessage, selfInfo: SelfInfo) { logMessage(msg: RawMessage, selfInfo: SelfInfo) {
const isSelfSent = msg.senderUin === selfInfo.uin; const isSelfSent = msg.senderUin === selfInfo.uin;
this.log(`${isSelfSent ? '发送 ->' : '接收 <-'} ${rawMessageToText(msg)}`); this.log(`${
isSelfSent ? '发送 ->' : '接收 <-'
} ${rawMessageToText(msg)}`);
} }
} }
@ -166,10 +158,12 @@ export function rawMessageToText(msg: RawMessage, recursiveLevel = 0): string {
tokens.push(`群聊 (群 ${msg.peerUin}${msg.senderUin})`); tokens.push(`群聊 (群 ${msg.peerUin}${msg.senderUin})`);
} else if (msg.chatType == ChatType.chatDevice) { } else if (msg.chatType == ChatType.chatDevice) {
tokens.push('移动设备'); tokens.push('移动设备');
} else { } else /* temp */ {
tokens.push(`临时消息 (${msg.peerUin})`); tokens.push(`临时消息 (${msg.peerUin})`);
} }
// message content
function msgElementToText(element: ElementWrapper) { function msgElementToText(element: ElementWrapper) {
if (element.textElement) { if (element.textElement) {
if (element.textElement.atType === AtType.notAt) { if (element.textElement.atType === AtType.notAt) {
@ -180,47 +174,60 @@ export function rawMessageToText(msg: RawMessage, recursiveLevel = 0): string {
return `${element.textElement.content} (${element.textElement.atUid})`; return `${element.textElement.content} (${element.textElement.atUid})`;
} }
} }
if (element.replyElement) { if (element.replyElement) {
const recordMsgOrNull = msg.records.find( const recordMsgOrNull = msg.records.find(
record => element.replyElement!.sourceMsgIdInRecords === record.msgId record => element.replyElement!.sourceMsgIdInRecords === record.msgId
); );
return `[回复消息 ${ return `[回复消息 ${
recordMsgOrNull && recordMsgOrNull &&
recordMsgOrNull.peerUin != '284840486' recordMsgOrNull.peerUin != '284840486' // 非转发消息; 否则定位不到
? rawMessageToText(recordMsgOrNull, recursiveLevel + 1) ?
: `未找到消息记录 (MsgId = ${element.replyElement.sourceMsgIdInRecords})` rawMessageToText(recordMsgOrNull, recursiveLevel + 1) :
`未找到消息记录 (MsgId = ${element.replyElement.sourceMsgIdInRecords})`
}]`; }]`;
} }
if (element.picElement) { if (element.picElement) {
return `[图片 ${element.picElement.fileName}]`; return `[图片 ${element.picElement.fileName}]`;
} }
if (element.fileElement) { if (element.fileElement) {
return `[文件 ${element.fileElement.fileName}]`; return `[文件 ${element.fileElement.fileName}]`;
} }
if (element.videoElement) { if (element.videoElement) {
return `[视频 ${element.videoElement.fileName}]`; return `[视频 ${element.videoElement.fileName}]`;
} }
if (element.pttElement) { if (element.pttElement) {
return `[语音 ${element.pttElement.duration}s]`; return `[语音 ${element.pttElement.duration}s]`;
} }
if (element.arkElement) { if (element.arkElement) {
return `[卡片消息 ${element.arkElement.bytesData}]`; return `[卡片消息 ${element.arkElement.bytesData}]`;
} }
if (element.faceElement) { if (element.faceElement) {
return `[表情 ${element.faceElement.faceText ?? ''}]`; return `[表情 ${element.faceElement.faceText ?? ''}]`;
} }
if (element.marketFaceElement) { if (element.marketFaceElement) {
return `[商城表情 ${element.marketFaceElement.faceName}]`; return `[商城表情 ${element.marketFaceElement.faceName}]`;
} }
if (element.markdownElement) { if (element.markdownElement) {
return `[Markdown ${element.markdownElement.content}]`; return `[Markdown ${element.markdownElement.content}]`;
} }
if (element.multiForwardMsgElement) { if (element.multiForwardMsgElement) {
return `[转发消息]`; return `[转发消息]`;
} }
if (element.elementType === ElementType.GreyTip) { if (element.elementType === ElementType.GreyTip) {
return `[灰条消息]`; return `[灰条消息]`; // TODO: resolve the text
} }
return `[未实现 (ElementType = ${element.elementType})]`; return `[未实现 (ElementType = ${element.elementType})]`;
} }
@ -229,4 +236,4 @@ export function rawMessageToText(msg: RawMessage, recursiveLevel = 0): string {
} }
return tokens.join(' '); return tokens.join(' ');
} }