feat: 在 MsgInHandler 中添加 Panic 恢复日志记录,并在出现 Panic 时发送警告消息
This commit is contained in:
parent
49be7aafb9
commit
546f1abcd1
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user