]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
房间切换弹幕不停止bug
authorqydysky <qydysky@foxmail.com>
Thu, 10 Jun 2021 18:03:49 +0000 (02:03 +0800)
committerqydysky <qydysky@foxmail.com>
Thu, 10 Jun 2021 18:03:49 +0000 (02:03 +0800)
Reply/F.go
Reply/Reply.go

index 3b4ae4e7d1cdf0e8ac4c3f441a48b4586e9bc8f5..642fff1601692873c5a7e200a517e14c2ef49c83 100644 (file)
@@ -1554,6 +1554,7 @@ func Danmuji_auto() {
 }
 
 type Autoskip struct {
+       roomid int
        buf map[string]Autoskip_item
        sync.Mutex
        now uint
@@ -1577,14 +1578,29 @@ func init(){
                        if len(autoskip.buf) == 0 {continue}
                        autoskip.now += 1
                        autoskip.Lock()
+                       if autoskip.roomid != c.Roomid {
+                               autoskip.buf = make(map[string]Autoskip_item)
+                               autoskip.roomid = c.Roomid
+                               flog.Base_add(`弹幕合并`).L(`T: `,`房间更新:`,autoskip.roomid)
+                               autoskip.Unlock()
+                               continue
+                       }
                        for k,v := range autoskip.buf{
                                if v.Exprie <= autoskip.now {
                                        delete(autoskip.buf,k)
                                        {//超时显示
                                                if v.Num > 3 {
-                                                       Msg_showdanmu(nil, strconv.Itoa(int(v.Num)) + " x " + k,`0multi`)
+                                                       Msg_showdanmu(Danmu_item{
+                                                               msg:strconv.Itoa(int(v.Num)) + " x " + k,
+                                                               uid:`0multi`,
+                                                               roomid:autoskip.roomid,
+                                                       })
                                                } else if v.Num > 1 {
-                                                       Msg_showdanmu(nil, strconv.Itoa(int(v.Num)) + " x " + k,`0default`)
+                                                       Msg_showdanmu(Danmu_item{
+                                                               msg:strconv.Itoa(int(v.Num)) + " x " + k,
+                                                               uid:`0default`,
+                                                               roomid:autoskip.roomid,
+                                                       })
                                                }
                                        }
                                }
@@ -1603,6 +1619,12 @@ func Autoskipf(s string) uint {
        if !IsOn("弹幕合并") || s == ""{return 0}
        autoskip.Lock()
        defer autoskip.Unlock()
+       if autoskip.roomid != c.Roomid {
+               autoskip.buf = make(map[string]Autoskip_item)
+               autoskip.roomid = c.Roomid
+               flog.Base_add(`弹幕合并`).L(`T: `,`房间更新:`,autoskip.roomid)
+               return 0
+       }
        {//验证是否已经存在
                if v,ok := autoskip.buf[s];ok && autoskip.now < v.Exprie{
                        autoskip.buf[s] = Autoskip_item{
@@ -1622,6 +1644,7 @@ func Autoskipf(s string) uint {
 }
 
 type Lessdanmu struct {
+       roomid int
        buf []string
        limit *limit.Limit
        max_num int
@@ -1649,6 +1672,14 @@ func init() {
                                time.Sleep(time.Second*10)
 
                                lessdanmu.Lock()
+                               if lessdanmu.roomid != c.Roomid {
+                                       lessdanmu.buf = nil
+                                       lessdanmu.roomid = c.Roomid
+                                       lessdanmu.threshold = 0.7
+                                       flog.Base_add(`更少弹幕`).L(`T: `,`房间更新:`,lessdanmu.roomid)
+                                       lessdanmu.Unlock()
+                                       continue
+                               }
                                if ptk := lessdanmu.limit.PTK();ptk == lessdanmu.max_num {
                                        if lessdanmu.threshold > 0.03 {
                                                lessdanmu.threshold -= 0.03
@@ -1666,6 +1697,15 @@ func init() {
 
 func Lessdanmuf(s string) (show bool) {
        if !IsOn("相似弹幕忽略") {return true}
+       if lessdanmu.roomid != c.Roomid {
+               lessdanmu.Lock()
+               lessdanmu.buf = nil
+               lessdanmu.roomid = c.Roomid
+               lessdanmu.threshold = 0.7
+               lessdanmu.Unlock()
+               flog.Base_add(`更少弹幕`).L(`T: `,`房间更新:`,lessdanmu.roomid)
+               return true
+       }
        if len(lessdanmu.buf) < 20 {
                lessdanmu.buf = append(lessdanmu.buf, s)
                return true
index fb421d482bcc557d522de4a19e518f7cfd9b6a30..628e8e714951b33d75c0cce27727177c1dee5749 100644 (file)
@@ -783,6 +783,12 @@ func (replyF) roominfo(s string){
 }
 
 //Msg-弹幕处理
+type Danmu_item struct {
+       msg string
+       auth interface{}
+       uid string
+       roomid int//to avoid danmu show when room has changed
+}
 func (replyF) danmu(s string) {
        var j struct {
                Cmd  string        `json:"cmd"`
@@ -794,27 +800,40 @@ func (replyF) danmu(s string) {
        }
        
        infob := j.Info
-       msg := infob[1].(string)
-       auth := infob[2].([]interface{})[1]
-       uid := strconv.Itoa(int(infob[2].([]interface{})[0].(float64)))
-       // timeStramp := int64(infob[0].([]interface{})[4].(float64))
+       item := Danmu_item{}
+       {
+               //解析
+               if len(infob) > 0 {
+                       item.msg,_ = infob[1].(string)
+               }
+               if len(infob) > 1 {
+                       i,_ := infob[2].([]interface{})
+                       if len(i) > 0 {
+                               item.uid = strconv.Itoa(int(i[0].(float64)))
+                       }
+                       if len(i) > 1 {
+                               item.auth = i[1]
+                       }
+               }
+               item.roomid = c.Roomid
+       }
 
        msglog := msglog.Log_show_control(false)
 
        {//附加功能 弹幕机 封禁 弹幕合并
-               Danmujif(msg)
-               if Autobanf(msg) {
-                       Gui_show(Itos([]interface{}{"风险", auth, ":", msg}))
-                       fmt.Println("风险", auth, ":", msg)
-                       msglog.Base_add("风险").L(`I: `, auth, ":", msg)
+               go Danmujif(item.msg)
+               if Autobanf(item.msg) {
+                       Gui_show(Itos([]interface{}{"风险", item.auth, ":", item.msg}))
+                       fmt.Println("风险", item.auth, ":", item.msg)
+                       msglog.Base_add("风险").L(`I: `, item.auth, ":", item.msg)
                        return
                }
-               if i := Autoskipf(msg); i > 0 {
-                       msglog.L(`I: `, auth, ":", msg)
+               if i := Autoskipf(item.msg); i > 0 {
+                       msglog.L(`I: `, item.auth, ":", item.msg)
                        return
                }
        }
-       Msg_showdanmu(auth, msg, uid)
+       Msg_showdanmu(item)
 }
 
 //弹幕发送
@@ -834,32 +853,39 @@ func Msg_senddanmu(msg string){
 
 //弹幕显示
 //由于额外功能有些需要显示,为了统一管理,使用此方法进行处理
-func Msg_showdanmu(auth interface{}, m ...string) {
-       msg := m[0]
+func Msg_showdanmu(item Danmu_item) {
+       msg := item.msg
        msglog := msglog.Log_show_control(false)
        {//附加功能 更少弹幕
                if !Lessdanmuf(msg) {
-                       if auth != nil {msglog.L(`I: `, auth, ":", msg)}
+                       if item.auth != nil {msglog.L(`I: `, item.auth, ":", msg)}
                        return
                }
                if _msg := Shortdanmuf(msg); _msg == "" {
-                       if auth != nil {msglog.L(`I: `, auth, ":", msg)}
+                       if item.auth != nil {msglog.L(`I: `, item.auth, ":", msg)}
                        return
                } else {msg = _msg}
+       }
+
+       //room change
+       if item.roomid != 0 && item.roomid != c.Roomid {return}
+       
+       //展示
+       {
                Assf(msg)//ass
-               if auth != nil {
-                       Gui_show(fmt.Sprint(auth) +`: `+ msg, m[1])
+               if item.auth != nil {
+                       Gui_show(fmt.Sprint(item.auth) +`: `+ msg, item.uid)
                } else {
-                       Gui_show(m...)
-               }       
+                       Gui_show(msg, item.uid)
+               }
        }
        {//语言tts 私信
-               if len(m) > 1 {
+               if item.uid != "" {
                        c.Danmu_Main_mq.Push_tag(`tts`,Danmu_mq_t{//传入消息队列
-                               uid:m[1],
+                               uid:item.uid,
                                msg:msg,
                        })
-                       if i,e := strconv.Atoi(m[1]);e == nil {
+                       if i,e := strconv.Atoi(item.uid);e == nil {
                                c.Danmu_Main_mq.Push_tag(`pm`,send.Pm_item{
                                        Uid:i,
                                        Msg:c.K_v.LoadV(`弹幕私信`).(string),
@@ -874,7 +900,7 @@ func Msg_showdanmu(auth interface{}, m ...string) {
                }
        }
        fmt.Println(msg)
-       if auth != nil {msglog.L(`I: `, auth, ":", msg)}
+       if item.auth != nil {msglog.L(`I: `, item.auth, ":", msg)}
 }
 
 type Danmu_mq_t struct {