1
0
mirror of https://github.com/fumiama/ReiBot.git synced 2026-06-10 13:00:40 +08:00
This commit is contained in:
源文雨
2022-05-31 21:09:38 +08:00
parent caaf7035d9
commit e37701840d
8 changed files with 297 additions and 0 deletions

38
event.go Normal file
View File

@@ -0,0 +1,38 @@
package rei
import (
"log"
"reflect"
"unsafe"
tgba "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)
// Event ...
type Event struct {
// Type is the non-null field name in Update
Type string
// UpdateID is the update's unique identifier.
UpdateID int
// Value is the non-null field value in Update
Value reflect.Value
}
func (tc *TelegramClient) processEvent(update tgba.Update) {
v := reflect.ValueOf(&update).Elem()
t := reflect.ValueOf(&update).Elem().Type()
h := reflect.ValueOf(tc.b.Handler)
for i := 1; i < v.NumField(); i++ {
f := v.Field(i)
if f.IsZero() {
continue
}
m := h.FieldByName("On" + t.Field(i).Name)
if m.IsZero() {
continue
}
log.Println("[INFO] processEvent call", "On"+t.Field(i).Name)
handler := m.Interface()
go (*(*GeneralHandleType)(unsafe.Add(unsafe.Pointer(&handler), unsafe.Sizeof(uintptr(0)))))(update.UpdateID, tc, f.UnsafePointer())
}
}