mirror of
https://github.com/AynaLivePlayer/blivedm-go.git
synced 2025-12-06 11:22:50 +08:00
update medal struct
This commit is contained in:
4
go.mod
4
go.mod
@@ -6,12 +6,16 @@ require (
|
||||
github.com/andybalholm/brotli v1.1.0
|
||||
github.com/gorilla/websocket v1.5.3
|
||||
github.com/sirupsen/logrus v1.9.3
|
||||
github.com/stretchr/testify v1.7.0
|
||||
github.com/tidwall/gjson v1.17.3
|
||||
google.golang.org/protobuf v1.34.2
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/tidwall/match v1.1.1 // indirect
|
||||
github.com/tidwall/pretty v1.2.1 // indirect
|
||||
golang.org/x/sys v0.25.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
|
||||
)
|
||||
|
||||
1
go.sum
1
go.sum
@@ -26,6 +26,7 @@ golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
|
||||
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
@@ -102,23 +102,43 @@ func (d *Danmaku) Parse(data []byte) {
|
||||
i2 := info.Get("2")
|
||||
i3 := info.Get("3")
|
||||
d.Content = info.Get("1").String() //弹幕内容
|
||||
// medal extra
|
||||
v2colors := []uint32{0, 0, 0, 0, 0}
|
||||
medalJson := info.Get("0.15.user.medal")
|
||||
v2colors[0] = utils.HexToUint32(medalJson.Get("v2_medal_color_level").String(), 1)
|
||||
v2colors[1] = utils.HexToUint32(medalJson.Get("v2_medal_color_start").String(), 1)
|
||||
v2colors[2] = utils.HexToUint32(medalJson.Get("v2_medal_color_end").String(), 1)
|
||||
v2colors[3] = utils.HexToUint32(medalJson.Get("v2_medal_color_border").String(), 1)
|
||||
v2colors[4] = utils.HexToUint32(medalJson.Get("v2_medal_color_text").String(), 1)
|
||||
|
||||
// if no medal, i3 is 0 length array
|
||||
|
||||
d.Sender = &User{ //用户信息
|
||||
Uid: int(i2.Get("0").Int()), //用户uid
|
||||
Uname: i2.Get("1").String(), //用户昵称
|
||||
UserLevel: i2.Get("16.0").Int(), //用户等级
|
||||
UserLevel: info.Get("16.0").Int(), //用户等级
|
||||
Admin: i2.Get("2").Bool(), //是否为管理者
|
||||
Urank: int(i2.Get("5").Int()),
|
||||
MobileVerify: i2.Get("6").Bool(), //是否绑定手机
|
||||
GuardLevel: int(info.Get("7").Int()), //舰队等级
|
||||
UserColor: utils.HexToUint32(i2.Get("7").String(), 1),
|
||||
//勋章信息
|
||||
Medal: &Medal{
|
||||
Level: int(i3.Get("0").Int()), //勋章等级
|
||||
Name: i3.Get("1").String(), //勋章名称
|
||||
UpName: i3.Get("2").String(), //勋章上主播昵称
|
||||
UpRoomId: int(i3.Get("3").Int()), //上主播房间id
|
||||
Color: int(i3.Get("4").Int()), //勋章颜色
|
||||
UpUid: int(i3.Get("12").Int()), //上主播uid
|
||||
Level: int(i3.Get("0").Int()), //勋章等级
|
||||
Name: i3.Get("1").String(), //勋章名称
|
||||
UpName: i3.Get("2").String(), //勋章上主播昵称
|
||||
UpRoomId: int(i3.Get("3").Int()), //上主播房间id
|
||||
Color: int(i3.Get("4").Int()), //勋章颜色
|
||||
ColorStart: int(i3.Get("7").Int()), //勋章开始颜色
|
||||
ColorEnd: int(i3.Get("8").Int()), //勋章结束颜色
|
||||
ColorBorder: int(i3.Get("9").Int()), //勋章边框颜色
|
||||
IsLight: i3.Get("11").Int() == 1, //勋章是否为点亮的
|
||||
UpUid: int(i3.Get("12").Int()), //上主播uid
|
||||
V2ColorLevel: v2colors[0],
|
||||
V2ColorStart: v2colors[1],
|
||||
V2ColorEnd: v2colors[2],
|
||||
V2ColorBorder: v2colors[3],
|
||||
V2ColorText: v2colors[4],
|
||||
},
|
||||
}
|
||||
d.Extra = ext
|
||||
|
||||
@@ -67,7 +67,7 @@ type Gift struct {
|
||||
SvgaBlock int `json:"svga_block"` // SVGA块
|
||||
TagImage string `json:"tag_image"` // 标签图片URL
|
||||
Tid string `json:"tid"` // TID
|
||||
Timestamp int `json:"timestamp"` // 时间戳
|
||||
Timestamp int64 `json:"timestamp"` // 时间戳
|
||||
TopList interface{} `json:"top_list"` // 顶级列表
|
||||
TotalCoin int `json:"total_coin"` // 总硬币数
|
||||
Uid int `json:"uid"` // 用户ID
|
||||
|
||||
@@ -52,7 +52,7 @@ type SuperChat struct {
|
||||
Time int `json:"time"` //剩余时间
|
||||
Token string `json:"token"`
|
||||
TransMark int `json:"trans_mark"`
|
||||
Ts int `json:"ts"`
|
||||
Ts int64 `json:"ts"`
|
||||
Uid int `json:"uid"` //用户ID
|
||||
UserInfo struct {
|
||||
Face string `json:"face"` //用户头像URL
|
||||
|
||||
@@ -9,13 +9,23 @@ type User struct {
|
||||
Medal *Medal
|
||||
GuardLevel int
|
||||
UserLevel int64
|
||||
UserColor uint32 // rgb
|
||||
}
|
||||
|
||||
type Medal struct {
|
||||
Name string
|
||||
Level int
|
||||
Color int
|
||||
UpRoomId int
|
||||
UpUid int
|
||||
UpName string
|
||||
Name string
|
||||
Level int
|
||||
Color int
|
||||
ColorStart int
|
||||
ColorEnd int
|
||||
ColorBorder int
|
||||
UpRoomId int
|
||||
UpUid int
|
||||
UpName string
|
||||
IsLight bool
|
||||
V2ColorLevel uint32 // rgba
|
||||
V2ColorStart uint32 // rgba
|
||||
V2ColorEnd uint32 // rgba
|
||||
V2ColorBorder uint32 // rgba
|
||||
V2ColorText uint32 // rgba
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package utils
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"strconv"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
@@ -28,3 +29,14 @@ func B64Decode(s string) ([]byte, error) {
|
||||
dst = dst[:n]
|
||||
return dst, nil
|
||||
}
|
||||
|
||||
func HexToUint32(s string, prefixLen int) uint32 {
|
||||
if len(s) <= prefixLen {
|
||||
return 0
|
||||
}
|
||||
parseInt, err := strconv.ParseInt(s[prefixLen:], 16, 64)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
return uint32(parseInt)
|
||||
}
|
||||
|
||||
11
utils/strconv_test.go
Normal file
11
utils/strconv_test.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestHexToUint32(t *testing.T) {
|
||||
require.Equal(t, uint32(0x919298CC), HexToUint32("#919298CC", 1))
|
||||
require.Equal(t, uint32(0), HexToUint32("", 1))
|
||||
}
|
||||
Reference in New Issue
Block a user