From: qydysky Date: Tue, 5 Jan 2021 16:26:02 +0000 (+0800) Subject: 效率优化 X-Git-Tag: v0.5.6~2^2~30 X-Git-Url: http://127.0.0.1:8081/?a=commitdiff_plain;h=a9b2910e66590939492856eb87f2f323b5704968;p=bili_danmu%2F.git 效率优化 --- diff --git a/CV/Var.go b/CV/Var.go index 5c7daf9..c3341d8 100644 --- a/CV/Var.go +++ b/CV/Var.go @@ -29,7 +29,8 @@ type Danmu_Main_mq_item struct { Class string Data interface{} } -var Danmu_Main_mq = mq.New(10) +//200长度防止push击穿 +var Danmu_Main_mq = mq.New(200) //日志 var Log = log.New(log.Config{ diff --git a/README.md b/README.md index 1b0b101..066297b 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ golang go version go1.15.5 linux/amd64 - [github.com/christopher-dG/go-obs-websocket](https://github.com/christopher-dG/go-obs-websocket) under [MIT](https://raw.githubusercontent.com/christopher-dG/go-obs-websocket/master/LICENSE) - [github.com/gorilla/websocket](https://github.com/gorilla/websocket) under [BSD 2-Clause](https://raw.githubusercontent.com/gorilla/websocket/master/LICENSE) - [github.com/skip2/go-qrcode](https://github.com/skip2/go-qrcode) under [MIT](https://github.com/skip2/go-qrcode/blob/master/LICENSE) +- [github.com/gofrs/uuid](https://github.com/gofrs/uuid) under [MIT](https://github.com/gofrs/uuid/blob/master/LICENSE) - [7z](https://www.7-zip.org/) under [LICENSE](https://www.7-zip.org/license.txt) --- @@ -57,6 +58,7 @@ golang go version go1.15.5 linux/amd64 #### 当前支持功能 以下内容可能过时,点击查看[当前支持功能](https://github.com/qydysky/bili_danmu/blob/master/Reply/F.go#L16) +- [x] 自定义私信 - [x] 自动切换粉丝牌 - [x] 扫码登录 - [x] 自定义语音提醒 diff --git a/Send/README.md b/Send/README.md index 3df4e43..57d8724 100644 --- a/Send/README.md +++ b/Send/README.md @@ -5,4 +5,5 @@ |-|-| |./|弹幕发送| |Send.go|弹幕发送| +|Send_pm.go|私信发送| --- \ No newline at end of file diff --git a/Send/Send_pm.go b/Send/Send_pm.go index 71a631c..f74a5f2 100644 --- a/Send/Send_pm.go +++ b/Send/Send_pm.go @@ -19,13 +19,12 @@ type Pm_item struct { var pm_limit = p.Limit(1, 5000, 10000) func Send_pm(uid int, msg string) error { - if pm_limit.TO() {return errors.New("TO")} - log := c.Log.Base_add(`私信`) - if msg == `` || uid == 0 { return errors.New(`msg == "" || uid == 0`) } + log := c.Log.Base_add(`私信`) + if c.Uid == 0 { log.L(`E: `,`client uid == 0`) return errors.New(`client uid == 0`) @@ -56,6 +55,8 @@ func Send_pm(uid int, msg string) error { } } + if pm_limit.TO() {return errors.New("TO")} + var send_str = `msg[sender_uid]=`+strconv.Itoa(c.Uid)+`&msg[receiver_id]=`+strconv.Itoa(uid)+`&msg[receiver_type]=1&msg[msg_type]=1&msg[msg_status]=0&msg[content]={"content":"`+msg+`"}&msg[timestamp]=`+strconv.Itoa(int(p.Sys().GetSTime()))+`&msg[new_face_version]=0&msg[dev_id]=`+strings.ToUpper(new_uuid)+`&from_firework=0&build=0&mobi_app=web&csrf_token=`+csrf+`&csrf=`+csrf req := p.Req() diff --git a/bili_danmu.go b/bili_danmu.go index ae5d03a..00c980c 100644 --- a/bili_danmu.go +++ b/bili_danmu.go @@ -32,7 +32,7 @@ func Demo(roomid ...int) { if _,ok := c.Default_qn[*live_qn]; ok{c.Live_qn = *live_qn} var exit_sign bool - var change_room_chan = make(chan bool,1) + var change_room_chan = make(chan struct{}) go func(){ var room = *groomid @@ -51,7 +51,7 @@ func Demo(roomid ...int) { } if c.Roomid == 0 { c.Roomid = room - change_room_chan <- true + change_room_chan <- struct{}{} } }() @@ -65,7 +65,8 @@ func Demo(roomid ...int) { c.Uname = ``//主播id c.Title = `` reply.Saveflv_wait()//停止保存直播流 - change_room_chan <- true + for len(change_room_chan) != 0 {<-change_room_chan} + change_room_chan <- struct{}{} return false }, `c.Rev_add`:func(data interface{})(bool){//收入 @@ -82,6 +83,9 @@ func Demo(roomid ...int) { interrupt <- os.Interrupt return false }, + }) + //单独,避免队列执行耗时block从而无法接收更多消息 + c.Danmu_Main_mq.Pull_tag(map[string]func(interface{})(bool){ `pm`:func(data interface{})(bool){//私信 if tmp,ok := data.(send.Pm_item);ok{ send.Send_pm(tmp.Uid,tmp.Msg) diff --git a/demo/config/README.md b/demo/config/README.md index e37e7e3..3f2bcae 100644 --- a/demo/config/README.md +++ b/demo/config/README.md @@ -8,4 +8,5 @@ |config_disable_msg.json|禁用消息开关| |config_gtk_keep_key.json|gtk醒目提示时长| |config_tts.json|语音提示模板| +|config_K_v.json|Key-value键值设置| --- \ No newline at end of file diff --git a/demo/face/0multi b/demo/face/0multi new file mode 100644 index 0000000..d390f51 Binary files /dev/null and b/demo/face/0multi differ diff --git a/demo/face/README.md b/demo/face/README.md index 8ab02b2..b772f71 100644 --- a/demo/face/README.md +++ b/demo/face/README.md @@ -14,4 +14,5 @@ |0room|房间消息时的头像| |0superchat|醒目留言时显示的头像| |0tianxuan|天选之人消息时显示的头像| +|0multi|多人消息时显示的头像| --- \ No newline at end of file diff --git a/demo/go.mod b/demo/go.mod index 95f06be..fdbbc80 100644 --- a/demo/go.mod +++ b/demo/go.mod @@ -11,7 +11,7 @@ require ( github.com/miekg/dns v1.1.35 // indirect github.com/mitchellh/mapstructure v1.4.0 // indirect github.com/qydysky/bili_danmu v0.5.7 - github.com/qydysky/part v0.3.5-0.20201228170623-c701da7df342 // indirect + github.com/qydysky/part v0.3.5-0.20210105160037-508c706d691b // indirect github.com/shirou/gopsutil v3.20.12+incompatible // indirect github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect @@ -22,4 +22,5 @@ require ( replace ( github.com/gotk3/gotk3 v0.5.2 => github.com/qydysky/gotk3 v0.0.0-20210103171910-327affdaaa80 github.com/qydysky/bili_danmu => ../ +//github.com/qydysky/part => ../../part ) diff --git a/demo/go.sum b/demo/go.sum index 2574424..8d811f3 100644 --- a/demo/go.sum +++ b/demo/go.sum @@ -101,6 +101,8 @@ github.com/qydysky/part v0.3.5-0.20201228153342-9ad523c2bef4 h1:0A7uj8u2PTn2DXea github.com/qydysky/part v0.3.5-0.20201228153342-9ad523c2bef4/go.mod h1:SxxNav0Z7DbsDLoG5uxo0wW5EKU/JBu2CAkZzZeLnX0= github.com/qydysky/part v0.3.5-0.20201228170623-c701da7df342 h1:7wCI40bHHgJ9+yByTqvLM7Jctz9Z5oMoK2AATHBHxaQ= github.com/qydysky/part v0.3.5-0.20201228170623-c701da7df342/go.mod h1:SxxNav0Z7DbsDLoG5uxo0wW5EKU/JBu2CAkZzZeLnX0= +github.com/qydysky/part v0.3.5-0.20210105160037-508c706d691b h1:rKR4PD/8CzT28Whf4ILQ4WZZW1S8MxJFSluYtrzu5+c= +github.com/qydysky/part v0.3.5-0.20210105160037-508c706d691b/go.mod h1:SxxNav0Z7DbsDLoG5uxo0wW5EKU/JBu2CAkZzZeLnX0= github.com/qydysky/part/msgq v0.0.0-20201213031129-ca3253dc72ad h1:Jtzf509lQrkUMGTV0Sc6IDCAiR1VrBcHrIban7hpye4= github.com/qydysky/part/msgq v0.0.0-20201213031129-ca3253dc72ad/go.mod h1:w32TkJNVtTJd4LOS09cq+4uYG6itcN2vsqw+slp44Rg= github.com/qydysky/part/msgq v0.0.0-20201213120821-f36e49c32bba h1:1ew9dRpc0Rux0WkWeT/4AE15ynYWmL2D7onJEJIFOB8= diff --git a/demo/main.go b/demo/main.go index f91f041..cd0204a 100644 --- a/demo/main.go +++ b/demo/main.go @@ -1,9 +1,17 @@ package main import ( + // "os" + // "runtime/pprof" q "github.com/qydysky/bili_danmu" ) func main() { + // f, _ := os.OpenFile("cpu.pprof", os.O_RDWR|os.O_CREATE, 0644) + // pprof.StartCPUProfile(f) + q.Demo() + + // pprof.StopCPUProfile() + // f.Close() } \ No newline at end of file