Documentation ¶
Index ¶
- Variables
- type Base
- type ChannelCreateEvent
- type ChannelDeleteEvent
- type ChannelPinsUpdateEvent
- type ChannelUnreadUpdateEvent
- type ChannelUpdateEvent
- type CloseEvent
- type EventHandler
- func (h *EventHandler) AddHandler(handler interface{}, middlewares ...interface{}) (rm func(), err error)
- func (h *EventHandler) AddHandlerOnce(handler interface{}, middlewares ...interface{}) error
- func (h *EventHandler) AddMiddleware(f interface{}) error
- func (h *EventHandler) AutoAddHandlers(scan interface{}, middlewares ...interface{})
- func (h *EventHandler) Call(e interface{})
- func (h *EventHandler) Close()
- func (h *EventHandler) DeriveIntents() (i gateway.Intents)
- func (h *EventHandler) MustAddHandler(handler interface{}, middlewares ...interface{}) func()
- func (h *EventHandler) MustAddHandlerOnce(handler interface{}, middlewares ...interface{})
- func (h *EventHandler) MustAddMiddleware(f interface{})
- func (h *EventHandler) Open(events <-chan interface{})
- type GuildAvailableEvent
- type GuildBanAddEvent
- type GuildBanRemoveEvent
- type GuildCreateEvent
- type GuildDeleteEvent
- type GuildEmojisUpdateEvent
- type GuildIntegrationsUpdateEvent
- type GuildJoinEvent
- type GuildLeaveEvent
- type GuildMemberAddEvent
- type GuildMemberRemoveEvent
- type GuildMemberUpdateEvent
- type GuildMembersChunkEvent
- type GuildReadyEvent
- type GuildRoleCreateEvent
- type GuildRoleDeleteEvent
- type GuildRoleUpdateEvent
- type GuildUnavailableEvent
- type GuildUpdateEvent
- type InviteCreateEvent
- type InviteDeleteEvent
- type MessageAckEvent
- type MessageCreateEvent
- type MessageDeleteBulkEvent
- type MessageDeleteEvent
- type MessageReactionAddEvent
- type MessageReactionRemoveAllEvent
- type MessageReactionRemoveEmojiEvent
- type MessageReactionRemoveEvent
- type MessageUpdateEvent
- type PresenceUpdateEvent
- type PresencesReplaceEvent
- type ReadyEvent
- type RelationshipAddEvent
- type RelationshipRemoveEvent
- type SessionsReplaceEvent
- type State
- func CloneMocker(m *dismock.Mocker, t *testing.T) (*dismock.Mocker, *State)
- func New(token string) (*State, error)
- func NewFromSession(s *session.Session, cabinet store.Cabinet) (st *State)
- func NewFromState(s *state.State) (st *State)
- func NewMocker(t *testing.T) (*dismock.Mocker, *State)
- func NewWithCabinet(token string, cabinet store.Cabinet) (*State, error)
- func NewWithIntents(token string, intents ...gateway.Intents) (*State, error)
- type TypingStartEvent
- type UserGuildSettingsUpdateEvent
- type UserNoteUpdateEvent
- type UserSettingsUpdateEvent
- type UserUpdateEvent
- type VoiceServerUpdateEvent
- type VoiceStateUpdateEvent
- type WebhooksUpdateEvent
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidHandler gets returned if a handler given to // EventManager.AddHandler or EventManager.MustAddHandler is not a valid // handler func, i.e. not following the form of func(*State, e) where e is // either a pointer to an event, *Base or interface{}. ErrInvalidHandler = errors.New("state: the passed interface{} does not resemble a valid handler") // ErrInvalidMiddleware gets returned if a middleware given to // EventManger.AddHandler or EventManager.MustAddHandler has not the same // type as its handler. // // Additionally, it is returned by AddMiddleware and // MustAddMiddleware if the middleware func is invalid. ErrInvalidMiddleware = errors.New("state: the passed middleware does not match the type of the handler") // Filtered should be returned if a filter blocks an event. Filtered = errors.New("filtered") //nolint:golint,stylecheck )
Functions ¶
This section is empty.
Types ¶
type Base ¶
type Base struct {
// contains filtered or unexported fields
}
Base is the base of all events.
func (*Base) Get ¶
func (b *Base) Get(key interface{}) (val interface{})
Get gets the element with the passed key.
type ChannelCreateEvent ¶
type ChannelCreateEvent struct { *gateway.ChannelCreateEvent *Base }
https://discord.com/developers/docs/topics/gateway#channel-create
type ChannelDeleteEvent ¶
type ChannelDeleteEvent struct { *gateway.ChannelDeleteEvent *Base Old *discord.Channel }
https://discord.com/developers/docs/topics/gateway#channel-delete
type ChannelPinsUpdateEvent ¶
type ChannelPinsUpdateEvent struct { *gateway.ChannelPinsUpdateEvent *Base }
https://discord.com/developers/docs/topics/gateway#channel-pins-update
type ChannelUnreadUpdateEvent ¶
type ChannelUnreadUpdateEvent struct { *gateway.ChannelUnreadUpdateEvent *Base }
type ChannelUpdateEvent ¶
type ChannelUpdateEvent struct { *gateway.ChannelUpdateEvent *Base Old *discord.Channel }
https://discord.com/developers/docs/topics/gateway#channel-update
type CloseEvent ¶
type CloseEvent struct {
*Base
}
CloseEvent gets dispatched when the gateway closes.
type EventHandler ¶
type EventHandler struct { ErrorHandler func(err error) PanicHandler func(err interface{}) // contains filtered or unexported fields }
func NewEventHandler ¶
func NewEventHandler(s *State) *EventHandler
NewEventHandler creates a new EventHandler.
func (*EventHandler) AddHandler ¶
func (h *EventHandler) AddHandler(handler interface{}, middlewares ...interface{}) (rm func(), err error)
AddHandler adds a handler with the passed middlewares to the event handlers. A handler can either be a function, or a channel of type chan *eventType. Note, however, that channel sends are non-blocking, and you must either buffer your channel sufficiently, or ensure you are listening.
The signature of a handler func is func(*State, e) where e is either a pointer to an event, *Base or interface{}. Optionally, a handler may return an error.
Middlewares must be of the same type as the handlers or must be an interface{} or Base handlers.
func (*EventHandler) AddHandlerOnce ¶ added in v3.1.0
func (h *EventHandler) AddHandlerOnce(handler interface{}, middlewares ...interface{}) error
AddHandlerOnce adds a handler that is only executed once. If middlewares prevent execution, the handler will be executed on the next event.
func (*EventHandler) AddMiddleware ¶
func (h *EventHandler) AddMiddleware(f interface{}) error
AddMiddleware adds the passed middleware as a global middleware.
The signature of a middleware func is func(*State, e) where e is either a pointer to an event, *Base or interface{}. Optionally, a middleware may return an error.
func (*EventHandler) AutoAddHandlers ¶
func (h *EventHandler) AutoAddHandlers(scan interface{}, middlewares ...interface{})
AutoAddHandlers adds all handlers methods of the passed struct to the EventHandler. scan must be a pointer to a struct.
func (*EventHandler) Call ¶
func (h *EventHandler) Call(e interface{})
Call can be used to manually dispatch an event. For this to succeed, e must be a pointer to an event, and it's Base field must be set.
func (*EventHandler) Close ¶
func (h *EventHandler) Close()
Close stops the event listener and blocks until all handlers have finished executing.
func (*EventHandler) DeriveIntents ¶
func (h *EventHandler) DeriveIntents() (i gateway.Intents)
DeriveIntents derives the intents based on the event handlers and global middlewares that were added. Interface and Base handlers will not be taken into account.
Note that this does not reflect the intents needed to enable caching for API calls made anywhere in code.
func (*EventHandler) MustAddHandler ¶
func (h *EventHandler) MustAddHandler(handler interface{}, middlewares ...interface{}) func()
MustAddHandler is the same as AddHandler, but panics if AddHandler returns an error.
func (*EventHandler) MustAddHandlerOnce ¶ added in v3.1.0
func (h *EventHandler) MustAddHandlerOnce(handler interface{}, middlewares ...interface{})
MustAddHandlerOnce is the same as AddHandlerOnce, but panics if AddHandlerOnce returns an error.
func (*EventHandler) MustAddMiddleware ¶
func (h *EventHandler) MustAddMiddleware(f interface{})
MustAddMiddleware is the same as AddMiddleware but panics if AddMiddleware returns an error.
func (*EventHandler) Open ¶
func (h *EventHandler) Open(events <-chan interface{})
Open starts listening for events until the returned closer function is called.
type GuildAvailableEvent ¶
type GuildAvailableEvent struct {
*GuildCreateEvent
}
GuildAvailableEvent is a situation-specific GuildCreate event. It gets fired when a guild becomes available, after getting marked unavailable during a GuildUnavailableEvent event. This event will not be fired for guilds that were already unavailable when initially connecting.
type GuildBanAddEvent ¶
type GuildBanAddEvent struct { *gateway.GuildBanAddEvent *Base }
https://discord.com/developers/docs/topics/gateway#guild-ban-add
type GuildBanRemoveEvent ¶
type GuildBanRemoveEvent struct { *gateway.GuildBanRemoveEvent *Base }
https://discord.com/developers/docs/topics/gateway#guild-ban-remove
type GuildCreateEvent ¶
type GuildCreateEvent struct { *gateway.GuildCreateEvent *Base }
https://discord.com/developers/docs/topics/gateway#guild-create
Note that this event will not be sent in Base and All handlers. Instead, the situation-specific sub-events will be sent.
type GuildDeleteEvent ¶
type GuildDeleteEvent struct { *gateway.GuildDeleteEvent *Base Old *discord.Guild }
https://discord.com/developers/docs/topics/gateway#guild-delete
Note that this event will not be sent in Base and All handlers. Instead, the situation-specific sub-events will be sent.
type GuildEmojisUpdateEvent ¶
type GuildEmojisUpdateEvent struct { *gateway.GuildEmojisUpdateEvent *Base Old []discord.Emoji }
https://discord.com/developers/docs/topics/gateway#guild-emojis-update
type GuildIntegrationsUpdateEvent ¶
type GuildIntegrationsUpdateEvent struct { *gateway.GuildIntegrationsUpdateEvent *Base }
https://discord.com/developers/docs/topics/gateway#guild-integrations-update
type GuildJoinEvent ¶
type GuildJoinEvent struct {
*GuildCreateEvent
}
GuildJoinEvent is a situation-specific GuildCreate event. It gets fired when the user/bot joins a guild.
type GuildLeaveEvent ¶
type GuildLeaveEvent struct {
*GuildDeleteEvent
}
GuildLeaveEvent is a situation-specific GuildDeleteEvent event. It gets fired when the user/bot leaves guild, gets kicked/banned from it, or the owner deletes it.
type GuildMemberAddEvent ¶
type GuildMemberAddEvent struct { *gateway.GuildMemberAddEvent *Base }
https://discord.com/developers/docs/topics/gateway#guild-member-add
type GuildMemberRemoveEvent ¶
type GuildMemberRemoveEvent struct { *gateway.GuildMemberRemoveEvent *Base Old *discord.Member }
https://discord.com/developers/docs/topics/gateway#guild-member-remove
type GuildMemberUpdateEvent ¶
type GuildMemberUpdateEvent struct { *gateway.GuildMemberUpdateEvent *Base Old *discord.Member }
https://discord.com/developers/docs/topics/gateway#guild-member-update
type GuildMembersChunkEvent ¶
type GuildMembersChunkEvent struct { *gateway.GuildMembersChunkEvent *Base }
https://discord.com/developers/docs/topics/gateway#guild-members-chunk
type GuildReadyEvent ¶
type GuildReadyEvent struct {
*GuildCreateEvent
}
GuildReadyEvent is a situation-specific GuildCreate event. It gets fired during Ready for all available guilds. Additionally, it gets fired for all those guilds that become available after initially connecting, but were not during Ready.
type GuildRoleCreateEvent ¶
type GuildRoleCreateEvent struct { *gateway.GuildRoleCreateEvent *Base }
https://discord.com/developers/docs/topics/gateway#guild-role-create
type GuildRoleDeleteEvent ¶
type GuildRoleDeleteEvent struct { *gateway.GuildRoleDeleteEvent *Base Old *discord.Role }
https://discord.com/developers/docs/topics/gateway#guild-role-delete
type GuildRoleUpdateEvent ¶
type GuildRoleUpdateEvent struct { *gateway.GuildRoleUpdateEvent *Base Old *discord.Role }
https://discord.com/developers/docs/topics/gateway#guild-role-update
type GuildUnavailableEvent ¶
type GuildUnavailableEvent struct {
}GuildUnavailableEvent is a situation-specific GuildDeleteEvent event. It gets fired if the guild becomes unavailable, e.g. through a discord outage.
type GuildUpdateEvent ¶
type GuildUpdateEvent struct { *gateway.GuildUpdateEvent *Base Old *discord.Guild }
https://discord.com/developers/docs/topics/gateway#guild-update
Note that this event will not be sent in Base and All handlers. Instead, the situation-specific sub-events will be sent.
type InviteCreateEvent ¶
type InviteCreateEvent struct { *gateway.InviteCreateEvent *Base }
https://discord.com/developers/docs/topics/gateway#invite-create
type InviteDeleteEvent ¶
type InviteDeleteEvent struct { *gateway.InviteDeleteEvent *Base }
https://discord.com/developers/docs/topics/gateway#invite-delete
type MessageAckEvent ¶
type MessageAckEvent struct { *gateway.MessageAckEvent *Base }
https://discord.com/developers/docs/topics/gateway#message-ack
type MessageCreateEvent ¶
type MessageCreateEvent struct { *gateway.MessageCreateEvent *Base }
https://discord.com/developers/docs/topics/gateway#message-create
type MessageDeleteBulkEvent ¶
type MessageDeleteBulkEvent struct { *gateway.MessageDeleteBulkEvent *Base Old []discord.Message }
https://discord.com/developers/docs/topics/gateway#message-delete-bulk
type MessageDeleteEvent ¶
type MessageDeleteEvent struct { *gateway.MessageDeleteEvent *Base Old *discord.Message }
https://discord.com/developers/docs/topics/gateway#message-delete
type MessageReactionAddEvent ¶
type MessageReactionAddEvent struct { *gateway.MessageReactionAddEvent *Base }
https://discord.com/developers/docs/topics/gateway#message-reaction-add
type MessageReactionRemoveAllEvent ¶
type MessageReactionRemoveAllEvent struct { *gateway.MessageReactionRemoveAllEvent *Base }
https://discord.com/developers/docs/topics/gateway#message-reaction-remove-all
type MessageReactionRemoveEmojiEvent ¶
type MessageReactionRemoveEmojiEvent struct { *gateway.MessageReactionRemoveEmojiEvent *Base }
https://discord.com/developers/docs/topics/gateway#message-reaction-remove-emoji
type MessageReactionRemoveEvent ¶
type MessageReactionRemoveEvent struct { *gateway.MessageReactionRemoveEvent *Base }
https://discord.com/developers/docs/topics/gateway#message-reaction-remove
type MessageUpdateEvent ¶
type MessageUpdateEvent struct { *gateway.MessageUpdateEvent *Base Old *discord.Message }
https://discord.com/developers/docs/topics/gateway#message-update
type PresenceUpdateEvent ¶
type PresenceUpdateEvent struct { *gateway.PresenceUpdateEvent *Base Old *gateway.Presence }
https://discord.com/developers/docs/topics/gateway#presence-update
type PresencesReplaceEvent ¶
type PresencesReplaceEvent struct { *gateway.PresencesReplaceEvent *Base }
undocumented
type ReadyEvent ¶
type ReadyEvent struct { *gateway.ReadyEvent *Base }
type RelationshipAddEvent ¶
type RelationshipAddEvent struct { *gateway.RelationshipAddEvent *Base }
undocumented
type RelationshipRemoveEvent ¶
type RelationshipRemoveEvent struct { *gateway.RelationshipRemoveEvent *Base }
undocumented
type SessionsReplaceEvent ¶
type SessionsReplaceEvent struct { *gateway.SessionsReplaceEvent *Base }
SessionsReplaceEvent is an undocumented user event. It's likely used for current user's presence updates.
type State ¶
type State struct { *state.State *EventHandler // contains filtered or unexported fields }
func CloneMocker ¶
CloneMocker clones the passed dismock.Mocker and returns a new mocker and mocked State.
func New ¶
New creates a new State using the passed token. If creating a bot session, the token must start with 'Bot '.
func NewFromSession ¶
NewFromSession creates a new *State from the passed Session. The Session may not be opened.
func NewFromState ¶
NewFromState creates a new State based on a arikawa State. Event handlers from the old state won't be copied.
func NewWithCabinet ¶
NewWithCabinet creates a new State with a custom state.Store.
func NewWithIntents ¶
NewWithIntents creates a new State with the given gateway intents using the passed token. If creating a bot session, the token must start with 'Bot '. For more information, refer to gateway.Intents.
func (*State) AddIntents ¶ added in v3.1.0
AddIntents adds the passed intents to the state.
type TypingStartEvent ¶
type TypingStartEvent struct { *gateway.TypingStartEvent *Base }
https://discord.com/developers/docs/topics/gateway#typing-start
type UserGuildSettingsUpdateEvent ¶
type UserGuildSettingsUpdateEvent struct { *gateway.UserGuildSettingsUpdateEvent *Base }
undocumented
type UserNoteUpdateEvent ¶
type UserNoteUpdateEvent struct { *gateway.UserNoteUpdateEvent *Base }
undocumented
type UserSettingsUpdateEvent ¶
type UserSettingsUpdateEvent struct { *gateway.UserSettingsUpdateEvent *Base }
undocumented
type UserUpdateEvent ¶
type UserUpdateEvent struct { *gateway.UserUpdateEvent *Base }
https://discord.com/developers/docs/topics/gateway#user-update
type VoiceServerUpdateEvent ¶
type VoiceServerUpdateEvent struct { *gateway.VoiceServerUpdateEvent *Base }
https://discord.com/developers/docs/topics/gateway#voice-server-update
type VoiceStateUpdateEvent ¶
type VoiceStateUpdateEvent struct { *gateway.VoiceStateUpdateEvent *Base }
https://discord.com/developers/docs/topics/gateway#voice-state-update
type WebhooksUpdateEvent ¶
type WebhooksUpdateEvent struct { *gateway.WebhooksUpdateEvent *Base }
https://discord.com/developers/docs/topics/gateway#webhooks-update