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