]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
Add 添加exit指令,可退出当前房间
authorqydysky <qydysky@foxmail.com>
Tue, 9 May 2023 18:56:31 +0000 (02:56 +0800)
committerqydysky <qydysky@foxmail.com>
Tue, 9 May 2023 18:56:35 +0000 (02:56 +0800)
Improve 优化主流程

CV/Var.go
Reply/Msg.go
Reply/tts.go
bili_danmu.go
cmd/cmd.go
go.mod
go.sum

index 1297701cb3c6c6eacdbf7e1345aced6a104a7bf7..6e1ff75bb11578fad2cb4e2cc00fe19d457f2e07 100644 (file)
--- a/CV/Var.go
+++ b/CV/Var.go
@@ -231,6 +231,18 @@ func (t *Common) Init() *Common {
 
        t.Danmu_Main_mq = mq.New()
 
+       go func() { //日期变化
+               var old = time.Now().Hour()
+               for {
+                       if now := time.Now().Hour(); now == 0 && old != now {
+                               t.Danmu_Main_mq.Push_tag(`new day`, nil)
+                               old = now
+                       }
+                       t.Danmu_Main_mq.Push_tag(`every100s`, nil)
+                       time.Sleep(time.Second * time.Duration(100))
+               }
+       }()
+
        t.ReqPool = pool.New(
                func() *reqf.Req {
                        return reqf.New()
index 3e1ab447e902a04b868ba0a69af377d88c687731..7f530493f59038cdb764a2b940627034f1b24237 100644 (file)
@@ -17,6 +17,7 @@ var msglog = c.C.Log.Base(`Msg`)
 
 // Msg类型数据处理方法map
 var Msg_map = map[string]func(replyF, string){
+       `HOT_BUY_NUM`:                       nil,
        `VOICE_JOIN_ROOM_COUNT_INFO`:        replyF.voice_join_room_count_info, //连麦等待
        `VOICE_JOIN_LIST`:                   nil,
        `VOICE_JOIN_STATUS`:                 replyF.voice_join_status,     //连麦人状态
index d0e3fd50f10979d09b81bcecbd80c427d65ea716..a31ae47775c1bc9ae7675953ce97b46f87218b66 100644 (file)
@@ -1,6 +1,7 @@
 package reply
 
 import (
+       "context"
        "crypto/hmac"
        "crypto/sha256"
        "encoding/base64"
@@ -276,7 +277,7 @@ var (
                `aisbabyxu`: true,
        }
        xfwsClient   *ws.Client
-       xf_req       func()
+       xf_req       func([]byte)
        xf_req_block funcCtrl.BlockFunc
 )
 
@@ -348,11 +349,11 @@ func init() {
                return
        }
 
-       xf_req = func() {
+       xf_req = func(b []byte) {
                xf_req_block.Block() //cant call in same time
                defer xf_req_block.UnBlock()
 
-               xfwsClient = ws.New_client(ws.Client{
+               xfwsClient, _ = ws.New_client(&ws.Client{
                        Url:   wsUrl,
                        Proxy: c.C.Proxy,
                        Header: map[string]string{
@@ -362,61 +363,71 @@ func init() {
                                `Pragma`:          `no-cache`,
                                `Cache-Control`:   `no-cache`,
                        },
-               }).Handle()
+               })
+               wsc, _ := xfwsClient.Handle()
                if xfwsClient.Isclose() {
                        tts_log.L(`E: `, "连接错误,使用百度", xfwsClient.Error())
                        tts_ser = `baidu`
                } else {
-                       go func() {
-                               var buf []byte
-                               for !xfwsClient.Isclose() {
-                                       data := <-xfwsClient.RecvChan
-                                       if len(data) == 0 {
-                                               break
-                                       }
+                       var buf []byte
+                       wait, cancel := context.WithCancel(context.Background())
+
+                       wsc.Pull_tag_only(`rec`, func(wm *ws.WsMsg) (disable bool) {
+                               if len(wm.Msg) == 0 {
+                                       cancel()
+                                       return true
+                               }
 
-                                       var partS struct {
-                                               Code    int    `json:"code"`
-                                               Message string `json:"message"`
-                                               Sid     string `json:"sid"`
-                                               Data    struct {
-                                                       Audio  string `json:"audio"`
-                                                       Ced    string `json:"ced"`
-                                                       Status int    `json:"status"`
-                                               } `json:"data"`
+                               var partS struct {
+                                       Code    int    `json:"code"`
+                                       Message string `json:"message"`
+                                       Sid     string `json:"sid"`
+                                       Data    struct {
+                                               Audio  string `json:"audio"`
+                                               Ced    string `json:"ced"`
+                                               Status int    `json:"status"`
+                                       } `json:"data"`
+                               }
+                               if e := json.Unmarshal(wm.Msg, &partS); e != nil {
+                                       tts_log.L(`E: `, "错误", e, wm.Msg)
+                                       xfwsClient.Close()
+                                       return
+                               } else {
+                                       if partS.Code != 0 {
+                                               tts_log.L(`W: `, fmt.Sprintf("code:%d msg:%s", partS.Code, partS.Message))
+                                               cancel()
+                                               return true
                                        }
-                                       if e := json.Unmarshal(data, &partS); e != nil {
-                                               tts_log.L(`E: `, "错误", e, data)
-                                               xfwsClient.Close()
-                                               return
-                                       } else {
-                                               if partS.Code != 0 {
-                                                       tts_log.L(`W: `, fmt.Sprintf("code:%d msg:%s", partS.Code, partS.Message))
-                                                       break
-                                               }
-                                               if partS.Data.Audio != "" {
-                                                       if part, e := base64.StdEncoding.DecodeString(partS.Data.Audio); e != nil {
-                                                               tts_log.L(`E: `, "错误", e)
-                                                               break
-                                                       } else {
-                                                               buf = append(buf, part...)
-                                                       }
-                                               }
-                                               if partS.Data.Status == 2 {
-                                                       break
+                                       if partS.Data.Audio != "" {
+                                               if part, e := base64.StdEncoding.DecodeString(partS.Data.Audio); e != nil {
+                                                       tts_log.L(`E: `, "错误", e)
+                                                       cancel()
+                                                       return true
+                                               } else {
+                                                       buf = append(buf, part...)
                                                }
                                        }
+                                       if partS.Data.Status == 2 {
+                                               cancel()
+                                               return true
+                                       }
                                }
-                               if len(buf) != 0 {
-                                       _, _ = file.New(sys.Sys().Cdir()+`/tts.mp3`, 0, true).Write(buf, true)
-                                       play()
-                               }
-                               xfwsClient.Close()
-                       }()
+                               return false
+                       })
+
+                       wsc.Push_tag(`send`, &ws.WsMsg{
+                               Msg: b,
+                       })
+
+                       <-wait.Done()
+                       if len(buf) != 0 {
+                               _, _ = file.New(sys.Sys().Cdir()+`/tts.mp3`, 0, true).Write(buf, true)
+                               play()
+                       }
+                       xfwsClient.Close()
                }
 
        }
-       xf_req()
 }
 func xf(msg string) error {
        if xfId == `` || xfKey == `` || xfSecret == `` {
@@ -461,10 +472,7 @@ func xf(msg string) error {
                if b, e := json.Marshal(postS); e != nil {
                        return e
                } else {
-                       if xfwsClient.Isclose() {
-                               xf_req()
-                       }
-                       xfwsClient.SendChan <- b
+                       xf_req(b)
                }
        }
        return nil
index 724f59933fcce95ec41f6c5528be26e25c4cfa70..8dd3efa5d86e86bb571605a87600af83173ce7b5 100644 (file)
@@ -1,7 +1,9 @@
 package bili_danmu
 
 import (
+       "context"
        _ "embed"
+       "errors"
        "fmt"
        "net/url"
        "os"
@@ -25,93 +27,78 @@ import (
 //go:embed VERSION
 var version string
 
-func init() {
-       go func() { //日期变化
-               var old = time.Now().Hour()
-               for {
-                       if now := time.Now().Hour(); now == 0 && old != now {
-                               c.C.Danmu_Main_mq.Push_tag(`new day`, nil)
-                               old = now
-                       }
-                       c.C.Danmu_Main_mq.Push_tag(`every100s`, nil)
-                       time.Sleep(time.Second * time.Duration(100))
-               }
-       }()
-}
-
 func Start() {
        var danmulog = c.C.Log.Base(`bilidanmu`)
        defer danmulog.Block(1000)
 
+       danmulog.L(`I: `, `当前PID:`, c.C.PID)
+       danmulog.L(`I: `, "version: ", strings.TrimSpace(version))
+
+       //检查配置
+       if c.C.K_v.Len() == 0 {
+               panic("未能加载配置")
+       }
+
+       // 保持唤醒
        var stop = sys.Sys().PreventSleep()
        defer stop.Done()
 
-       danmulog.L(`I: `, "version: ", strings.TrimSpace(version))
-
        //ctrl+c退出
-       interrupt := make(chan os.Signal, 2)
        go func() {
+               var interrupt = make(chan os.Signal, 2)
+               //捕获ctrl+c退出
+               signal.Notify(interrupt, os.Interrupt)
                danmulog.L(`T: `, "两次ctrl+c强制退出")
-               for len(interrupt) < 2 {
-                       time.Sleep(time.Second * 3)
-               }
-               danmulog.L(`I: `, "强制退出!").Block(1000)
-               os.Exit(1)
-       }()
-
-       danmulog.L(`I: `, `当前PID:`, c.C.PID)
-
-       //启动时显示ip
-       {
-               if v, ok := c.C.K_v.LoadV("启动时显示ip").(bool); ok && v {
-                       for _, v := range sys.GetIntranetIp(``) {
-                               danmulog.L(`I: `, `当前ip:http://`+v)
+               for {
+                       <-interrupt
+                       danmulog.L(`I: `, "3s内ctrl+c强制退出!").Block(1000)
+                       c.C.Danmu_Main_mq.PushLock_tag(`interrupt`, nil)
+                       select {
+                       case <-interrupt:
+                               c.C.Danmu_Main_mq.PushLock_tag(`interrupt`, nil)
+                               danmulog.L(`I: `, "强制退出!").Block(1000)
+                               os.Exit(1)
+                       case <-time.After(time.Second * 3):
                        }
                }
-       }
+       }()
 
-       //检查配置
-       {
-               if c.C.K_v.Len() == 0 {
-                       panic("未能加载配置")
+       // 启动时显示ip
+       if v, ok := c.C.K_v.LoadV("启动时显示ip").(bool); ok && v {
+               for _, v := range sys.GetIntranetIp(``) {
+                       danmulog.L(`I: `, `当前ip:http://`+v)
                }
        }
 
        {
-               var (
-                       change_room_chan = make(chan struct{})
-                       flash_room_chan  = make(chan struct{})
-               )
-
                //如果连接中断,则等待
                F.KeepConnect()
                //获取cookie
                F.Get(c.C).Get(`Cookie`)
                //获取LIVE_BUVID
                F.Get(c.C).Get(`LIVE_BUVID`)
+               //命令行操作 切换房间 发送弹幕
+               go Cmd.Cmd()
+               //获取uid
+               F.Get(c.C).Get(`Uid`)
+               //兑换硬币
+               F.Get(c.C).Get(`Silver_2_coin`)
+               //每日签到
+               F.Dosign()
+               // 附加功能 savetojson
+               reply.SaveToJson.Init()
+
+               var change_room_chan = c.C.Danmu_Main_mq.Pull_tag_chan(`change_room`, 1, context.Background())
+               var interrupt_chan = c.C.Danmu_Main_mq.Pull_tag_chan(`interrupt`, 1, context.Background())
 
                // 房间初始化
-               if c.C.Roomid == 0 {
-                       c.C.Log.Block(1000) //等待所有日志输出完毕
-                       fmt.Println("回车查看指令")
-               } else {
+               if c.C.Roomid != 0 {
                        fmt.Print("房间号: ", strconv.Itoa(c.C.Roomid), "\n")
-                       go func() { change_room_chan <- struct{}{} }()
+                       c.C.Danmu_Main_mq.Push_tag(`change_room`, nil)
                }
 
-               //命令行操作 切换房间 发送弹幕
-               go Cmd.Cmd()
-
                //使用带tag的消息队列在功能间传递消息
                c.C.Danmu_Main_mq.Pull_tag(msgq.FuncMap{
-                       `flash_room`: func(_ any) bool { //房间重进
-                               F.Get(c.C).Get(`WSURL`)
-                               select {
-                               case flash_room_chan <- struct{}{}:
-                               default:
-                               }
-                               return false
-                       },
                        `change_room`: func(_ any) bool { //房间改变
                                c.C.Rev = 0.0     // 营收
                                c.C.Renqi = 1     // 人气置1
@@ -122,10 +109,6 @@ func Start() {
                                c.C.Uname = ``    // 主播id
                                c.C.Title = ``
                                c.C.Wearing_FansMedal = 0
-                               for len(change_room_chan) != 0 {
-                                       <-change_room_chan
-                               }
-                               change_room_chan <- struct{}{}
                                return false
                        },
                        `c.Rev_add`: func(data any) bool { //收入
@@ -139,7 +122,7 @@ func Start() {
                                return false
                        },
                        `gtk_close`: func(_ any) bool { //gtk关闭信号
-                               interrupt <- os.Interrupt
+                               c.C.Danmu_Main_mq.PushLock_tag(`interrupt`, nil)
                                return false
                        },
                        `pm`: func(data any) bool { //私信
@@ -152,30 +135,28 @@ func Start() {
                        },
                })
 
-               <-change_room_chan
+               for exit_sign := true; exit_sign; {
+                       if len(change_room_chan) == 0 {
+                               fmt.Println("回车查看指令")
+                       }
 
-               //捕获ctrl+c退出
-               signal.Notify(interrupt, os.Interrupt)
-               //获取uid
-               F.Get(c.C).Get(`Uid`)
-               //兑换硬币
-               F.Get(c.C).Get(`Silver_2_coin`)
-               //每日签到
-               F.Dosign()
-               // //客户版本 不再需要
-               // F.Get(`VERSION`)
-               // 附加功能 savetojson
-               reply.SaveToJson.Init()
-               //附加功能 保持牌子点亮
-               go reply.Keep_medal_light()
-               //附加功能 自动发送即将过期礼物
-               go reply.AutoSend_silver_gift()
+                       select {
+                       case <-change_room_chan:
+                       case <-interrupt_chan:
+                               exit_sign = false
+                       }
 
-               for exit_sign := true; exit_sign; {
+                       if !exit_sign {
+                               break
+                       }
 
                        danmulog.L(`T: `, "准备")
                        //如果连接中断,则等待
                        F.KeepConnect()
+                       //附加功能 保持牌子点亮
+                       go reply.Keep_medal_light()
+                       //附加功能 自动发送即将过期礼物
+                       go reply.AutoSend_silver_gift()
                        //获取热门榜
                        F.Get(c.C).Get(`Note`)
 
@@ -200,12 +181,12 @@ func Start() {
 
                        //对每个弹幕服务器尝试
                        F.Get(c.C).Get(`WSURL`)
-                       for i := 0; i < len(c.C.WSURL); i += 1 {
+                       for i, aliveT, exitloop := 0, time.Now().Add(3*time.Hour), false; !exitloop && i < len(c.C.WSURL) && time.Now().Before(aliveT); {
                                v := c.C.WSURL[i]
                                //ws启动
                                danmulog.L(`T: `, "连接 "+v)
                                u, _ := url.Parse(v)
-                               ws_c := ws.New_client(ws.Client{
+                               ws_c, err := ws.New_client(&ws.Client{
                                        Url:               v,
                                        TO:                35 * 1000,
                                        Proxy:             c.C.Proxy,
@@ -221,136 +202,156 @@ func Start() {
                                                `Pragma`:          `no-cache`,
                                                `Cache-Control`:   `no-cache`,
                                        },
-                               }).Handle()
+                               })
+                               if err != nil {
+                                       danmulog.L(`E: `, "连接错误", err)
+                                       i += 1
+                                       continue
+                               }
+                               wsmsg, err := ws_c.Handle()
+                               if err != nil {
+                                       danmulog.L(`E: `, "连接错误", err)
+                                       i += 1
+                                       continue
+                               }
                                if ws_c.Isclose() {
                                        danmulog.L(`E: `, "连接错误", ws_c.Error())
+                                       i += 1
                                        continue
                                }
 
-                               //SendChan 传入发送[]byte
-                               //RecvChan 接收[]byte
-                               ws_c.SendChan <- F.HelloGen(c.C.Roomid, c.C.Token)
-                               if F.HelloChe(<-ws_c.RecvChan) {
-                                       danmulog.L(`I: `, "已连接到房间", c.C.Uname, `(`, c.C.Roomid, `)`)
-                                       reply.Gui_show(`进入直播间: `+c.C.Uname+` (`+strconv.Itoa(c.C.Roomid)+`)`, `0room`)
-                                       if c.C.Title != `` {
-                                               danmulog.L(`I: `, c.C.Title)
-                                               reply.Gui_show(`房间标题: `+c.C.Title, `0room`)
-                                       }
-                                       //30s获取一次人气
-                                       go func() {
-                                               time.Sleep(time.Millisecond * time.Duration(500)) //500ms
-                                               danmulog.L(`T: `, "获取人气")
-                                               go func() {
-                                                       heartbeatmsg, heartinterval := F.Heartbeat()
-                                                       for !ws_c.Isclose() {
-                                                               ws_c.SendChan <- heartbeatmsg
-                                                               time.Sleep(time.Millisecond * time.Duration(heartinterval*1000))
-                                                       }
-                                               }()
-
-                                               //订阅消息,以便刷新舰长数
-                                               F.Get(c.C).Get(`GuardNum`)
-                                               // 在线人数
-                                               F.Get(c.C).Get(`getOnlineGoldRank`)
-                                               //当前ws的消息队列
-                                               c.C.Danmu_Main_mq.Pull_tag(msgq.FuncMap{
-                                                       `exit_cu_room`: func(_ any) bool { //退出
-                                                               return true
-                                                       },
-                                                       `guard_update`: func(_ any) bool { //舰长更新
-                                                               go F.Get(c.C).Get(`GuardNum`)
-                                                               return false
-                                                       },
-                                                       `flash_room`: func(_ any) bool { //重进房时退出当前房间
-                                                               return true
-                                                       },
-                                                       `change_room`: func(_ any) bool { //换房时退出当前房间
-                                                               return true
-                                                       },
-                                                       `every100s`: func(_ any) bool { //每100s
-                                                               if v, ok := c.C.K_v.LoadV("下播后不记录人气观看人数").(bool); ok && v && !c.C.Liveing {
-                                                                       return false
-                                                               }
-                                                               // 在线人数
-                                                               F.Get(c.C).Get(`getOnlineGoldRank`)
-                                                               return false
-                                                       },
-                                                       `new day`: func(_ any) bool { //日期更换
-                                                               //每日签到
-                                                               F.Dosign()
-                                                               // //获取用户版本  不再需要
-                                                               // go F.Get(`VERSION`)
-                                                               //每日兑换硬币
-                                                               go F.Get(c.C).Silver_2_coin()
-                                                               //附加功能 每日发送弹幕
-                                                               go reply.Entry_danmu()
-                                                               //附加功能 保持牌子点亮
-                                                               go reply.Keep_medal_light()
-                                                               //附加功能 自动发送即将过期礼物
-                                                               go reply.AutoSend_silver_gift()
-                                                               return false
-                                                       },
-                                               })
-
-                                               //验证cookie
-                                               if missKey := F.CookieCheck([]string{
-                                                       `bili_jct`,
-                                                       `DedeUserID`,
-                                                       `LIVE_BUVID`,
-                                               }); len(missKey) == 0 {
-                                                       //附加功能 弹幕机 无cookie无法发送弹幕
-                                                       reply.Danmuji_auto()
+                               // auth
+                               {
+                                       wsmsg.PushLock_tag(`send`, &ws.WsMsg{
+                                               Msg: F.HelloGen(c.C.Roomid, c.C.Token),
+                                       })
+                                       waitCheckAuth, cancel := context.WithTimeout(context.Background(), 5*time.Second)
+                                       wsmsg.Pull_tag_only(`rec`, func(wm *ws.WsMsg) (disable bool) {
+                                               if F.HelloChe(wm.Msg) {
+                                                       cancel()
                                                }
+                                               return true
+                                       })
+                                       <-waitCheckAuth.Done()
+                                       if err := waitCheckAuth.Err(); errors.Is(err, context.DeadlineExceeded) {
+                                               danmulog.L(`E: `, "连接验证失败")
+                                               i += 1
+                                               continue
+                                       }
+                               }
 
-                                               { //附加功能 进房间发送弹幕 直播流保存 营收 每日签到
-                                                       go F.Dosign()
-                                                       go reply.Entry_danmu()
-                                                       go reply.StreamOStart(c.C.Roomid)
-                                                       go reply.ShowRevf()
-                                                       go F.RoomEntryAction(c.C.Roomid)
-                                               }
-                                       }()
+                               danmulog.L(`I: `, "已连接到房间", c.C.Uname, `(`, c.C.Roomid, `)`)
+                               reply.Gui_show(`进入直播间: `+c.C.Uname+` (`+strconv.Itoa(c.C.Roomid)+`)`, `0room`)
+                               if c.C.Title != `` {
+                                       danmulog.L(`I: `, c.C.Title)
+                                       reply.Gui_show(`房间标题: `+c.C.Title, `0room`)
                                }
 
-                               var isclose bool
-                               var break_sign bool
-                               for !isclose {
-                                       select {
-                                       case i := <-ws_c.RecvChan:
-                                               if len(i) == 0 && ws_c.Isclose() {
-                                                       isclose = true
-                                               } else {
-                                                       go reply.Reply(i)
-                                               }
-                                       case <-interrupt:
-                                               ws_c.Close()
-                                               danmulog.L(`I: `, "停止,等待服务器断开连接")
-                                               break_sign = true
-                                               exit_sign = false
-                                       case <-flash_room_chan:
-                                               ws_c.Close()
-                                               danmulog.L(`I: `, "停止,等待服务器断开连接")
-                                               //刷新WSURL
-                                               F.Get(c.C).Get(`WSURL`)
-                                               i = 0
-                                       case <-change_room_chan:
-                                               ws_c.Close()
-                                               danmulog.L(`I: `, "停止,等待服务器断开连接")
-                                               break_sign = true
+                               //30s获取一次人气
+                               go func() {
+                                       danmulog.L(`T: `, "获取人气")
+                                       heartbeatmsg, heartinterval := F.Heartbeat()
+                                       for !ws_c.Isclose() {
+                                               wsmsg.PushLock_tag(`send`, &ws.WsMsg{
+                                                       Msg: heartbeatmsg,
+                                               })
+                                               time.Sleep(time.Millisecond * time.Duration(heartinterval*1000))
                                        }
+                               }()
+
+                               // 刷新舰长数
+                               F.Get(c.C).Get(`GuardNum`)
+                               // 在线人数
+                               F.Get(c.C).Get(`getOnlineGoldRank`)
+                               //验证cookie
+                               if missKey := F.CookieCheck([]string{
+                                       `bili_jct`,
+                                       `DedeUserID`,
+                                       `LIVE_BUVID`,
+                               }); len(missKey) == 0 {
+                                       //附加功能 弹幕机 无cookie无法发送弹幕
+                                       reply.Danmuji_auto()
                                }
-
-                               // 当前ws链接断开时,取消当前ws的消息队列
-                               c.C.Danmu_Main_mq.Push_tag(`exit_cu_room`, nil)
-
-                               if break_sign {
-                                       break
+                               { //附加功能 进房间发送弹幕 直播流保存 营收 每日签到
+                                       go F.Dosign()
+                                       go reply.Entry_danmu()
+                                       go reply.StreamOStart(c.C.Roomid)
+                                       go reply.ShowRevf()
+                                       go F.RoomEntryAction(c.C.Roomid)
                                }
-                       }
-                       { //附加功能
-                               if v, ok := c.C.K_v.LoadV(`仅保存当前直播间流`).(bool); ok && v {
-                                       reply.StreamOStop(-2) //停止其他房间录制
+
+                               //当前ws
+                               {
+                                       c.C.Danmu_Main_mq.Pull_tag(msgq.FuncMap{
+                                               `interrupt`: func(_ any) (disable bool) {
+                                                       exitloop = true
+                                                       exit_sign = false
+                                                       ws_c.Close()
+                                                       danmulog.L(`I: `, "停止,等待服务器断开连接")
+                                                       reply.StreamOStop(-1) //停止录制
+                                                       return true
+                                               },
+                                               `exit_room`: func(_ any) bool { //退出当前房间
+                                                       exitloop = true
+                                                       ws_c.Close()
+                                                       return true
+                                               },
+                                               `change_room`: func(_ any) bool { //换房时退出当前房间
+                                                       exitloop = true
+                                                       ws_c.Close()
+                                                       if v, ok := c.C.K_v.LoadV(`仅保存当前直播间流`).(bool); ok && v {
+                                                               reply.StreamOStop(-2) //停止其他房间录制
+                                                       }
+                                                       return true
+                                               },
+                                               `flash_room`: func(_ any) bool { //重进房时退出当前房间
+                                                       ws_c.Close()
+                                                       return true
+                                               },
+                                               `guard_update`: func(_ any) bool { //舰长更新
+                                                       go F.Get(c.C).Get(`GuardNum`)
+                                                       return false
+                                               },
+                                               `every100s`: func(_ any) bool { //每100s
+                                                       if time.Now().After(aliveT) {
+                                                               c.C.Danmu_Main_mq.Push_tag(`flash_room`, nil)
+                                                               return false
+                                                       }
+                                                       if v, ok := c.C.K_v.LoadV("下播后不记录人气观看人数").(bool); ok && v && !c.C.Liveing {
+                                                               return false
+                                                       }
+                                                       // 在线人数
+                                                       F.Get(c.C).Get(`getOnlineGoldRank`)
+                                                       return false
+                                               },
+                                               `new day`: func(_ any) bool { //日期更换
+                                                       //每日签到
+                                                       F.Dosign()
+                                                       // //获取用户版本  不再需要
+                                                       // go F.Get(`VERSION`)
+                                                       //每日兑换硬币
+                                                       go F.Get(c.C).Silver_2_coin()
+                                                       //附加功能 每日发送弹幕
+                                                       go reply.Entry_danmu()
+                                                       //附加功能 保持牌子点亮
+                                                       go reply.Keep_medal_light()
+                                                       //附加功能 自动发送即将过期礼物
+                                                       go reply.AutoSend_silver_gift()
+                                                       return false
+                                               },
+                                       })
+
+                                       wsmsg.Pull_tag(map[string]func(*ws.WsMsg) (disable bool){
+                                               `rec`: func(wm *ws.WsMsg) (disable bool) {
+                                                       go reply.Reply(wm.Msg)
+                                                       return false
+                                               },
+                                               `close`: func(_ *ws.WsMsg) (disable bool) {
+                                                       return true
+                                               },
+                                       })
+                                       <-wsmsg.Pull_tag_chan(`close`, 1, context.Background())
+                                       time.Sleep(time.Second)
                                }
                        }
                        time.Sleep(time.Second)
@@ -360,7 +361,6 @@ func Start() {
                        reply.SaveToJson.Close()
                        reply.StreamOStop(-1)
                }
-               // close(interrupt)
                danmulog.L(`I: `, "结束退出")
        }
 }
index 38ecf8bd457c10e4172ccf7d1567088eded3b1cd..9873466a9fb11ff4fc1313ad5f248120fd6cff0d 100644 (file)
@@ -48,6 +48,7 @@ func Cmd() {
                        fmt.Println("搜索主播->输入' sea关键词'回车")
                        fmt.Println("房间信息->输入' room'回车")
                        fmt.Println("开始结束录制->输入' rec'回车")
+                       fmt.Println("退出当前房间->输入' exit'回车")
                        fmt.Println("其他输出隔断不影响")
                        fmt.Print("\n")
                } else if inputs[0] == 27 { //屏蔽功能键
@@ -157,6 +158,14 @@ func Cmd() {
 
                                continue
                        }
+                       //退出当前房间
+                       if strings.Contains(inputs, ` exit`) && c.C.Roomid != 0 {
+                               cmdlog.L(`I: `, "退出房间", c.C.Roomid)
+                               reply.StreamOStop(c.C.Roomid)
+                               c.C.Roomid = 0
+                               c.C.Danmu_Main_mq.Push_tag(`exit_room`, nil)
+                               continue
+                       }
                        //重载弹幕
                        if strings.Contains(inputs, ` reload`) && c.C.Roomid != 0 {
                                c.C.Danmu_Main_mq.Push_tag(`flash_room`, nil)
diff --git a/go.mod b/go.mod
index 9e8a7621d3488386c3c5fc83075b379c1935932b..3bab44558e91db09546c801e2cd9d7a2cd26792a 100644 (file)
--- a/go.mod
+++ b/go.mod
@@ -5,7 +5,7 @@ go 1.20
 require (
        github.com/gotk3/gotk3 v0.6.2
        github.com/mdp/qrterminal/v3 v3.0.0
-       github.com/qydysky/part v0.25.2
+       github.com/qydysky/part v0.26.2
        github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
        github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
        golang.org/x/text v0.9.0
@@ -47,7 +47,7 @@ require (
        github.com/yusufpapurcu/wmi v1.2.2 // indirect
        golang.org/x/mod v0.10.0 // indirect
        golang.org/x/net v0.9.0 // indirect
-       golang.org/x/sys v0.7.0 // indirect
+       golang.org/x/sys v0.8.0 // indirect
        golang.org/x/tools v0.8.0 // indirect
        gopkg.in/yaml.v3 v3.0.1 // indirect
        modernc.org/sqlite v1.22.1
diff --git a/go.sum b/go.sum
index 21f30b4f97e6a902112971e93f52cf3ab14de9b2..47c8fe64bd86327de18d449d6704d81604e163ac 100644 (file)
--- a/go.sum
+++ b/go.sum
@@ -40,6 +40,12 @@ github.com/qydysky/part v0.25.1 h1:/Y+ywM79DIVhhd6pYSdHVvZRz641eJvnpqL317DheDE=
 github.com/qydysky/part v0.25.1/go.mod h1:8Rn6RC+170YRrtgssAumk8/r68+YH3F45J4l6F6+Fl4=
 github.com/qydysky/part v0.25.2 h1:kyLm5pqy9IrQqjEKj3xtyr97lfDtRJSyO+Pbd1sq+eI=
 github.com/qydysky/part v0.25.2/go.mod h1:IEMpGB0NBl6MklZmoenSpS5ChhaIL79JYFo6mF1UkAU=
+github.com/qydysky/part v0.26.0 h1:ZicQ2atzgJdyOvtlCLQxbSaar0xYEtf0zXpUHAgfkZg=
+github.com/qydysky/part v0.26.0/go.mod h1:IEMpGB0NBl6MklZmoenSpS5ChhaIL79JYFo6mF1UkAU=
+github.com/qydysky/part v0.26.1 h1:DuEjWevYrz//J9sFqZ1Y52DzUryhPQYLOHAWAHvGEBg=
+github.com/qydysky/part v0.26.1/go.mod h1:IEMpGB0NBl6MklZmoenSpS5ChhaIL79JYFo6mF1UkAU=
+github.com/qydysky/part v0.26.2 h1:sAVn7m/NMovy4rD2uWLvOl5MtNaun2imtWD6R8zayPk=
+github.com/qydysky/part v0.26.2/go.mod h1:IEMpGB0NBl6MklZmoenSpS5ChhaIL79JYFo6mF1UkAU=
 github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
 github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
 github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
@@ -71,6 +77,8 @@ golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
 golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
+golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
 golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
 golang.org/x/tools v0.8.0 h1:vSDcovVPld282ceKgDimkRSC8kpaH1dgyc9UMzlt84Y=