mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
update: handle unknown message type
This commit is contained in:
parent
b802aad726
commit
4b4f5aad82
@ -258,11 +258,8 @@ export class LaanaMessageUtils {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async rawMessageToLaana(msg: RawMessage): Promise<LaanaMessage | null> {
|
async rawMessageToLaana(msg: RawMessage): Promise<LaanaMessage> {
|
||||||
const msgContentOrNull = await this.createLaanaMessageContent(msg);
|
const msgContent = await this.createLaanaMessageContent(msg);
|
||||||
if (!msgContentOrNull) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
msgId: msg.msgId,
|
msgId: msg.msgId,
|
||||||
time: BigInt(msg.msgTime),
|
time: BigInt(msg.msgTime),
|
||||||
@ -272,15 +269,20 @@ export class LaanaMessageUtils {
|
|||||||
type: msg.chatType === ChatType.KCHATTYPEGROUP ?
|
type: msg.chatType === ChatType.KCHATTYPEGROUP ?
|
||||||
Peer_Type.GROUP : Peer_Type.BUDDY,
|
Peer_Type.GROUP : Peer_Type.BUDDY,
|
||||||
},
|
},
|
||||||
content: msgContentOrNull,
|
content: msgContent,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private async createLaanaMessageContent(msg: RawMessage): Promise<LaanaMessage['content'] | null> {
|
private async createLaanaMessageContent(msg: RawMessage): Promise<LaanaMessage['content']> {
|
||||||
const firstElement = msg.elements[0];
|
const firstElement = msg.elements[0];
|
||||||
|
|
||||||
if (!firstElement) {
|
if (!firstElement) {
|
||||||
throw Error('消息内容为空');
|
return {
|
||||||
|
oneofKind: 'unknownMessage',
|
||||||
|
unknownMessage: {
|
||||||
|
rawContent: '',
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@ -357,10 +359,6 @@ export class LaanaMessageUtils {
|
|||||||
}
|
}
|
||||||
return { oneofKind: 'bubble', bubble };
|
return { oneofKind: 'bubble', bubble };
|
||||||
} else {
|
} else {
|
||||||
if (msg.elements.length > 1) {
|
|
||||||
this.core.context.logger.logWarn('意外的消息链长度', msg.elements.length, '将只解析第一个元素');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (firstElement.fileElement) {
|
if (firstElement.fileElement) {
|
||||||
return {
|
return {
|
||||||
oneofKind: 'file',
|
oneofKind: 'file',
|
||||||
@ -463,13 +461,17 @@ export class LaanaMessageUtils {
|
|||||||
oneofKind: 'forwardMsgRef',
|
oneofKind: 'forwardMsgRef',
|
||||||
forwardMsgRef: {
|
forwardMsgRef: {
|
||||||
refId: msg.msgId,
|
refId: msg.msgId,
|
||||||
// TODO: remove this field, since it is redundant to query forwarded msg with another refId
|
|
||||||
displayText: firstElement.multiForwardMsgElement.xmlContent,
|
displayText: firstElement.multiForwardMsgElement.xmlContent,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
this.core.context.logger.logWarn('未知的消息元素类型', firstElement.elementType);
|
this.core.context.logger.logWarn('未知的消息元素类型', firstElement.elementType);
|
||||||
return null; // TODO: add 'extended' message content type
|
return {
|
||||||
|
oneofKind: 'unknownMessage',
|
||||||
|
unknownMessage: {
|
||||||
|
rawContent: JSON.stringify(msg.elements),
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user