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.

99 lines
3.7 KiB
Go

package msg_handler
import (
"encoding/json"
"git.noahlan.cn/northlan/ntools-go/kafka"
"live-gateway/config"
"live-gateway/pb"
kfk "live-gateway/pkg/kafka"
"strconv"
)
// GiftOfficial 礼物结构 官方
type GiftOfficial struct {
RoomId int64 `json:"room_id"` // 房间号
Uid int64 `json:"uid"` // 送礼用户UID
Uname string `json:"uname"` // 送礼用户昵称
Uface string `json:"uface"` // 送礼用户头像
GiftId int64 `json:"gift_id"` // 道具id(盲盒:爆出道具id)
GiftName string `json:"gift_name"` // 道具名(盲盒:爆出道具名)
GiftNum int64 `json:"gift_num"` // 赠送道具数量
Price int64 `json:"price"` // 支付金额(1000 = 1元 = 10电池),盲盒:爆出道具的价值
Paid bool `json:"paid"` // 是否是付费道具
FansMedalLevel int64 `json:"fans_medal_level"` // 实际送礼人的勋章信息
FansMedalName string `json:"fans_medal_name"` // 粉丝勋章名
FansMedalWearingStatus bool `json:"fans_medal_wearing_status"` // 当前佩戴的粉丝勋章佩戴状态
GuardLevel int64 `json:"guard_level"` // 大航海等级
Timestamp int64 `json:"timestamp"` // 收礼时间秒级时间戳
AnchorInfo anchorInfo `json:"anchor_info"` // 主播信息
MsgId string `json:"msg_id"` // 消息唯一id
}
type anchorInfo struct {
Uid int64 `json:"uid"` // 收礼主播uid
Uname string `json:"uname"` // 收礼主播昵称
Uface string `json:"uface"` // 收礼主播头像
}
type GiftOfficialHandler struct {
producer *kafka.Producer
liveRoomId int64
}
func NewGiftOfficialHandler(liveRoomId int64) *GiftOfficialHandler {
cfg := config.Config.Kafka.Gift
return &GiftOfficialHandler{
producer: kafka.NewKafkaProducer(kfk.DefaultProducerConfig, cfg.Addr, cfg.Topic),
liveRoomId: liveRoomId,
}
}
func (h *GiftOfficialHandler) CMD() string {
return "LIVE_OPEN_PLATFORM_SEND_GIFT"
}
func (h *GiftOfficialHandler) HandlerMessage(data []byte) {
var baseMsg struct {
CMD string `json:"cmd"`
Data *GiftOfficial `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)
gift := baseMsg.Data
dmMsg := &pbMq.MqGift{
Platform: pbMq.Platform_name[int32(pbMq.Platform_bilibili)],
LiveRoomId: h.liveRoomId,
Uid: gift.Uid,
Uname: gift.Uname,
Avatar: gift.Uface,
GiftId: gift.GiftId,
GiftName: gift.GiftName,
GiftNum: gift.GiftNum,
Price: gift.Price,
IsPaid: gift.Paid,
MsgId: gift.MsgId,
Timestamp: gift.Timestamp,
NobilityLevel: gift.GuardLevel,
FansMedalWearingStatus: gift.FansMedalWearingStatus,
FansMedalName: gift.FansMedalName,
FansMedalLevel: gift.FansMedalLevel,
}
_ = h.producer.SendMessageAsync(dmMsg, strconv.FormatInt(dmMsg.Uid, 10))
}
func (h *GiftOfficialHandler) isPaid(coinType string) bool {
if coinType == CoinTypeGold {
return true
}
if coinType == CoinTypeSilver {
return false
}
return false
}