lambdinte

package module
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

README

lambdinte

Use AWS Lambda functions to respond to Discord interactions.

Examples will be documented once I figure out how/if this thing works.

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

Constants

This section is empty.

Variables

View Source
var DefaultMux = &defaultMux

DefaultMux is the default Handler used by App.

View Source
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

func RegisterCommand(name string, handler Handler)

RegisterCommand registers the handler for application command interactions with the given name into DefaultMux.

func RegisterCommandAutocomplete

func RegisterCommandAutocomplete(name string, handler Handler)

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

func RegisterComponent(customID string, handler Handler)

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

func RegisterModal(customID string, handler Handler)

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.

func Start

func Start(publicKey ed25519.PublicKey)

Start listens for incoming AWS Lambda events using the given public key and 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

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

func (h *ApplicationCommandMux) Register(key string, handler Handler)

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.

func (*Function) Invoke

func (f *Function) Invoke(ctx context.Context, eventData []byte) ([]byte, error)

Invoke reads the event data, verifies the signature, and calls Handler.Handle.

func (*Function) Start

func (f *Function) Start()

Start listens for incoming AWS Lambda events. If PublicKey is nil, Start panics.

type Handler

type Handler interface {
	Handle(context.Context, discordgo.Interaction) (discordgo.InteractionResponse, error)
}

Handler handles and responds to Discord interactions

type HandlerFunc

HandlerFunc is a Handler that calls itself

func (HandlerFunc) Handle

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

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

func (h *MessageComponentMux) Register(key string, handler Handler)

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

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

func (h *ModalSubmitMux) Register(key string, handler Handler)

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

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

func (m *Mux) RegisterCommand(name string, handler Handler)

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

func (m *Mux) RegisterCommandAutocomplete(name string, handler Handler)

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

func (m *Mux) RegisterComponent(customID string, handler Handler)

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

func (m *Mux) RegisterModal(customID string, handler Handler)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL