forked from Akegarasu/blivedm-go
/
main.go
74 lines (69 loc) · 1.91 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"fmt"
"github.com/AceXiamo/blivedm-go/api"
"github.com/AceXiamo/blivedm-go/client"
"github.com/AceXiamo/blivedm-go/message"
_ "github.com/AceXiamo/blivedm-go/utils"
log "github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
)
func main() {
log.SetLevel(log.DebugLevel)
c := client.NewClient(6)
c.SetCookie("this is a example cookie.")
//弹幕事件
c.OnDanmaku(func(danmaku *message.Danmaku) {
if danmaku.Type == message.EmoticonDanmaku {
fmt.Printf("[弹幕表情] %s:表情URL: %s\n", danmaku.Sender.Uname, danmaku.Emoticon.Url)
} else {
fmt.Printf("[弹幕] %s:%s\n", danmaku.Sender.Uname, danmaku.Content)
}
})
// 醒目留言事件
c.OnSuperChat(func(superChat *message.SuperChat) {
fmt.Printf("[SC|%d元] %s: %s\n", superChat.Price, superChat.UserInfo.Uname, superChat.Message)
})
// 礼物事件
c.OnGift(func(gift *message.Gift) {
if gift.CoinType == "gold" {
fmt.Printf("[礼物] %s 的 %s %d 个 共%.2f元\n", gift.Uname, gift.GiftName, gift.Num, float64(gift.Num*gift.Price)/1000)
}
})
// 上舰事件
c.OnGuardBuy(func(guardBuy *message.GuardBuy) {
fmt.Printf("[大航海] %s 开通了 %d 等级的大航海,金额 %d 元\n", guardBuy.Username, guardBuy.GuardLevel, guardBuy.Price/1000)
})
// 监听自定义事件
c.RegisterCustomEventHandler("STOP_LIVE_ROOM_LIST", func(s string) {
data := gjson.Get(s, "data").String()
fmt.Printf("STOP_LIVE_ROOM_LIST: %s\n", data)
})
err := c.Start()
if err != nil {
log.Fatal(err)
}
log.Println("started")
// 需要自行阻塞什么方法都可以
select {}
}
func sendDanmaku() error {
dmReq := &api.DanmakuRequest{
Msg: "official_13",
RoomID: "732",
Bubble: "0",
Color: "16777215",
FontSize: "25",
Mode: "1",
DmType: "1",
}
d, err := api.SendDanmaku(dmReq, &api.BiliVerify{
Csrf: "",
SessData: "",
})
if err != nil {
return err
}
fmt.Println(d)
return nil
}