1
0
mirror of https://github.com/fumiama/NanoBot.git synced 2026-06-18 01:33:00 +08:00

finish handler

This commit is contained in:
源文雨
2023-10-15 17:12:16 +09:00
parent 6a42e70f55
commit 354ceb10c0
5 changed files with 111 additions and 57 deletions

28
event.go Normal file
View File

@@ -0,0 +1,28 @@
package nano
import (
"encoding/json"
"reflect"
log "github.com/sirupsen/logrus"
)
// processEvent 处理需要关注的业务事件
func (bot *Bot) processEvent(payload *WebsocketPayload) {
tp := UnderlineToCamel(payload.T)
if bot.Handler != nil {
ev, ok := bot.handlers[tp]
if !ok {
return
}
log.Debugln(getLogHeader(), "使用 handlers 处理", tp, "事件")
x := reflect.New(ev.t)
err := json.Unmarshal(payload.D, x.Interface())
if err != nil {
log.Warnln(getLogHeader(), "解析", tp, "事件时出现错误:", err)
return
}
go ev.h(payload.S, bot, x.UnsafePointer())
return
}
}