-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.go
45 lines (41 loc) 路 1.58 KB
/
event.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Package event provides wrappers around arikawa's events as well as a custom
// event handler.
//
// Event Handler
//
// disstate's event handler expands the functionality of arikawa's built-in
// handler system.
// It adds support for middlewares both on a global level and a per-handler
// level.
//
// Furthermore, *state.State is the first parameter of all events, to allow
// access to the state without wrapping functions.
// Optionally, handler functions may also return an error that is handled
// by the event handler's ErrorHandler function.
// Similarly, the event handler will also recover from panics and handle them
// using the event handler's PanicHandler function.
//
// Event Types
//
// Wrapped events have two key differences in comparison to their arikawa
// counterparts.
//
// Firstly, they embed a *Base that contains a key-value-store similar to that
// of context.Context.
// This allows to share state between middlewares and handlers.
//
// Secondly, some events have an Old field, containing the state of event's
// entity prior to when the event was received.
// The Old field will obviously only be filled, if the enitity was previously
// cached.
// This functionality replaces arikawa's PreHandler system and allows handlers
// to work with both the previous and the current entity, something impossible
// with arikawa's system.
package event
import "reflect"
//go:generate go run ../../tools/codegen/event/event.go
var (
interfaceType = reflect.TypeOf((*interface{})(nil)).Elem()
baseType = reflect.TypeOf(new(Base))
errorType = reflect.TypeOf((*error)(nil)).Elem()
)