🎉 message

This commit is contained in:
Akiba
2022-01-19 21:29:27 +08:00
parent 4d36a29694
commit c78040b47d
7 changed files with 356 additions and 0 deletions

52
message/danmu.go Normal file
View File

@@ -0,0 +1,52 @@
package message
import (
"bytes"
"encoding/json"
log "github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
)
type Danmuku struct {
Sender User
Content string
Extra Extra
}
type Extra struct {
SendFromMe bool `json:"send_from_me"`
Mode int `json:"mode"`
Color int `json:"color"`
DmType int `json:"dm_type"`
FontSize int `json:"font_size"`
PlayerMode int `json:"player_mode"`
ShowPlayerType int `json:"show_player_type"`
Content string `json:"content"`
UserHash string `json:"user_hash"`
EmoticonUnique string `json:"emoticon_unique"`
Direction int `json:"direction"`
PkDirection int `json:"pk_direction"`
SpaceType string `json:"space_type"`
SpaceUrl string `json:"space_url"`
}
func (d *Danmuku) Parse(data []byte) {
sb := bytes.NewBuffer(data).String()
info := gjson.Get(sb, "info")
d.Content = info.Get("1").String()
d.Sender = User{
Uid: int(info.Get("2.0").Int()),
Uname: info.Get("2.1").String(),
Medal: Medal{
Name: info.Get("3.1").String(),
Level: int(info.Get("3.0").Int()),
Up: info.Get("3.2").String(),
},
}
ext := new(Extra)
err := json.Unmarshal([]byte(info.Get("0.15.extra").String()), ext)
if err != nil {
log.Error("parse danmuku extra failed")
}
d.Extra = *ext
}

120
message/gift.go Normal file
View File

@@ -0,0 +1,120 @@
package message
import (
"bytes"
"encoding/json"
log "github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
)
type Gift struct {
Action string `json:"action"`
BatchComboId string `json:"batch_combo_id"`
BatchComboSend interface{} `json:"batch_combo_send"`
BeatId string `json:"beatId"`
BizSource string `json:"biz_source"`
BlindGift interface{} `json:"blind_gift"`
BroadcastId int `json:"broadcast_id"`
CoinType string `json:"coin_type"`
ComboResourcesId int `json:"combo_resources_id"`
ComboSend interface{} `json:"combo_send"`
ComboStayTime int `json:"combo_stay_time"`
ComboTotalCoin int `json:"combo_total_coin"`
CritProb int `json:"crit_prob"`
Demarcation int `json:"demarcation"`
DiscountPrice int `json:"discount_price"`
Dmscore int `json:"dmscore"`
Draw int `json:"draw"`
Effect int `json:"effect"`
EffectBlock int `json:"effect_block"`
Face string `json:"face"`
FloatScResourceId int `json:"float_sc_resource_id"`
GiftId int `json:"giftId"`
GiftName string `json:"giftName"`
GiftType int `json:"giftType"`
Gold int `json:"gold"`
GuardLevel int `json:"guard_level"`
IsFirst bool `json:"is_first"`
IsSpecialBatch int `json:"is_special_batch"`
Magnification float64 `json:"magnification"`
MedalInfo struct {
AnchorRoomid int `json:"anchor_roomid"`
AnchorUname string `json:"anchor_uname"`
GuardLevel int `json:"guard_level"`
IconId int `json:"icon_id"`
IsLighted int `json:"is_lighted"`
MedalColor int `json:"medal_color"`
MedalColorBorder int `json:"medal_color_border"`
MedalColorEnd int `json:"medal_color_end"`
MedalColorStart int `json:"medal_color_start"`
MedalLevel int `json:"medal_level"`
MedalName string `json:"medal_name"`
Special string `json:"special"`
TargetId int `json:"target_id"`
} `json:"medal_info"`
NameColor string `json:"name_color"`
Num int `json:"num"`
OriginalGiftName string `json:"original_gift_name"`
Price int `json:"price"`
Rcost int `json:"rcost"`
Remain int `json:"remain"`
Rnd string `json:"rnd"`
SendMaster interface{} `json:"send_master"`
Silver int `json:"silver"`
Super int `json:"super"`
SuperBatchGiftNum int `json:"super_batch_gift_num"`
SuperGiftNum int `json:"super_gift_num"`
SvgaBlock int `json:"svga_block"`
TagImage string `json:"tag_image"`
Tid string `json:"tid"`
Timestamp int `json:"timestamp"`
TopList interface{} `json:"top_list"`
TotalCoin int `json:"total_coin"`
Uid int `json:"uid"`
Uname string `json:"uname"`
}
type ComboSend struct {
Action string `json:"action"`
BatchComboId string `json:"batch_combo_id"`
BatchComboNum int `json:"batch_combo_num"`
ComboId string `json:"combo_id"`
ComboNum int `json:"combo_num"`
ComboTotalCoin int `json:"combo_total_coin"`
Dmscore int `json:"dmscore"`
GiftId int `json:"gift_id"`
GiftName string `json:"gift_name"`
GiftNum int `json:"gift_num"`
IsShow int `json:"is_show"`
MedalInfo struct {
AnchorRoomid int `json:"anchor_roomid"`
AnchorUname string `json:"anchor_uname"`
GuardLevel int `json:"guard_level"`
IconId int `json:"icon_id"`
IsLighted int `json:"is_lighted"`
MedalColor int `json:"medal_color"`
MedalColorBorder int `json:"medal_color_border"`
MedalColorEnd int `json:"medal_color_end"`
MedalColorStart int `json:"medal_color_start"`
MedalLevel int `json:"medal_level"`
MedalName string `json:"medal_name"`
Special string `json:"special"`
TargetId int `json:"target_id"`
} `json:"medal_info"`
NameColor string `json:"name_color"`
RUname string `json:"r_uname"`
Ruid int `json:"ruid"`
SendMaster interface{} `json:"send_master"`
TotalNum int `json:"total_num"`
Uid int `json:"uid"`
Uname string `json:"uname"`
}
func (g *Gift) Parse(data []byte) {
sb := bytes.NewBuffer(data).String()
sd := gjson.Get(sb, "data").String()
err := json.Unmarshal([]byte(sd), g)
if err != nil {
log.Error("parse Gift failed")
}
}

29
message/guard.go Normal file
View File

@@ -0,0 +1,29 @@
package message
import (
"bytes"
"encoding/json"
log "github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
)
type GuardBuy struct {
Uid int `json:"uid"`
Username string `json:"username"`
GuardLevel int `json:"guard_level"`
Num int `json:"num"`
Price int `json:"price"`
GiftId int `json:"gift_id"`
GiftName string `json:"gift_name"`
StartTime int `json:"start_time"`
EndTime int `json:"end_time"`
}
func (g *GuardBuy) Parse(data []byte) {
sb := bytes.NewBuffer(data).String()
sd := gjson.Get(sb, "data").String()
err := json.Unmarshal([]byte(sd), g)
if err != nil {
log.Error("parse GuardBuy failed")
}
}

33
message/live.go Normal file
View File

@@ -0,0 +1,33 @@
package message
import (
"encoding/json"
log "github.com/sirupsen/logrus"
)
type StopLiveRoomList struct {
RoomIdList []int `json:"room_id_list"`
}
type Live struct {
Cmd string `json:"cmd"`
LiveKey string `json:"live_key"`
VoiceBackground string `json:"voice_background"`
SubSessionKey string `json:"sub_session_key"`
LivePlatform string `json:"live_platform"`
LiveModel int `json:"live_model"`
LiveTime int `json:"live_time"`
Roomid int `json:"roomid"`
}
type Preparing struct {
Cmd string `json:"cmd"`
Roomid string `json:"roomid"`
}
func (l *Live) Parse(data []byte) {
err := json.Unmarshal(data, l)
if err != nil {
log.Error("parse live failed")
}
}

81
message/superchat.go Normal file
View File

@@ -0,0 +1,81 @@
package message
import (
"bytes"
"encoding/json"
log "github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
)
// SuperChat
// message_jpn: 消息日文翻译目前只出现在SUPER_CHAT_MESSAGE_JPN
// id_: str消息ID删除时用
type SuperChat struct {
BackgroundBottomColor string `json:"background_bottom_color"` //底部背景色
BackgroundColor string `json:"background_color"` //背景色
BackgroundColorEnd string `json:"background_color_end"`
BackgroundColorStart string `json:"background_color_start"`
BackgroundIcon string `json:"background_icon"` //背景图标
BackgroundImage string `json:"background_image"` //背景图
BackgroundPriceColor string `json:"background_price_color"` //背景价格颜色
ColorPoint float64 `json:"color_point"`
Dmscore int `json:"dmscore"`
EndTime int `json:"end_time"` //结束时间戳
Gift struct {
GiftId int `json:"gift_id"` //礼物ID
GiftName string `json:"gift_name"` //礼物名
Num int `json:"num"`
} `json:"gift"`
Id int `json:"id"`
IsRanked int `json:"is_ranked"`
IsSendAudit int `json:"is_send_audit"`
MedalInfo struct {
AnchorRoomid int `json:"anchor_roomid"`
AnchorUname string `json:"anchor_uname"`
GuardLevel int `json:"guard_level"` // 舰队等级0:非舰队1:总督2:提督3:舰长
IconId int `json:"icon_id"`
IsLighted int `json:"is_lighted"`
MedalColor string `json:"medal_color"`
MedalColorBorder int `json:"medal_color_border"`
MedalColorEnd int `json:"medal_color_end"`
MedalColorStart int `json:"medal_color_start"`
MedalLevel int `json:"medal_level"`
MedalName string `json:"medal_name"`
Special string `json:"special"`
TargetId int `json:"target_id"`
} `json:"medal_info"`
Message string `json:"message"` // 消息
MessageFontColor string `json:"message_font_color"`
MessageTrans string `json:"message_trans"`
Price int `json:"price"` // 价格(人民币)
Rate int `json:"rate"`
StartTime int `json:"start_time"` // 开始时间戳
Time int `json:"time"` //剩余时间
Token string `json:"token"`
TransMark int `json:"trans_mark"`
Ts int `json:"ts"`
Uid int `json:"uid"` //用户ID
UserInfo struct {
Face string `json:"face"` //用户头像URL
FaceFrame string `json:"face_frame"`
GuardLevel int `json:"guard_level"`
IsMainVip int `json:"is_main_vip"`
IsSvip int `json:"is_svip"`
IsVip int `json:"is_vip"`
LevelColor string `json:"level_color"`
Manager int `json:"manager"`
NameColor string `json:"name_color"`
Title string `json:"title"`
Uname string `json:"uname"` //用户名
UserLevel int `json:"user_level"` //用户等级
} `json:"user_info"`
}
func (s *SuperChat) Parse(data []byte) {
sb := bytes.NewBuffer(data).String()
sd := gjson.Get(sb, "data").String()
err := json.Unmarshal([]byte(sd), s)
if err != nil {
log.Error("parse superchat failed")
}
}

13
message/user.go Normal file
View File

@@ -0,0 +1,13 @@
package message
type User struct {
Uid int
Uname string
Medal Medal
}
type Medal struct {
Name string
Level int
Up string
}

28
message/utils.go Normal file
View File

@@ -0,0 +1,28 @@
package message
// WidgetBanner
// TODO: widget_list的code不定
type WidgetBanner struct {
Timestamp int `json:"timestamp"`
WidgetList struct {
Field1 struct {
Id int `json:"id"`
Title string `json:"title"`
Cover string `json:"cover"`
WebCover string `json:"web_cover"`
TipText string `json:"tip_text"`
TipTextColor string `json:"tip_text_color"`
TipBottomColor string `json:"tip_bottom_color"`
JumpUrl string `json:"jump_url"`
Url string `json:"url"`
StayTime int `json:"stay_time"`
Site int `json:"site"`
PlatformIn []string `json:"platform_in"`
Type int `json:"type"`
BandId int `json:"band_id"`
SubKey string `json:"sub_key"`
SubData string `json:"sub_data"`
IsAdd bool `json:"is_add"`
} `json:"58"`
} `json:"widget_list"`
}