Documentation
¶
Index ¶
- Variables
- type Base
- type ChannelCreateEvent
- type ChannelDeleteEvent
- type ChannelPinsUpdateEvent
- type ChannelUnreadUpdateEvent
- type ChannelUpdateEvent
- type CloseEvent
- type EventHandler
- func (h *EventHandler) AddGlobalMiddleware(f interface{}) error
- func (h *EventHandler) AddHandler(f interface{}, middlewares ...interface{}) (func(), error)
- func (h *EventHandler) AutoAddHandlers(scan interface{}, middlewares ...interface{})
- func (h *EventHandler) Call(e interface{})
- func (h *EventHandler) Close()
- func (h *EventHandler) MustAddGlobalMiddleware(f interface{})
- func (h *EventHandler) MustAddHandler(f interface{}, middlewares ...interface{}) func()
- 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, store state.Store) (st *State)
- func NewFromState(s *state.State) (st *State)
- func NewMocker(t *testing.T) (*dismock.Mocker, *State)
- func NewWithIntents(token string, intents ...gateway.Intents) (*State, error)
- func NewWithStore(token string, store state.Store) (*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("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 AddGlobalMiddleware and // MustAddGlobalMiddleware if the middleware func is invalid. ErrInvalidMiddleware = errors.New("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") )
Functions ¶
This section is empty.
Types ¶
type Base ¶
type Base struct {
// contains filtered or unexported fields
}
Base is the base of all events.
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) AddGlobalMiddleware ¶
func (h *EventHandler) AddGlobalMiddleware(f interface{}) error
AddGlobalMiddleware adds the passed middleware as a global middleware.
The scheme 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) AddHandler ¶
func (h *EventHandler) AddHandler(f interface{}, middlewares ...interface{}) (func(), error)
AddHandler adds a handlers with the passed globalMiddlewares to the event handlers.
Middlewares must be of the same type as the handlers or must be an interface{} or Base handlers.
The scheme 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.
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()
func (*EventHandler) MustAddGlobalMiddleware ¶
func (h *EventHandler) MustAddGlobalMiddleware(f interface{})
MustAddGlobalMiddleware is the same as AddGlobalMiddleware but panics if AddGlobalMiddleware returns an error.
func (*EventHandler) MustAddHandler ¶
func (h *EventHandler) MustAddHandler(f interface{}, middlewares ...interface{}) func()
MustAddHandler is the same as AddHandler, but panics if AddHandler 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.MessageReactionRemoveEmoji *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 *discord.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 Ready *gateway.ReadyEvent StateLog func(error) // contains filtered or unexported fields }
func CloneMocker ¶
CloneMocker clones the passed mocker and returns a new dismock.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 ¶ added in v2.1.0
NewFromState creates a new State based on a arikawa State. Event handlers from the old state won't be copied.
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 NewWithStore ¶
NewWithStore creates a new State with a custom state.Store.
func (*State) AuthorDisplayName ¶
func (s *State) AuthorDisplayName(message *gateway.MessageCreateEvent) string
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