Documentation ¶
Overview ¶
Package advancedevents provides a much more advanced event and error handling framework for events
Index ¶
- func Wrap[T events.EventInterface](evt func(w *gateway.GatewayClient, ctx *gateway.EventContext, e *T), ...) func(w *gateway.GatewayClient, ctx *gateway.EventContext, e *T)
- func WrapEnd[T events.EventInterface](evt func(w *gateway.GatewayClient, ctx *gateway.EventContext, e *T), ...) func(w *gateway.GatewayClient, ctx *gateway.EventContext, e *T)
- type ErrorHandler
- type EventFunc
- type EventHandler
- func (ef *EventHandler[T]) Add(fns ...EventHandlerFunc[T]) *EventHandler[T]
- func (ef *EventHandler[T]) AddGlobalErrorHandler(fn ErrorHandler[T]) *EventHandler[T]
- func (ef *EventHandler[T]) AddRaw(fns ...EventFunc[T]) *EventHandler[T]
- func (ef *EventHandler[T]) Build() func(w *gateway.GatewayClient, ctx *gateway.EventContext, e *T)
- type EventHandlerFunc
- type Multi
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Wrap ¶
func Wrap[T events.EventInterface](evt func(w *gateway.GatewayClient, ctx *gateway.EventContext, e *T), funcs ...func(w *gateway.GatewayClient, ctx *gateway.EventContext, e *T)) func(w *gateway.GatewayClient, ctx *gateway.EventContext, e *T)
Wrap a event on top of potential other non-advancedevent events and friends
func WrapEnd ¶
func WrapEnd[T events.EventInterface](evt func(w *gateway.GatewayClient, ctx *gateway.EventContext, e *T), funcs ...func(w *gateway.GatewayClient, ctx *gateway.EventContext, e *T)) func(w *gateway.GatewayClient, ctx *gateway.EventContext, e *T)
Wrap a event below potential other non-advancedevent events and friends
Types ¶
type ErrorHandler ¶
type ErrorHandler[T events.EventInterface] func(w *gateway.GatewayClient, ctx *gateway.EventContext, evt *T, err error, handler EventFunc[T])
type EventFunc ¶
type EventFunc[T events.EventInterface] struct { // The ID of the handler ID string // The handler itself Handler EventHandlerFunc[T] // Error handlers for this specific event handler ErrorHandlers []ErrorHandler[T] }
Event errors
type EventHandler ¶
type EventHandler[T events.EventInterface] struct { // It is recommended to use Add() instead as it is more ergonomic, // but this allows you to set handlers // // If a handler errors, the error will be passed to the error handlers // // No other handlers will be called on error making it useful for db calls and // “on_command_error“ implementations Handlers []EventFunc[T] // Global error handler for the event // // This is per event, not per handler GlobalErrorHandlers []ErrorHandler[T] }
An event function, note that events are loaded *syncronously* so you should make your event handlers accordingly
func NewEventHandler ¶
func NewEventHandler[T events.EventInterface]() *EventHandler[T]
Creates a new event handler
func (*EventHandler[T]) Add ¶
func (ef *EventHandler[T]) Add(fns ...EventHandlerFunc[T]) *EventHandler[T]
Adds an simple event handler
func (*EventHandler[T]) AddGlobalErrorHandler ¶
func (ef *EventHandler[T]) AddGlobalErrorHandler(fn ErrorHandler[T]) *EventHandler[T]
Adds a handler for errors
Type is "func(w *GatewayClient, evt *T, err error, handler EventFunc[T])"
func (*EventHandler[T]) AddRaw ¶
func (ef *EventHandler[T]) AddRaw(fns ...EventFunc[T]) *EventHandler[T]
Adds an event handler
func (*EventHandler[T]) Build ¶
func (ef *EventHandler[T]) Build() func(w *gateway.GatewayClient, ctx *gateway.EventContext, e *T)
type EventHandlerFunc ¶
type EventHandlerFunc[T events.EventInterface] func(w *gateway.GatewayClient, ctx *gateway.EventContext, evt *T) error
type Multi ¶
type Multi[T events.EventInterface] struct { Funcs []func(w *gateway.GatewayClient, ctx *gateway.EventContext, e *T) }
func NewMulti ¶
func NewMulti[T events.EventInterface](evts ...func(w *gateway.GatewayClient, ctx *gateway.EventContext, e *T)) *Multi[T]
Creates a new multi event handler for running multiple event handlers in a single event
"We truly live in a world of wonders" - Tim Cook
func (*Multi[T]) Add ¶
func (m *Multi[T]) Add(f func(w *gateway.GatewayClient, ctx *gateway.EventContext, e *T))
Add a event handler function to a multi
func (*Multi[T]) Build ¶
func (m *Multi[T]) Build() func(w *gateway.GatewayClient, ctx *gateway.EventContext, e *T)