2024-04-07 03:23:34 +08:00
|
|
|
|
import dayjs from 'dayjs';
|
|
|
|
|
|
2024-04-07 01:53:46 +08:00
|
|
|
|
export default function MessageDispatcher({ message }: { message: any }) {
|
2024-04-07 03:23:34 +08:00
|
|
|
|
const messageType = message?.units?.[0]?.type;
|
|
|
|
|
let nick = "";
|
|
|
|
|
let content = "[暂不支持该类型消息]";
|
|
|
|
|
let fortuneLv = 0;
|
|
|
|
|
let text = '';
|
|
|
|
|
let productId = '';
|
|
|
|
|
let amount = 0;
|
2024-04-07 01:53:46 +08:00
|
|
|
|
|
2024-04-07 03:23:34 +08:00
|
|
|
|
if (message?.type === "sauth_ret") {
|
|
|
|
|
if (message?.data?.em !== "ok") {
|
|
|
|
|
return <div>{message?.data?.em}</div>;
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2024-04-07 01:53:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-07 03:23:34 +08:00
|
|
|
|
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 "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;
|
2024-04-07 01:53:46 +08:00
|
|
|
|
}
|
|
|
|
|
return (
|
2024-04-07 03:23:34 +08:00
|
|
|
|
<div className="p-1 text-xs">
|
|
|
|
|
[{message.current}]{nick}{nick ? ': ' : ''}{content}
|
2024-04-07 01:53:46 +08:00
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|