You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.3 KiB
Go

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package msg_handler
import (
"encoding/json"
"git.noahlan.cn/northlan/ntools-go/kafka"
"live-gateway/config"
"live-gateway/pb/mq"
pbVars "live-gateway/pb/vars"
kfk "live-gateway/pkg/kafka"
"strconv"
)
type RedPocket struct {
LotId int64 `json:"lot_id"` // 本次抽奖ID
Uname string `json:"uname"` // UName
UID int64 `json:"uid"` // UID
StartTime int64 `json:"start_time"` // 红包开始时间
CurrentTime int64 `json:"current_time"` // 当前时间
WaitNum int64 `json:"wait_num"` // 不清楚???
Action string `json:"action"`
GiftName string `json:"gift_name"` // 名
GiftID int64 `json:"gift_id"` // id - 13000
Num int64 `json:"num"` // 数量
Price int64 `json:"price"` // 电池数
MedalInfo FansMedal `json:"medal_info"`
}
type RedPocketHandler struct {
producer *kafka.Producer
liveRoomId int64
}
func NewRedPocketHandler(liveRoomId int64) *RedPocketHandler {
cfg := config.Config.Kafka.Gift
return &RedPocketHandler{
producer: kafka.NewKafkaProducer(kfk.DefaultProducerConfig, cfg.Addr, cfg.Topic),
liveRoomId: liveRoomId,
}
}
func (h *RedPocketHandler) CMD() string {
return "POPULARITY_RED_POCKET_NEW"
}
func (h *RedPocketHandler) HandlerMessage(data []byte) {
var baseMsg struct {
CMD string `json:"cmd"`
Data *RedPocket `json:"data"`
}
if err := json.Unmarshal(data, &baseMsg); err != nil {
return
}
//logger.SLog.Infof("%s %s礼物 %s x%d", baseMsg.Data.Uname, baseMsg.Data.Action, baseMsg.Data.GiftName, baseMsg.Data.Num)
dmMsg := &pbMq.MqGift{
Platform: pbVars.Platform_name[int32(pbVars.Platform_Bilibili)],
LiveRoomId: h.liveRoomId,
MsgId: "",
Timestamp: baseMsg.Data.CurrentTime,
Uid: baseMsg.Data.UID,
Uname: baseMsg.Data.Uname,
Avatar: "",
GiftId: baseMsg.Data.GiftID,
GiftName: baseMsg.Data.GiftName,
GiftNum: baseMsg.Data.Num,
Price: baseMsg.Data.Price * 100, // 红包的price是电池转换为金瓜子
IsPaid: true,
Type: pbMq.MqGift_RED_PACK,
PackGift: nil,
FansMedalWearingStatus: baseMsg.Data.MedalInfo.AnchorRoomId == h.liveRoomId,
FansMedalName: baseMsg.Data.MedalInfo.MedalName,
FansMedalLevel: baseMsg.Data.MedalInfo.MedalLevel,
}
_ = h.producer.SendMessageAsync(dmMsg, strconv.FormatInt(dmMsg.Uid, 10))
}