From 546f1abcd1205e12571df1f291e46d7e05edbe7c Mon Sep 17 00:00:00 2001 From: lixiangwuxian Date: Thu, 10 Apr 2025 01:05:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9C=A8=20MsgInHandler=20=E4=B8=AD?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20Panic=20=E6=81=A2=E5=A4=8D=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E8=AE=B0=E5=BD=95=EF=BC=8C=E5=B9=B6=E5=9C=A8=E5=87=BA?= =?UTF-8?q?=E7=8E=B0=20Panic=20=E6=97=B6=E5=8F=91=E9=80=81=E8=AD=A6?= =?UTF-8?q?=E5=91=8A=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- action/action.go | 3 +++ handler/handler.go | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/action/action.go b/action/action.go index fdde0b9..ebd5925 100644 --- a/action/action.go +++ b/action/action.go @@ -3,6 +3,7 @@ package action import ( "encoding/json" "fmt" + "log" "strconv" "sync" "time" @@ -62,6 +63,7 @@ func (am *actionManager) SendMsg(reply *model.Reply) error { for !am.Started() { time.Sleep(100 * time.Millisecond) } + log.Default().Printf("\033[32m↑\033[0m:%s", string(sendPkgJson)) if err = am.botConn.WriteMessage(websocket.TextMessage, sendPkgJson); err != nil { return err } @@ -84,6 +86,7 @@ func (am *actionManager) SendForward(reply *model.Reply) error { if err != nil { return err } + log.Default().Printf("\033[32m↑\033[0m:%s", string(sendPkgJson)) if err = am.botConn.WriteMessage(websocket.TextMessage, sendPkgJson); err != nil { return err } diff --git a/handler/handler.go b/handler/handler.go index 7a2cce1..0ab2df2 100644 --- a/handler/handler.go +++ b/handler/handler.go @@ -8,7 +8,9 @@ import ( "strings" "time" + "git.lxtend.com/qqbot/action" "git.lxtend.com/qqbot/auth" + "git.lxtend.com/qqbot/config" "git.lxtend.com/qqbot/constants" "git.lxtend.com/qqbot/model" ) @@ -95,6 +97,15 @@ func MsgInHandler(msg model.Message) (reply *model.Reply) { errMsg := fmt.Sprintf("[%s] Panic recovered:\nError: %v\nStack Trace:\n%s\n", time.Now().Format("2006-01-02 15:04:05"), r, stack) log.Print(errMsg) + action.ActionManager.SendMsg(&model.Reply{ + ReplyMsg: "出现了Panic:\n" + errMsg, + ReferOriginMsg: false, + FromMsg: model.Message{ + GroupInfo: model.GroupInfo{ + GroupId: config.ConfigManager.GetConfig().Management.ReportGroup, + }, + }, + }) } }() if msg.RawMsg != "" { @@ -104,7 +115,7 @@ func MsgInHandler(msg model.Message) (reply *model.Reply) { } defer func() { if reply != nil { - log.Default().Printf("\033[32m↑\033[0m:%v", reply) + // log.Default().Printf("\033[32m↑\033[0m:%v", reply) } }() if handlerUserID, ok := liveHandlers[msg.GroupInfo.GroupId]; ok {