import (
"encoding/json"
"errors"
+ "flag"
"io"
"time"
K_v syncmap.Map //配置文件
Log *log.Log_interface //日志
Danmu_Main_mq *mq.Msgq //消息
- ReqPool *idpool.Idpool // 请求池
+ ReqPool *idpool.Idpool //请求池
}
func (t *Common) init() Common {
t.Danmu_Main_mq = mq.New(200)
+ var (
+ ckv = flag.String("ckv", "", "自定义配置KV文件,将会覆盖config_K_v配置")
+ roomIdP = flag.Int("r", 0, "roomid")
+ )
+ flag.Parse()
+ t.Roomid = *roomIdP
+
if bb, err := file.New("config/config_K_v.json", 0, true).ReadAll(100, 1<<16); err != nil {
if errors.Is(err, io.EOF) {
var data map[string]interface{}
}
}
+ if t.K_v.Len() == 0 {
+ panic("未能加载配置")
+ }
+
+ if *ckv != "" {
+ if bb, err := file.New(*ckv, 0, true).ReadAll(100, 1<<16); err != nil {
+ if errors.Is(err, io.EOF) {
+ var data map[string]interface{}
+ json.Unmarshal(bb, &data)
+ for k, v := range data {
+ t.K_v.Store(k, v)
+ }
+ } else {
+ panic(err)
+ }
+ }
+ }
+
go func() {
for {
v, ok := t.K_v.LoadV("几秒后重载").(float64)
### 说明
本项目使用github action自动构建,构建过程详见[yml](https://github.com/qydysky/bili_danmu/blob/master/.github/workflows/go.yml)
+#### 自定义config_K_v.json
+当启动时使用`-ckv 路径`,将从此路径加载config_K_v.json并覆盖默认config_K_v.json中的配置项。使用此配置,可以在有新配置项时,默认使用新配置项而保持之前其他的配置。
+
#### 表情发送
当`demo/config/config_K_v.json`中`弹幕_识别表情代码`为`true`时,发送特定的文字将发送表情。
clone/下载本项目。进入`demo`目录(文件夹),运行:
```
-go run [-tags "gtk"] main.go [-r 房间ID]
+go run [-tags "gtk"] main.go [-r 房间ID] [-ckv 自定义config_K_v.json]
```
3. docker部署
import (
"encoding/json"
- "io/ioutil"
"strconv"
c "github.com/qydysky/bili_danmu/CV"
+ file "github.com/qydysky/part/file"
limit "github.com/qydysky/part/limit"
reqf "github.com/qydysky/part/reqf"
sys "github.com/qydysky/part/sys"
// 初始化表情代码
func init() {
- bb, err := ioutil.ReadFile("config/config_danmu_official.json")
+ bb, err := file.New("config/config_danmu_official.json", 0, true).ReadAll(1000, 1<<16)
if err != nil {
return
}
import (
_ "embed"
- "flag"
"fmt"
"net/url"
"os"
}()
}
-func Start(roomid ...int) {
+func Start() {
var danmulog = c.C.Log.Base(`bilidanmu`)
defer danmulog.Block(1000)
}
{
- var groomid = flag.Int("r", 0, "roomid")
- flag.Parse()
-
var (
change_room_chan = make(chan struct{})
flash_room_chan = make(chan struct{})
)
- //-r 房间初始化
- var room = *groomid
- if room == 0 && len(roomid) != 0 {
- room = roomid[0]
- }
-
//如果连接中断,则等待
F.KeepConnect()
//获取cookie
F.Get(&c.C).Get(`Cookie`)
//获取LIVE_BUVID
F.Get(&c.C).Get(`LIVE_BUVID`)
- if room == 0 {
+
+ // 房间初始化
+ if c.C.Roomid == 0 {
c.C.Log.Block(1000) //等待所有日志输出完毕
fmt.Println("输入房间号或` live`获取正在直播的主播")
} else {
- fmt.Print("房间号: ", strconv.Itoa(room), "\n")
- if c.C.Roomid == 0 {
- c.C.Roomid = room
- go func() { change_room_chan <- struct{}{} }()
- }
+ fmt.Print("房间号: ", strconv.Itoa(c.C.Roomid), "\n")
+ go func() { change_room_chan <- struct{}{} }()
}
+
//命令行操作 切换房间 发送弹幕
go Cmd.Cmd()