feat: 礼物协议更新(+bilibili)

main
NorthLan 3 years ago
parent 617273fb86
commit ac822ff069

@ -60,6 +60,11 @@ type SendGift struct {
Uname string `json:"uname"` // 用户名
}
const (
CoinTypeGold = "gold"
CoinTypeSilver = "silver"
)
type SendGiftHandler struct {
producer *kafka.Producer
liveRoomId int64
@ -96,9 +101,19 @@ func (h *SendGiftHandler) HandlerMessage(data []byte) {
GiftId: baseMsg.Data.GiftId,
Num: baseMsg.Data.Num,
GiftName: baseMsg.Data.GiftName,
TotalCoin: int64(baseMsg.Data.TotalCoin),
SendTime: int64(baseMsg.Data.Timestamp),
Price: int64(baseMsg.Data.Price),
IsPaid: h.isPaid(baseMsg.Data.CoinType),
}
_ = h.producer.SendMessageAsync(dmMsg, strconv.FormatInt(dmMsg.Uid, 10))
}
func (h *SendGiftHandler) isPaid(coinType string) bool {
if coinType == CoinTypeGold {
return true
}
if coinType == CoinTypeSilver {
return false
}
return false
}

@ -0,0 +1,28 @@
Bilibili:
Enabled: true
Url: wss://broadcastlv.chat.bilibili.com:2245/sub
GetRoomUrl: https://api.live.bilibili.com/room/v1/Room/room_init?id=
HeartbeatInterval: 30
UserId: 111222
RoomId: 8722013
Log:
Console:
Level: info
Format: console
File:
Enabled: true
Level: info
Format: json
Path: ./logs
Filename: live-gateway.log
FileMaxSize: 10 # 10mb
FileMaxBackups: 30 #
MaxAge: 7 # 保留7天
Compress: true # 压缩日志
Kafka:
Danmaku:
Addr: ["127.0.0.1:9093"]
Topic: "danmaku-dev"
Gift:
Addr: [ "127.0.0.1:9093" ]
Topic: "gift-dev"

@ -171,8 +171,8 @@ type MqGift struct {
GiftId int64 `protobuf:"varint,5,opt,name=giftId,proto3" json:"giftId,omitempty"`
Num int64 `protobuf:"varint,6,opt,name=num,proto3" json:"num,omitempty"`
GiftName string `protobuf:"bytes,7,opt,name=giftName,proto3" json:"giftName,omitempty"`
TotalCoin int64 `protobuf:"varint,8,opt,name=totalCoin,proto3" json:"totalCoin,omitempty"`
SendTime int64 `protobuf:"varint,9,opt,name=sendTime,proto3" json:"sendTime,omitempty"`
Price int64 `protobuf:"varint,8,opt,name=price,proto3" json:"price,omitempty"`
IsPaid bool `protobuf:"varint,9,opt,name=isPaid,proto3" json:"isPaid,omitempty"`
}
func (x *MqGift) Reset() {
@ -256,18 +256,18 @@ func (x *MqGift) GetGiftName() string {
return ""
}
func (x *MqGift) GetTotalCoin() int64 {
func (x *MqGift) GetPrice() int64 {
if x != nil {
return x.TotalCoin
return x.Price
}
return 0
}
func (x *MqGift) GetSendTime() int64 {
func (x *MqGift) GetIsPaid() bool {
if x != nil {
return x.SendTime
return x.IsPaid
}
return 0
return false
}
var File_mq_proto protoreflect.FileDescriptor
@ -284,7 +284,7 @@ var file_mq_proto_rawDesc = []byte{
0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28,
0x09, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65,
0x6e, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x65,
0x6e, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x22, 0xec, 0x01, 0x0a, 0x06, 0x4d, 0x71, 0x47, 0x69, 0x66,
0x6e, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x22, 0xe0, 0x01, 0x0a, 0x06, 0x4d, 0x71, 0x47, 0x69, 0x66,
0x74, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x18, 0x01, 0x20,
0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x12, 0x1e, 0x0a,
0x0a, 0x6c, 0x69, 0x76, 0x65, 0x52, 0x6f, 0x6f, 0x6d, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28,
@ -295,16 +295,15 @@ var file_mq_proto_rawDesc = []byte{
0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x67, 0x69, 0x66, 0x74, 0x49, 0x64, 0x12, 0x10, 0x0a,
0x03, 0x6e, 0x75, 0x6d, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x6e, 0x75, 0x6d, 0x12,
0x1a, 0x0a, 0x08, 0x67, 0x69, 0x66, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28,
0x09, 0x52, 0x08, 0x67, 0x69, 0x66, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x74,
0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x69, 0x6e, 0x18, 0x08, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09,
0x74, 0x6f, 0x74, 0x61, 0x6c, 0x43, 0x6f, 0x69, 0x6e, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x6e,
0x64, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x65, 0x6e,
0x64, 0x54, 0x69, 0x6d, 0x65, 0x2a, 0x39, 0x0a, 0x08, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72,
0x6d, 0x12, 0x0c, 0x0a, 0x08, 0x62, 0x69, 0x6c, 0x69, 0x62, 0x69, 0x6c, 0x69, 0x10, 0x00, 0x12,
0x08, 0x0a, 0x04, 0x68, 0x75, 0x79, 0x61, 0x10, 0x01, 0x12, 0x09, 0x0a, 0x05, 0x64, 0x6f, 0x75,
0x79, 0x75, 0x10, 0x02, 0x12, 0x0a, 0x0a, 0x06, 0x64, 0x6f, 0x75, 0x79, 0x69, 0x6e, 0x10, 0x03,
0x42, 0x07, 0x5a, 0x05, 0x2f, 0x70, 0x62, 0x4d, 0x71, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x33,
0x09, 0x52, 0x08, 0x67, 0x69, 0x66, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x70,
0x72, 0x69, 0x63, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x70, 0x72, 0x69, 0x63,
0x65, 0x12, 0x16, 0x0a, 0x06, 0x69, 0x73, 0x50, 0x61, 0x69, 0x64, 0x18, 0x09, 0x20, 0x01, 0x28,
0x08, 0x52, 0x06, 0x69, 0x73, 0x50, 0x61, 0x69, 0x64, 0x2a, 0x39, 0x0a, 0x08, 0x50, 0x6c, 0x61,
0x74, 0x66, 0x6f, 0x72, 0x6d, 0x12, 0x0c, 0x0a, 0x08, 0x62, 0x69, 0x6c, 0x69, 0x62, 0x69, 0x6c,
0x69, 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, 0x68, 0x75, 0x79, 0x61, 0x10, 0x01, 0x12, 0x09, 0x0a,
0x05, 0x64, 0x6f, 0x75, 0x79, 0x75, 0x10, 0x02, 0x12, 0x0a, 0x0a, 0x06, 0x64, 0x6f, 0x75, 0x79,
0x69, 0x6e, 0x10, 0x03, 0x42, 0x07, 0x5a, 0x05, 0x2f, 0x70, 0x62, 0x4d, 0x71, 0x62, 0x06, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (

@ -28,6 +28,6 @@ message MqGift {
int64 giftId = 5;
int64 num = 6;
string giftName = 7;
int64 totalCoin = 8;
int64 sendTime = 9;
int64 price = 8;
bool isPaid = 9;
}
Loading…
Cancel
Save