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
{message?.data?.em}
; } 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 (
[{message.current}]{nick}{nick ? ': ' : ''}{content}
); }