From ac822ff069b751f8a81614b25275b850baca67a1 Mon Sep 17 00:00:00 2001 From: NorthLan <6995syu@163.com> Date: Mon, 16 May 2022 10:00:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=A4=BC=E7=89=A9=E5=8D=8F=E8=AE=AE?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=EF=BC=88+bilibili=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bilibili/msg_handler/send_gift.go | 19 +++++++++++++++-- config-dev.yml | 28 +++++++++++++++++++++++++ pb/mq.pb.go | 35 +++++++++++++++---------------- pb/mq.proto | 4 ++-- 4 files changed, 64 insertions(+), 22 deletions(-) create mode 100644 config-dev.yml diff --git a/bilibili/msg_handler/send_gift.go b/bilibili/msg_handler/send_gift.go index 9836c6b..504a5a5 100644 --- a/bilibili/msg_handler/send_gift.go +++ b/bilibili/msg_handler/send_gift.go @@ -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 +} diff --git a/config-dev.yml b/config-dev.yml new file mode 100644 index 0000000..3e50bc6 --- /dev/null +++ b/config-dev.yml @@ -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" diff --git a/pb/mq.pb.go b/pb/mq.pb.go index 879ca55..619471a 100644 --- a/pb/mq.pb.go +++ b/pb/mq.pb.go @@ -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 ( diff --git a/pb/mq.proto b/pb/mq.proto index f5a1b1a..ca33987 100644 --- a/pb/mq.proto +++ b/pb/mq.proto @@ -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; } \ No newline at end of file