This commit refactors the whole package gateway as well as utils/ws
(formerly utils/wsutil) and voice/voicegateway. The new refactor
utilizes a design pattern involving a concurrent loop and an arriving
event channel.
An additional change was made to the way gateway events are typed.
Before, pretty much any type will satisfy a gateway event type, since
the actual type was just interface{}. The new refactor defines a
concrete interface that events can implement:
type Event interface {
Op() OpCode
EventType() EventType
}
Using this interface, the user can easily add custom gateway events
independently of the library without relying on string maps. This adds a
lot of type safety into the library and makes type-switching on Event
types much more reasonable.
Gateway error callbacks are also almost entirely removed in favor of
custom gateway events. A catch-all can easily be added like this:
s.AddHandler(func(err error) {
log.Println("gateway error:, err")
})
This commit refactors a lot of packages.
It refactors the handler package, removing the Synchronous field and
replacing it the AddSyncHandler API, which allows each handler to
control whether or not it should be ran synchronously independent of
other handlers. This is useful for libraries that need to guarantee the
incoming order of events.
It also refactors the store interfaces to accept more interfaces. This
is to make the API more consistent as well as reducing potential useless
copies. The public-facing state API should still be the same, so this
change will mostly concern users with their own store implementations.
Several miscellaneous functions (such as a few in package gateway) were
modified to be more suitable to other packages, but those functions
should rarely ever be used, anyway.
Several tests are also fixed within this commit, namely fixing state's
intents bug.
* Store,State: Add update param to all store.XXXStore.XXXSet methods
* State: add paginating Messages
* Store: Fix test error
* store: merge shouldPrependMessage and shouldAppendMessage into single messageInsertPosition
This commit refactors the Store interface in State into smaller
interfaces in package store. These interfaces are combined into one
structure called a "Cabinet". The default implementation of those
interfaces have been rewritten in package defaultstore, while the old
no-op implementation stays with the store package.
This commit also omitted several state handlers for user events, as it
is unclear what they are actually structured like.
This addresses discord/discord-api-docs#1440.
State documentation has been added, which documents the store and
handlers as well.
Bug fixes include:
- PreHandler being called after the state handler; it is now called
before as documented.
- Minor behavior changes regarding Guild Create events. Refer to State's
documentation.