danmu-sim/app/danmu/message.tsx

55 lines
1.6 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import dayjs from 'dayjs';
export default function MessageDispatcher({ message }: { message: any }) {
const messageType = message?.units?.[0]?.type;
let nick = "";
let content = "[暂不支持该类型消息]";
let fortuneLv = 0;
let text = '';
let productId = '';
let amount = 0;
if (message?.type === "sauth_ret") {
if (message?.data?.em !== "ok") {
return <div>{message?.data?.em}</div>;
} else {
return null;
}
}
switch (messageType) {
case "Message":
nick = message?.nick;
content = message?.units?.[0]?.["Msg.Message.data"]?.text;
break;
case "EnterRoom":
text = message?.units?.[0]?.["Set.EnterRoom.data"]?.text;
fortuneLv = message?.units?.[0]?.["Set.EnterRoom.data"]?.fortune_lv;
content = `有新人:${text} lv: ${fortuneLv}`;
break;
case "Version":
// TODO 解析
return null
case "BiliBili":
nick = message?.nick;
text = message?.['units']?.[0]?.['Pay.BiliBili.data']?.['text']
break;
case "GiftV3":
nick = message?.nick;
text = message?.['units']?.[0]?.['GiftV3.giftV3']?.['text']
productId = message?.['units']?.[0]?.['GiftV3.giftV3']?.['productId']
amount = message?.['units']?.[0]?.['GiftV3.giftV3']?.['weight']
content = `${nick} 送出礼物,内容为: ${text}产品ID为: ${productId}, 价值:${amount}`
nick = ''
break;
default:
console.log("debug....", messageType, message);
break;
}
return (
<div className="p-1 text-xs">
[{message.current}]{nick}{nick ? ': ' : ''}{content}
</div>
);
}