🐛 fix: anonymous danmu msg

This commit is contained in:
HarryWong
2023-07-08 10:22:49 +08:00
parent f56426ffa7
commit 8bc38ae586
6 changed files with 16 additions and 8 deletions

View File

@@ -33,7 +33,7 @@ import (
func main() {
log.SetLevel(log.DebugLevel)
c := client.NewClient("732")
c := client.NewClient("732", 194484313) // 732为房间号194484313为UID
//弹幕事件
c.OnDanmaku(func(danmaku *message.Danmaku) {
if danmaku.Type == message.EmoticonDanmaku {

View File

@@ -4,16 +4,18 @@ import (
"context"
"errors"
"fmt"
"strconv"
"time"
"github.com/Akegarasu/blivedm-go/api"
"github.com/Akegarasu/blivedm-go/packet"
"github.com/gorilla/websocket"
log "github.com/sirupsen/logrus"
"strconv"
"time"
)
type Client struct {
conn *websocket.Conn
uid int
roomID string
tempID string
token string
@@ -26,10 +28,11 @@ type Client struct {
}
// NewClient 创建一个新的弹幕 client
func NewClient(roomID string) *Client {
func NewClient(roomID string, uid int) *Client {
ctx, cancel := context.WithCancel(context.Background())
return &Client{
tempID: roomID,
uid: uid,
eventHandlers: &eventHandlers{},
customEventHandlers: &customEventHandlers{},
done: ctx.Done(),
@@ -157,7 +160,7 @@ func (c *Client) sendEnterPacket() error {
if err != nil {
return errors.New("error roomID")
}
pkt := packet.NewEnterPacket(0, rid, c.token)
pkt := packet.NewEnterPacket(c.uid, rid, c.token)
if err = c.conn.WriteMessage(websocket.BinaryMessage, pkt); err != nil {
return err
}

View File

@@ -2,6 +2,7 @@ package main
import (
"fmt"
"github.com/Akegarasu/blivedm-go/client"
_ "github.com/Akegarasu/blivedm-go/utils"
log "github.com/sirupsen/logrus"
@@ -9,12 +10,13 @@ import (
)
const roomId = "8792912"
const uid = 745493
var dumps = []string{"GUARD_BUY", "USER_TOAST_MSG"}
func main() {
log.SetLevel(log.DebugLevel)
c := client.NewClient(roomId)
c := client.NewClient(roomId, uid)
for _, v := range dumps {
vv := v
c.RegisterCustomEventHandler(vv, func(s string) {

View File

@@ -2,6 +2,7 @@ package main
import (
"fmt"
"github.com/Akegarasu/blivedm-go/api"
"github.com/Akegarasu/blivedm-go/client"
"github.com/Akegarasu/blivedm-go/message"
@@ -12,7 +13,7 @@ import (
func main() {
log.SetLevel(log.DebugLevel)
c := client.NewClient("732")
c := client.NewClient("732", 194484313)
//弹幕事件
c.OnDanmaku(func(danmaku *message.Danmaku) {
if danmaku.Type == message.EmoticonDanmaku {

1
go.mod
View File

@@ -7,4 +7,5 @@ require (
github.com/gorilla/websocket v1.4.2
github.com/sirupsen/logrus v1.8.1
github.com/tidwall/gjson v1.13.0
golang.org/x/sys v0.0.0-20210423082822-04245dca01da // indirect
)

3
go.sum
View File

@@ -16,5 +16,6 @@ github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da h1:b3NXsE2LusjYGGjL5bxEVZZORm/YEFFrWFjR8eFrw/c=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=