Пример #1
0
func recoverCb(cb guiniol.CallbackFunc) guiniol.Callback {
	return guiniol.CallbackFunc(func(ctx context.Context, eventCtx *guiniol.EventCtx) {
		defer func() {
			if err := recover(); err != nil {
				e := newEvent(ctx, eventCtx, "")
				e.Reply(fmt.Sprintf("%v", err))
			}
		}()

		cb.Next(ctx, eventCtx)
	})
}
Пример #2
0
func Wrap(fn guiniol.CallbackFunc) guiniol.Callback {
	return guiniol.CallbackFunc(func(c context.Context, e *guiniol.EventCtx) {
		if e.MessageEvent().Subtype == "bot_message" {
			return
		}

		name, m := matcher(e)
		if name != e.UserName() && name != e.UserId() {
			return
		}

		c = context.WithValue(c, MessageKey, m)

		fn.Next(c, e)
	})
}