Documentation ¶
Overview ¶
Package gateway contains a gateway client and event handlers. Sadly, thanks to how Revolt sends events, gateway clients also need a cache, so it doesn't work completely standalone.
Index ¶
- Constants
- Variables
- type ChannelCreateEvent
- type ChannelStartTypingEvent
- type ChannelStopTypingEvent
- type ChannelUpdateEvent
- type ChannelUpdateEventData
- type DisconnectEvent
- type Gateway
- type Handler
- func (h *Handler) AddHandler(handler interface{}) (rm func())
- func (h *Handler) AddHandlerCheck(handler interface{}) (rm func(), err error)
- func (h *Handler) AddSyncHandler(handler interface{}) (rm func())
- func (h *Handler) AddSyncHandlerCheck(handler interface{}) (rm func(), err error)
- func (h *Handler) Call(ev interface{})
- func (h *Handler) ChanFor(fn func(interface{}) bool) (out <-chan interface{}, cancel func())
- func (h *Handler) WaitFor(ctx context.Context, fn func(interface{}) bool) interface{}
- type MessageDeleteEvent
- type MessageEvent
- type MessageUpdateEvent
- type ReadyEvent
- type UnknownEvent
Constants ¶
const ( ErrUnlabeled = errors.Sentinel("unlabeled error") ErrInternalError = errors.Sentinel("internal error") ErrInvalidSession = errors.Sentinel("invalid session") ErrOnboardingNotFinished = errors.Sentinel("onboarding not finished") ErrAlreadyAuthenticated = errors.Sentinel("already authenticated") )
Authentication errors
const ErrNotAuthenticatedEvent = errors.Sentinel("first event wasn't Authenticated")
ErrNotAuthenticatedEvent is returned when the first event from the websocket isn't the Authenticated or Error event.
const ErrWSAlreadyOpen = errors.Sentinel("websocket already opened")
ErrWSAlreadyOpen is returned when you attempt to open a websocket that already is open.
Variables ¶
var StoreDebug = func(tmpl string, args ...interface{}) {
return
}
StoreDebug is called for store debug logging.
var WSDebug = func(tmpl string, args ...interface{}) {
return
}
WSDebug is called for websocket debug logging.
Functions ¶
This section is empty.
Types ¶
type ChannelStartTypingEvent ¶
type ChannelStartTypingEvent struct { ChannelID string `json:"channel_id"` UserID string `json:"user"` }
ChannelStartTypingEvent ...
type ChannelStopTypingEvent ¶
type ChannelStopTypingEvent struct { ChannelID string `json:"channel_id"` UserID string `json:"user"` }
ChannelStopTypingEvent ...
type ChannelUpdateEvent ¶
type ChannelUpdateEvent struct { ID string `json:"id"` Data ChannelUpdateEventData `json:"data"` Clear string `json:"clear,omitempty"` }
ChannelUpdateEvent ...
func (ChannelUpdateEvent) Update ¶
func (ev ChannelUpdateEvent) Update(ch *revolt.Channel)
Update updates the given channel with data from the event.
type ChannelUpdateEventData ¶
type ChannelUpdateEventData struct { Type *string `json:"channel_type,omitempty"` Name *string `json:"name,omitempty"` Icon *revolt.Attachment `json:"icon,omitempty"` NSFW *bool `json:"nsfw,omitempty"` Description *string `json:"description,omitempty,omitempty"` LastMessageID *string `json:"last_message_id,omitempty"` // Only in groups Permissions *uint64 `json:"permissions,omitempty"` // Only in servers DefaultPermissions *uint64 `json:"default_permissions,omitempty"` RolePermissions map[string]uint64 `json:"role_permissions,omitempty"` // If a DM, whether it's active DMActive *bool `json:"active,omitempty"` // If a group, the owner's ID GroupOwnerID *string `json:"owner,omitempty"` Recipients *[]string `json:"recipients,omitempty"` }
ChannelUpdateEventData ...
type DisconnectEvent ¶
type DisconnectEvent struct{}
DisconnectEvent is emitted when the gateway connection is closed.
type Gateway ¶
type Gateway struct { Handler *Handler Store store.Store LastPing, LastPong time.Time // if the time since the last pong is larger than this, trigger a gateway reconnect // default: 3 minutes MaximumPong time.Duration sync.RWMutex // contains filtered or unexported fields }
Gateway is a gateway client.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is a container for command handlers. A zero-value instance is a valid instance.
func (*Handler) AddHandler ¶
func (h *Handler) AddHandler(handler interface{}) (rm func())
AddHandler adds the handler, returning a function that would remove this handler when called. A handler type is either a single-argument no-return function or a channel.
Function ¶
A handler can be a function with a single argument that is the expected event type. It must not have any returns or any other number of arguments.
// An example of a valid function handler. h.AddHandler(func(*gateway.MessageCreateEvent) {})
Channel ¶
A handler can also be a channel. The underlying type that the channel wraps around will be the event type. As such, the type rules are the same as function handlers.
Keep in mind that the user must NOT close the channel. In fact, the channel should not be closed at all. The caller function WILL PANIC if the channel is closed!
When the rm callback that is returned is called, it will also guarantee that all blocking sends will be cancelled. This helps prevent dangling goroutines.
// An example of a valid channel handler. ch := make(chan *gateway.MessageCreateEvent) h.AddHandler(ch)
func (*Handler) AddHandlerCheck ¶
AddHandlerCheck adds the handler, but safe-guards reflect panics with a recoverer, returning the error. Refer to AddHandler for more information.
func (*Handler) AddSyncHandler ¶
func (h *Handler) AddSyncHandler(handler interface{}) (rm func())
AddSyncHandler is a synchronous variant of AddHandler. Handlers added using this method will block the Call method, which is helpful if the user needs to rely on the order of events arriving. Handlers added using this method should not block for very long, as it may clog up other handlers.
func (*Handler) AddSyncHandlerCheck ¶
AddSyncHandlerCheck is the safe-guarded version of AddSyncHandler. It is similar to AddHandlerCheck.
func (*Handler) Call ¶
func (h *Handler) Call(ev interface{})
Call calls all handlers with the given event. This is an internal method; use with care.
func (*Handler) ChanFor ¶
ChanFor returns a channel that would receive all incoming events that match the callback given. The cancel() function removes the handler and drops all hanging goroutines.
This method is more intended to be used as a filter. For a persistent event channel, consider adding it directly as a handler with AddHandler.
type MessageDeleteEvent ¶
MessageDeleteEvent ...
type MessageUpdateEvent ¶
MessageUpdateEvent ...
type ReadyEvent ¶
type ReadyEvent struct { Users []revolt.User `json:"users"` Servers []revolt.Server `json:"servers"` Channels []revolt.Channel `json:"channels"` }
ReadyEvent ...
type UnknownEvent ¶
UnknownEvent is emitted when an unknown event is received.