1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-05 11:33:48 +08:00

support event recover.

This commit is contained in:
Mrs4s 2020-12-09 14:24:39 +08:00
parent d07e1ee77a
commit e694e8b482

View File

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"hash/crc32" "hash/crc32"
"path" "path"
"runtime/debug"
"sync" "sync"
"time" "time"
@ -397,6 +398,11 @@ func (bot *CQBot) dispatchEventMessage(m MSG) {
} }
for _, f := range bot.events { for _, f := range bot.events {
go func(fn func(MSG)) { go func(fn func(MSG)) {
defer func() {
if pan := recover(); pan != nil {
log.Warnf("处理事件 %v 时出现错误: %v \n%s", m, pan, debug.Stack())
}
}()
start := time.Now() start := time.Now()
fn(m) fn(m)
end := time.Now() end := time.Now()