Commit f713f093 by 杨铁龙

parserMessage 用try catch

parent a6262f4c
Showing with 26 additions and 22 deletions
...@@ -17,28 +17,32 @@ const mapping = new Map<MessageType, string>([ ...@@ -17,28 +17,32 @@ const mapping = new Map<MessageType, string>([
]) ])
export function parserMessage(type: MessageType, rawMsg: string) { export function parserMessage(type: MessageType, rawMsg: string) {
if (!type) return ""; try {
if (!rawMsg) return ""; if (!type) return "";
if (type === MessageType.Text) { if (!rawMsg) return "";
const msg = JSON.parse(rawMsg); if (type === MessageType.Text) {
return msg.text; const msg = JSON.parse(rawMsg);
} return msg.text;
if (type === MessageType.Action) {
const msg = JSON.parse(rawMsg);
return msg.text;
}
if (type === MessageType.Notify) {
return rawMsg;
}
if (type === MessageType.Card) {
const p = JSON.parse(rawMsg) as CardMessage;
if (p && p.title) {
return p.title || '通知';
} }
if (type === MessageType.Action) {
const msg = JSON.parse(rawMsg);
return msg.text;
}
if (type === MessageType.Notify) {
return rawMsg;
}
if (type === MessageType.Card) {
const p = JSON.parse(rawMsg) as CardMessage;
if (p && p.title) {
return p.title || '通知';
}
}
const t = mapping.get(type)
if (t) {
return `[${t}]`;
}
return `[系统自动回复]`;
} catch {
return ""
} }
const t = mapping.get(type)
if (t) {
return `[${t}]`;
}
return `[系统自动回复]`;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment