diff --git a/context.go b/context.go index 6c29594..11c661d 100644 --- a/context.go +++ b/context.go @@ -4,6 +4,7 @@ import ( "fmt" "reflect" "sync" + "unsafe" "github.com/wdvxdr1123/ZeroBot/message" ) @@ -26,6 +27,11 @@ func (ctx *Ctx) GetMatcher() *Matcher { return ctx.ma } +// ExposeCaller as *T, maybe panic if misused +func ExposeCaller[T any](ctx *Ctx) *T { + return (*T)(*(*unsafe.Pointer)(unsafe.Add(unsafe.Pointer(&ctx.caller), unsafe.Sizeof(uintptr(0))))) +} + // decoder 反射获取的数据 type decoder []dec