Documentation ¶
Overview ¶
Package lambdinte handles Discord interactions received as AWS Lambda events. It is largely modeled after net/http; register interaction handlers with DefaultMux via top-level Register functions, and then call Start to listen for events. Clients wanting more control can set the Handler fields of DefaultMux or create a Function with a custom base Handler.
Index ¶
- Variables
- func DefaultPingHandlerFunc(ctx context.Context, evt discordgo.Interaction) (discordgo.InteractionResponse, error)
- func RegisterCommand(name string, handler Handler)
- func RegisterCommandAutocomplete(name string, handler Handler)
- func RegisterCommandAutocompleteFunc(name string, ...)
- func RegisterCommandFunc(name string, ...)
- func RegisterComponent(customID string, handler Handler)
- func RegisterComponentFunc(customID string, ...)
- func RegisterModal(customID string, handler Handler)
- func RegisterModalFunc(customID string, ...)
- func Start(publicKey ed25519.PublicKey)
- type ApplicationCommandMux
- type Function
- type Handler
- type HandlerFunc
- type MessageComponentMux
- type ModalSubmitMux
- type Mux
- func (m *Mux) Handle(ctx context.Context, evt discordgo.Interaction) (discordgo.InteractionResponse, error)
- func (m *Mux) RegisterCommand(name string, handler Handler)
- func (m *Mux) RegisterCommandAutocomplete(name string, handler Handler)
- func (m *Mux) RegisterCommandAutocompleteFunc(name string, ...)
- func (m *Mux) RegisterCommandFunc(name string, ...)
- func (m *Mux) RegisterComponent(customID string, handler Handler)
- func (m *Mux) RegisterComponentFunc(customID string, ...)
- func (m *Mux) RegisterModal(customID string, handler Handler)
- func (m *Mux) RegisterModalFunc(customID string, ...)
Constants ¶
This section is empty.
Variables ¶
var DefaultMux = &defaultMux
DefaultMux is the default Handler used by App.
var DefaultPingHandler = HandlerFunc(DefaultPingHandlerFunc)
DefaultPingHandler responds to pings with pongs.
Functions ¶
func DefaultPingHandlerFunc ¶
func DefaultPingHandlerFunc(ctx context.Context, evt discordgo.Interaction) (discordgo.InteractionResponse, error)
DefaultPingHandlerFunc responds to pings with pongs.
func RegisterCommand ¶
RegisterCommand registers the handler for application command interactions with the given name into DefaultMux.
func RegisterCommandAutocomplete ¶
RegisterCommandAutocomplete registers the handler for application command autocomplete interactions with the given name into DefaultMux.
func RegisterCommandAutocompleteFunc ¶
func RegisterCommandAutocompleteFunc(name string, handler func(context.Context, discordgo.Interaction) (discordgo.InteractionResponse, error))
RegisterCommandAutocompleteFunc registers the handler function for application command autocomplete interactions with the given name into DefaultMux.
func RegisterCommandFunc ¶
func RegisterCommandFunc(name string, handler func(context.Context, discordgo.Interaction) (discordgo.InteractionResponse, error))
RegisterCommandFunc registers the handler function for application command interactions with the given name into DefaultMux.
func RegisterComponent ¶
RegisterComponent registers the handler for message component interactions with the given ID into DefaultMux.
func RegisterComponentFunc ¶
func RegisterComponentFunc(customID string, handler func(context.Context, discordgo.Interaction) (discordgo.InteractionResponse, error))
RegisterComponentFunc registers the handler function for message component interactions with the given ID into DefaultMux.
func RegisterModal ¶
RegisterModal registers the handler for modal submit interactions with the given ID into DefaultMux.
func RegisterModalFunc ¶
func RegisterModalFunc(customID string, handler func(context.Context, discordgo.Interaction) (discordgo.InteractionResponse, error))
RegisterModalFunc registers the handler function for modal submit interactions with the given ID into DefaultMux.
Types ¶
type ApplicationCommandMux ¶
type ApplicationCommandMux struct {
// contains filtered or unexported fields
}
ApplicationCommandMux stores and selects handlers for application command interactions based on their name. It is appropriate for both APPLICATION_COMMAND interactions (type 2) and APPLICATION_COMMAND_AUTOCOMPLETE interactions (type 4).
func (*ApplicationCommandMux) Handle ¶
func (m *ApplicationCommandMux) Handle(ctx context.Context, evt discordgo.Interaction) (discordgo.InteractionResponse, error)
Handle handles the interaction. If the interaction is of the wrong type, or the command name has not been registered, it panics.
func (*ApplicationCommandMux) Register ¶
Register registers the handler for the given key. If a handler already exists for key, Handle panics.
func (*ApplicationCommandMux) RegisterFunc ¶
func (h *ApplicationCommandMux) RegisterFunc(name string, handler func(context.Context, discordgo.Interaction) (discordgo.InteractionResponse, error))
RegisterFunc registers the handler function for the given key.
type Function ¶
type Function struct { // PublicKey should be set to your Discord application's public key before calling Start. PublicKey ed25519.PublicKey // Handler handles incoming interaction events; if it is nil, DefaultMux will be used. Handler Handler }
Function handles Discord interactions received as AWS Lambda events.
type Handler ¶
type Handler interface {
Handle(context.Context, discordgo.Interaction) (discordgo.InteractionResponse, error)
}
Handler handles and responds to Discord interactions
type HandlerFunc ¶
type HandlerFunc func(context.Context, discordgo.Interaction) (discordgo.InteractionResponse, error)
HandlerFunc is a Handler that calls itself
func (HandlerFunc) Handle ¶
func (f HandlerFunc) Handle(c context.Context, i discordgo.Interaction) (discordgo.InteractionResponse, error)
Handle calls the underlying function
type MessageComponentMux ¶
type MessageComponentMux struct {
// contains filtered or unexported fields
}
MessageComponentMux stores and selects handlers for message component interactions based on their custom_id. If you use custom_id for any purpose other than identifying the component, such as persisting state, it is probably not appropriate.
func (*MessageComponentMux) Handle ¶
func (m *MessageComponentMux) Handle(ctx context.Context, evt discordgo.Interaction) (discordgo.InteractionResponse, error)
Handle handles the interaction. If the interaction is of the wrong type, or the component ID has not been registered, it panics.
func (*MessageComponentMux) Register ¶
Register registers the handler for the given key. If a handler already exists for key, Handle panics.
func (*MessageComponentMux) RegisterFunc ¶
func (h *MessageComponentMux) RegisterFunc(name string, handler func(context.Context, discordgo.Interaction) (discordgo.InteractionResponse, error))
RegisterFunc registers the handler function for the given key.
type ModalSubmitMux ¶
type ModalSubmitMux struct {
// contains filtered or unexported fields
}
ModalSubmitMux stores and selects handlers for modal submit interactions based on their custom_id. If you use custom_id for any purpose other than identifying the modal, such as persisting state, it is probably not appropriate.
func (*ModalSubmitMux) Handle ¶
func (m *ModalSubmitMux) Handle(ctx context.Context, evt discordgo.Interaction) (discordgo.InteractionResponse, error)
Handle handles the interaction. If the interaction is of the wrong type, or the modal ID has not been registered, it panics.
func (*ModalSubmitMux) Register ¶
Register registers the handler for the given key. If a handler already exists for key, Handle panics.
func (*ModalSubmitMux) RegisterFunc ¶
func (h *ModalSubmitMux) RegisterFunc(name string, handler func(context.Context, discordgo.Interaction) (discordgo.InteractionResponse, error))
RegisterFunc registers the handler function for the given key.
type Mux ¶
type Mux struct { // PingHandler is called for PING interactions (type 1). // If it is nil, DefaultPingHandler will be used. PingHandler Handler // ApplicationCommandHandler is called for APPLICATION_COMMAND interactions (type 2). // You probably want to use RegisterCommand and/or RegisterCommandFunc to set it up. ApplicationCommandHandler Handler // MessageComponentHandler is called for MESSAGE_COMPONENT interactions (type 3). // You may want to use RegisterComponent and/or RegisterComponentFunc to set it up. MessageComponentHandler Handler // ApplicationCommandAutocompleteHandler is called for APPLICATION_COMMAND_AUTOCOMPLETE interactions (type 4). // You probably want to use RegisterCommandAutocomplete and/or RegisterCommandAutocompleteFunc to set it up. ApplicationCommandAutocompleteHandler Handler // ModalSubmitHandler is called for MODAL_SUBMIT interactions (type 5). // You may want to use RegisterModal and/or RegisterModalFunc to set it up. ModalSubmitHandler Handler }
Mux routes interactions to Handlers based on their types.
func (*Mux) Handle ¶
func (m *Mux) Handle(ctx context.Context, evt discordgo.Interaction) (discordgo.InteractionResponse, error)
Handle forwards to the appropriate Handler. If an interaction is received of a type that Mux does not have a handler for (other than PING), Handle panics.
func (*Mux) RegisterCommand ¶
RegisterCommand registers the handler for application command interactions with the given name. If ApplicationCommandHandler is nil, it is set up as an ApplicationCommandMux. If ApplicationCommandHandler is not nil or an ApplicationCommandMux, RegisterCommand panics.
func (*Mux) RegisterCommandAutocomplete ¶
RegisterCommandAutocomplete registers the handler for application command autocomplete interactions with the given name. If ApplicationCommandAutocompleteHandler is nil, it is set up as an ApplicationCommandMux. If ApplicationCommandAutocompleteHandler is not nil or an ApplicationCommandMux, RegisterCommandAutocomplete panics.
func (*Mux) RegisterCommandAutocompleteFunc ¶
func (m *Mux) RegisterCommandAutocompleteFunc(name string, handler func(context.Context, discordgo.Interaction) (discordgo.InteractionResponse, error))
RegisterCommandAutocompleteFunc registers the handler function for application command autocomplete interactions with the given name. If ApplicationCommandAutocompleteHandler is nil, it is set up as an ApplicationCommandMux. If ApplicationCommandAutocompleteHandler is not nil or an ApplicationCommandMux, RegisterCommandAutocompleteFunc panics.
func (*Mux) RegisterCommandFunc ¶
func (m *Mux) RegisterCommandFunc(name string, handler func(context.Context, discordgo.Interaction) (discordgo.InteractionResponse, error))
RegisterCommandFunc registers the handler function for application command interactions with the given name. If ApplicationCommandHandler is nil, it is set up as an ApplicationCommandMux. If ApplicationCommandHandler is not nil or an ApplicationCommandMux, RegisterCommandFunc panics.
func (*Mux) RegisterComponent ¶
RegisterComponent registers the handler for message component interactions with the given ID. If MessageComponentHandler is nil, it is set up as a MessageComponentMux. If MessageComponentHandler is not nil or a MessageComponentMux, RegisterComponent panics.
func (*Mux) RegisterComponentFunc ¶
func (m *Mux) RegisterComponentFunc(customID string, handler func(context.Context, discordgo.Interaction) (discordgo.InteractionResponse, error))
RegisterComponentFunc registers the handler function for message component interactions with the given ID. If MessageComponentHandler is nil, it is set up as a MessageComponentMux. If MessageComponentHandler is not nil or a MessageComponentMux, RegisterComponentFunc panics.
func (*Mux) RegisterModal ¶
RegisterModal registers the handler for modal submit interactions with the given ID. If ModalSubmitHandler is nil, it is set up as a ModalSubmitMux. If ModalSubmitHandler is not nil or a ModalSubmitMux, RegisterModal panics.
func (*Mux) RegisterModalFunc ¶
func (m *Mux) RegisterModalFunc(customID string, handler func(context.Context, discordgo.Interaction) (discordgo.InteractionResponse, error))
RegisterModalFunc registers the handler function for modal submit interactions with the given ID. If ModalSubmitHandler is nil, it is set up as a ModalSubmitMux. If ModalSubmitHandler is not nil or a ModalSubmitMux, RegisterModalFunc panics.