Documentation ¶
Index ¶
- Constants
- Variables
- func AddArgumentsToContext(ctx context.Context, v map[string]*Argument) context.Context
- func AddCommandBranchToContext(ctx context.Context, v []string) context.Context
- func AddCommandTreeToContext(ctx context.Context, v []string) context.Context
- func AddComponentListenerToContext(ctx context.Context, v *ComponentListener) context.Context
- func AddIdentifierToContext(ctx context.Context, v string) context.Context
- func AddInteractionCommandToContext(ctx context.Context, v *InteractionCommandable) context.Context
- func AddRawOptionsToContext(ctx context.Context, v map[string]discord.InteractionDataOption) context.Context
- func GetArgumentsFromContext(ctx context.Context) map[string]*Argument
- func GetCommandBranchFromContext(ctx context.Context) []string
- func GetCommandTreeFromContext(ctx context.Context) []string
- func GetIdentifierFromContext(ctx context.Context) string
- func GetRawOptionsFromContext(ctx context.Context) map[string]discord.InteractionDataOption
- func HandleInteractionArgumentTypeBool(ctx context.Context, sub *Subway, interaction discord.Interaction, ...) (out interface{}, err error)
- func HandleInteractionArgumentTypeColour(ctx context.Context, sub *Subway, interaction discord.Interaction, ...) (out interface{}, err error)
- func HandleInteractionArgumentTypeEmoji(ctx context.Context, sub *Subway, interaction discord.Interaction, ...) (out interface{}, err error)
- func HandleInteractionArgumentTypeFloat(ctx context.Context, sub *Subway, interaction discord.Interaction, ...) (out interface{}, err error)
- func HandleInteractionArgumentTypeGuild(ctx context.Context, sub *Subway, interaction discord.Interaction, ...) (out interface{}, err error)
- func HandleInteractionArgumentTypeGuildChannel(ctx context.Context, sub *Subway, interaction discord.Interaction, ...) (out interface{}, err error)
- func HandleInteractionArgumentTypeInt(ctx context.Context, sub *Subway, interaction discord.Interaction, ...) (out interface{}, err error)
- func HandleInteractionArgumentTypeMember(ctx context.Context, sub *Subway, interaction discord.Interaction, ...) (out interface{}, err error)
- func HandleInteractionArgumentTypePartialEmoji(ctx context.Context, sub *Subway, interaction discord.Interaction, ...) (out interface{}, err error)
- func HandleInteractionArgumentTypeRole(ctx context.Context, sub *Subway, interaction discord.Interaction, ...) (out interface{}, err error)
- func HandleInteractionArgumentTypeSnowflake(ctx context.Context, sub *Subway, interaction discord.Interaction, ...) (out interface{}, err error)
- func HandleInteractionArgumentTypeString(ctx context.Context, sub *Subway, interaction discord.Interaction, ...) (out interface{}, err error)
- func HandleInteractionArgumentTypeUser(ctx context.Context, sub *Subway, interaction discord.Interaction, ...) (out interface{}, err error)
- type Argument
- func (a *Argument) Bool() (bool, error)
- func (a *Argument) Channel() (*discord.Channel, error)
- func (a *Argument) Colour() (*color.RGBA, error)
- func (a *Argument) Emoji() (*discord.Emoji, error)
- func (a *Argument) Float() (float64, error)
- func (a *Argument) Guild() (*discord.Guild, error)
- func (a *Argument) Int() (int64, error)
- func (a *Argument) Member() (*discord.GuildMember, error)
- func (a *Argument) MustBool() bool
- func (a *Argument) MustChannel() *discord.Channel
- func (a *Argument) MustColour() *color.RGBA
- func (a *Argument) MustEmoji() *discord.Emoji
- func (a *Argument) MustFloat() float64
- func (a *Argument) MustGuild() *discord.Guild
- func (a *Argument) MustInt() int64
- func (a *Argument) MustMember() *discord.GuildMember
- func (a *Argument) MustRole() *discord.Role
- func (a *Argument) MustSnowflake() *discord.Snowflake
- func (a *Argument) MustString() string
- func (a *Argument) MustStrings() []string
- func (a *Argument) MustUser() *discord.User
- func (a *Argument) Role() (*discord.Role, error)
- func (a *Argument) Snowflake() (*discord.Snowflake, error)
- func (a *Argument) String() (string, error)
- func (a *Argument) Strings() ([]string, error)
- func (a *Argument) User() (*discord.User, error)
- type ArgumentParameter
- type ArgumentType
- type Cog
- type CogInfo
- type CogWithBotLoad
- type CogWithBotUnload
- type CogWithInteractionCommands
- type ComponentListener
- type InteractionArgumentConverterType
- type InteractionAutocompleteHandler
- type InteractionCheckFuncType
- type InteractionCommandable
- func (ic *InteractionCommandable) AddInteractionCommand(interactionCommandable *InteractionCommandable) (icc *InteractionCommandable, err error)
- func (ic *InteractionCommandable) CanRun(ctx context.Context, sub *Subway, interaction discord.Interaction) (bool, error)
- func (ic *InteractionCommandable) GetAllCommands() []*InteractionCommandable
- func (ic *InteractionCommandable) GetCommand(name string) *InteractionCommandable
- func (ic *InteractionCommandable) Invoke(ctx context.Context, sub *Subway, interaction discord.Interaction) (*discord.InteractionResponse, error)
- func (ic *InteractionCommandable) IsGroup() bool
- func (ic *InteractionCommandable) MapApplicationCommands() []discord.ApplicationCommand
- func (ic *InteractionCommandable) MapApplicationOptions() (applicationOptions []discord.ApplicationCommandOption)
- func (ic *InteractionCommandable) MustAddInteractionCommand(interactionCommandable *InteractionCommandable) (icc *InteractionCommandable)
- func (ic *InteractionCommandable) RecursivelyRemoveAllCommands()
- func (ic *InteractionCommandable) RemoveCommand(name string) *InteractionCommandable
- type InteractionCommandableType
- type InteractionConverter
- type InteractionConverters
- type InteractionErrorHandler
- type InteractionHandler
- type InteractionRequestHandler
- type InteractionResponseHandler
- type PanicError
- type Subway
- func (sub *Subway) CanRun(ctx context.Context, interaction discord.Interaction) (bool, error)
- func (sub *Subway) HandleComponent(interaction discord.Interaction, customID string, timeout time.Duration, ...) *ComponentListener
- func (sub *Subway) HandleSubwayRequest(w http.ResponseWriter, r *http.Request)
- func (sub *Subway) InteractionCleanupJob(ctx context.Context, maximumAge time.Duration)
- func (sub *Subway) ListenAndServe(route, host string) error
- func (sub *Subway) MustRegisterCog(cog Cog)
- func (sub *Subway) NewGRPCContext(ctx context.Context) *sandwich.GRPCContext
- func (sub *Subway) ProcessApplicationCommandInteraction(ctx context.Context, interaction discord.Interaction) (*discord.InteractionResponse, error)
- func (sub *Subway) ProcessMessageComponentInteraction(ctx context.Context, interaction discord.Interaction) (*discord.InteractionResponse, error)
- func (sub *Subway) RegisterCog(cog Cog) error
- func (sub *Subway) RegisterCogInteractionCommandable(cog Cog, interactionCommandable *InteractionCommandable)
- func (sub *Subway) SetupPrometheus() error
- func (sub *Subway) SyncCommands(ctx context.Context, token string, applicationID discord.Snowflake) error
- type SubwayContextKey
- type SubwayOptions
Constants ¶
const ( HeaderSignature = "X-Signature-Ed25519" HeaderTimestamp = "X-Signature-Timestamp" )
const ( PermissionsDefault = 0o744 PermissionWrite = 0o600 )
const VERSION = "0.4"
VERSION follows semantic versioning.
Variables ¶
var ( ErrSubwayAlreadyExists = errors.New("subway already created") ErrInvalidRequestSignature = errors.New("invalid request signature") ErrInvalidPublicKey = errors.New("invalid public key. this must be a 64 characters long and hex encoded") ErrReadConfigurationFailure = errors.New("failed to read configuration") ErrLoadConfigurationFailure = errors.New("failed to load configuration") ErrFetchMissingGuild = errors.New("object requires guild ID to fetch") ErrFetchMissingSnowflake = errors.New("object requires snowflake to fetch") ErrCogAlreadyRegistered = errors.New("cog with this name already exists") ErrCommandAlreadyRegistered = errors.New("command with this name already exists") ErrInvalidArgumentType = errors.New("argument value is not correct type for converter used") ErrCommandNotFound = errors.New("command with this name was not found") ErrCommandAutoCompleteNotFound = errors.New("autocomplete for command with this name was not found") ErrComponentListenerNotFound = errors.New("component listener with this name was not found or has expired") ErrCheckFailure = errors.New("command failed built-in checks") ErrMissingRequiredArgument = errors.New("command missing required arguments") ErrArgumentNotFound = errors.New("command argument was not found") ErrConverterNotFound = errors.New("command converter is not setup") ErrSnowflakeNotFound = errors.New("id does not follow a valid id or mention format") ErrMemberNotFound = errors.New("member provided was not found") ErrUserNotFound = errors.New("user provided was not found") ErrChannelNotFound = errors.New("channel provided was not found") ErrGuildNotFound = errors.New("guild provided was not found") ErrRoleNotFound = errors.New("role provided was not found") ErrEmojiNotFound = errors.New("emoji provided was not found") ErrBadInviteArgument = errors.New("invite provided was invalid or expired") ErrBadColourArgument = errors.New("colour provided was not in valid format") ErrBadBoolArgument = errors.New("bool provided was not in valid format") ErrBadIntArgument = errors.New("int provided was not in valid format") ErrBadFloatArgument = errors.New("float provided was not in valid format") ErrBadWebhookArgument = errors.New("webhook url provided was not in valid format") )
var ( IDRegex = regexp.MustCompile("([0-9]{15,20})$") GenericMentionRegex = regexp.MustCompile("<(?:@(?:!|&)?|#)([0-9]{15,20})>$") UserMentionRegex = regexp.MustCompile("<@!?([0-9]{15,20})>$") ChannelMentionRegex = regexp.MustCompile("<#([0-9]{15,20})>") RoleMentionRegex = regexp.MustCompile("<@&([0-9]{15,20})>$") EmojiRegex = regexp.MustCompile("<a?:[a-zA-Z0-9_]{1,32}:([0-9]{15,20})>$") PartialEmojiRegex = regexp.MustCompile("<(a?):([a-zA-Z0-9_]{1,32}):([0-9]{15,20})>$") )
var InteractionPongResponse = []byte(`{"type":1}`)
Functions ¶
func AddArgumentsToContext ¶
Arguments context handler.
func AddCommandBranchToContext ¶
CommandBranch context handler.
func AddCommandTreeToContext ¶
CommandTree context handler.
func AddComponentListenerToContext ¶
func AddComponentListenerToContext(ctx context.Context, v *ComponentListener) context.Context
ComponentListener context handler.
func AddIdentifierToContext ¶
Identifier context handler.
func AddInteractionCommandToContext ¶
func AddInteractionCommandToContext(ctx context.Context, v *InteractionCommandable) context.Context
InteractionCommand context handler.
func AddRawOptionsToContext ¶
func AddRawOptionsToContext(ctx context.Context, v map[string]discord.InteractionDataOption) context.Context
RawOptions context handler.
func GetArgumentsFromContext ¶
func GetRawOptionsFromContext ¶
func GetRawOptionsFromContext(ctx context.Context) map[string]discord.InteractionDataOption
func HandleInteractionArgumentTypeBool ¶
func HandleInteractionArgumentTypeBool(ctx context.Context, sub *Subway, interaction discord.Interaction, option discord.InteractionDataOption) (out interface{}, err error)
HandleInteractionArgumentTypeBool handles converting from a string argument into a Bool type. Use .Bool() within a command to get the proper type.
func HandleInteractionArgumentTypeColour ¶
func HandleInteractionArgumentTypeColour(ctx context.Context, sub *Subway, interaction discord.Interaction, option discord.InteractionDataOption) (out interface{}, err error)
HandleInteractionArgumentTypeColour handles converting from a string argument into a Colour type. Use .Colour() within a command to get the proper type.
func HandleInteractionArgumentTypeEmoji ¶
func HandleInteractionArgumentTypeEmoji(ctx context.Context, sub *Subway, interaction discord.Interaction, option discord.InteractionDataOption) (out interface{}, err error)
HandleInteractionArgumentTypeEmoji handles converting from a string argument into a Emoji type. Use .Emoji() within a command to get the proper type.
func HandleInteractionArgumentTypeFloat ¶
func HandleInteractionArgumentTypeFloat(ctx context.Context, sub *Subway, interaction discord.Interaction, option discord.InteractionDataOption) (out interface{}, err error)
HandleInteractionArgumentTypeFloat handles converting from a string argument into a Float type. Use .Float64() within a command to get the proper type.
func HandleInteractionArgumentTypeGuild ¶
func HandleInteractionArgumentTypeGuild(ctx context.Context, sub *Subway, interaction discord.Interaction, option discord.InteractionDataOption) (out interface{}, err error)
HandleInteractionArgumentTypeGuild handles converting from a string argument into a Guild type. Use .Guild() within a command to get the proper type.
func HandleInteractionArgumentTypeGuildChannel ¶
func HandleInteractionArgumentTypeGuildChannel(ctx context.Context, sub *Subway, interaction discord.Interaction, option discord.InteractionDataOption) (out interface{}, err error)
HandleInteractionArgumentTypeGuildChannel handles converting from a string argument into a TextChannel type. Use .Channel() within a command to get the proper type.
func HandleInteractionArgumentTypeInt ¶
func HandleInteractionArgumentTypeInt(ctx context.Context, sub *Subway, interaction discord.Interaction, option discord.InteractionDataOption) (out interface{}, err error)
HandleInteractionArgumentTypeInt handles converting from a string argument into a Int type. Use .Int64() within a command to get the proper type.
func HandleInteractionArgumentTypeMember ¶
func HandleInteractionArgumentTypeMember(ctx context.Context, sub *Subway, interaction discord.Interaction, option discord.InteractionDataOption) (out interface{}, err error)
HandleInteractionArgumentTypeMember handles converting from a string argument into a Member type. Use .Member() within a command to get the proper type.
func HandleInteractionArgumentTypePartialEmoji ¶
func HandleInteractionArgumentTypePartialEmoji(ctx context.Context, sub *Subway, interaction discord.Interaction, option discord.InteractionDataOption) (out interface{}, err error)
HandleInteractionArgumentTypePartialEmoji handles converting from a string argument into a Emoji type. Use .Emoji() within a command to get the proper type.
func HandleInteractionArgumentTypeRole ¶
func HandleInteractionArgumentTypeRole(ctx context.Context, sub *Subway, interaction discord.Interaction, option discord.InteractionDataOption) (out interface{}, err error)
HandleInteractionArgumentTypeRole handles converting from a string argument into a Role type. Use .Role() within a command to get the proper type.
func HandleInteractionArgumentTypeSnowflake ¶
func HandleInteractionArgumentTypeSnowflake(ctx context.Context, sub *Subway, interaction discord.Interaction, option discord.InteractionDataOption) (out interface{}, err error)
HandleInteractionArgumentTypeSnowflake handles converting from a string argument into a Snowflake type. Use .Snowflake() within a command to get the proper type.
func HandleInteractionArgumentTypeString ¶
func HandleInteractionArgumentTypeString(ctx context.Context, sub *Subway, interaction discord.Interaction, option discord.InteractionDataOption) (out interface{}, err error)
HandleInteractionArgumentTypeString handles converting from a string argument into a String type. Use .String() within a command to get the proper type.
func HandleInteractionArgumentTypeUser ¶
func HandleInteractionArgumentTypeUser(ctx context.Context, sub *Subway, interaction discord.Interaction, option discord.InteractionDataOption) (out interface{}, err error)
HandleInteractionArgumentTypeUser handles converting from a string argument into a User type. Use .User() within a command to get the proper type.
Types ¶
type Argument ¶
type Argument struct { ArgumentType ArgumentType // contains filtered or unexported fields }
func GetArgument ¶
GetArgument returns an argument based on its name.
func MustGetArgument ¶
MustGetArgument returns an argument based on its name. Panics on error.
func (*Argument) Bool ¶
Bool returns an argument as the specified Type. If the argument is not the right type for the converter that made the argument, ErrInvalidArgumentType will be returned.
func (*Argument) Channel ¶
Channel returns an argument as the specified Type. If the argument is not the right type for the converter that made the argument, ErrInvalidArgumentType will be returned.
func (*Argument) Colour ¶
Colour returns an argument as the specified Type. If the argument is not the right type for the converter that made the argument, ErrInvalidArgumentType will be returned.
func (*Argument) Emoji ¶
Emoji returns an argument as the specified Type. If the argument is not the right type for the converter that made the argument, ErrInvalidArgumentType will be returned.
func (*Argument) Float ¶
Float returns an argument as the specified Type. If the argument is not the right type for the converter that made the argument, ErrInvalidArgumentType will be returned.
func (*Argument) Guild ¶
Guild returns an argument as the specified Type. If the argument is not the right type for the converter that made the argument, ErrInvalidArgumentType will be returned.
func (*Argument) Int ¶
Int returns an argument as the specified Type. If the argument is not the right type for the converter that made the argument, ErrInvalidArgumentType will be returned.
func (*Argument) Member ¶
func (a *Argument) Member() (*discord.GuildMember, error)
Member returns an argument as the specified Type. If the argument is not the right type for the converter that made the argument, ErrInvalidArgumentType will be returned.
func (*Argument) MustChannel ¶
MustTextChannel will attempt to do Channel() and will panic if not possible.
func (*Argument) MustColour ¶
MustColour will attempt to do Colour() and will panic if not possible.
func (*Argument) MustMember ¶
func (a *Argument) MustMember() *discord.GuildMember
MustMember will attempt to do Member() and will panic if not possible.
func (*Argument) MustSnowflake ¶
MustSnowflake will attempt to do Snowflake() and will panic if not possible.
func (*Argument) MustString ¶
MustString will attempt to do String() and will panic if not possible.
func (*Argument) MustStrings ¶
MustStrings will attempt to do Strings() and will panic if not possible.
func (*Argument) Role ¶
Role returns an argument as the specified Type. If the argument is not the right type for the converter that made the argument, ErrInvalidArgumentType will be returned.
func (*Argument) Snowflake ¶
Snowflake returns an argument as the specified Type. If the argument is not the right type for the converter that made the argument, ErrInvalidArgumentType will be returned.
func (*Argument) String ¶
String returns an argument as the specified Type. If the argument is not the right type for the converter that made the argument, ErrInvalidArgumentType will be returned.
type ArgumentParameter ¶
type ArgumentParameter struct { Required bool ArgumentType ArgumentType Name string Description string NameLocalizations map[string]string DescriptionLocalizations map[string]string Choices []discord.ApplicationCommandOptionChoice ChannelTypes []discord.ChannelType MinValue *int32 MaxValue *int32 MinLength *int32 MaxLength *int32 Autocomplete *bool }
type ArgumentType ¶
type ArgumentType uint16
const ( ArgumentTypeSnowflake ArgumentType = iota + 1 ArgumentTypeMember ArgumentTypeUser ArgumentTypeTextChannel ArgumentTypeGuild ArgumentTypeRole ArgumentTypeColour ArgumentTypeVoiceChannel ArgumentTypeStageChannel ArgumentTypeEmoji ArgumentTypePartialEmoji ArgumentTypeCategoryChannel ArgumentTypeStoreChannel ArgumentTypeThread ArgumentTypeGuildChannel ArgumentTypeString ArgumentTypeBool ArgumentTypeInt ArgumentTypeFloat ArgumentTypeStrings )
type Cog ¶
Cog is the basic interface for any cog. This must provide information about the cog such as its name and description.
type CogWithBotLoad ¶
type CogWithBotLoad interface {
BotLoad(sub *Subway)
}
CogWithBotLoad is an interface for any cog that implements methods that run when a bot loads.
type CogWithBotUnload ¶
CogWithBotUnload is an interface for any cog that implements methods that run when a bot unloads.
type CogWithInteractionCommands ¶
type CogWithInteractionCommands interface {
GetInteractionCommandable() *InteractionCommandable
}
CogWithInteractionCommands is an interface for any cog that implements methods that return interaction commands.
type ComponentListener ¶
type ComponentListener struct { Channel chan *discord.Interaction InitialInteraction discord.Interaction Handler InteractionHandler // contains filtered or unexported fields }
func GetComponentListenerFromContext ¶
func GetComponentListenerFromContext(ctx context.Context) *ComponentListener
func (*ComponentListener) Cancel ¶
func (listener *ComponentListener) Cancel()
Cancel stops listening for a component and closes the channel, if one is present.
type InteractionArgumentConverterType ¶
type InteractionArgumentConverterType func(ctx context.Context, sub *Subway, interaction discord.Interaction, argument discord.InteractionDataOption) (out interface{}, err error)
type InteractionAutocompleteHandler ¶
type InteractionAutocompleteHandler func(ctx context.Context, sub *Subway, interaction discord.Interaction) ([]discord.ApplicationCommandOptionChoice, error)
type InteractionCheckFuncType ¶
type InteractionCheckFuncType func(ctx context.Context, sub *Subway, interaction discord.Interaction) (canRun bool, err error)
Func Type used for command checks.
type InteractionCommandable ¶
type InteractionCommandable struct { Name string Description string NameLocalizations map[string]string DescriptionLocalizations map[string]string Type InteractionCommandableType CommandType *discord.ApplicationCommandType Checks []InteractionCheckFuncType ArgumentParameter []ArgumentParameter Handler InteractionHandler ErrorHandler InteractionErrorHandler DefaultMemberPermission *discord.Int64 DMPermission *bool AutocompleteHandler InteractionAutocompleteHandler // contains filtered or unexported fields }
func GetInteractionCommandFromContext ¶
func GetInteractionCommandFromContext(ctx context.Context) *InteractionCommandable
func NewSubcommandGroup ¶
func NewSubcommandGroup(name string, description string) *InteractionCommandable
Accelerator to create a subcommand group.
func SetupInteractionCommandable ¶
func SetupInteractionCommandable(commandable *InteractionCommandable) *InteractionCommandable
SetupInteractionCommandable ensures all nullable variables are properly constructed.
func (*InteractionCommandable) AddInteractionCommand ¶
func (ic *InteractionCommandable) AddInteractionCommand(interactionCommandable *InteractionCommandable) (icc *InteractionCommandable, err error)
func (*InteractionCommandable) CanRun ¶
func (ic *InteractionCommandable) CanRun(ctx context.Context, sub *Subway, interaction discord.Interaction) (bool, error)
CanRun checks interactionCommandable checks and returns if the interaction passes them all. If an error occurs, the message will be treated as not being able to run.
func (*InteractionCommandable) GetAllCommands ¶
func (ic *InteractionCommandable) GetAllCommands() []*InteractionCommandable
GetAllCommands returns all commands.
func (*InteractionCommandable) GetCommand ¶
func (ic *InteractionCommandable) GetCommand(name string) *InteractionCommandable
func (*InteractionCommandable) Invoke ¶
func (ic *InteractionCommandable) Invoke(ctx context.Context, sub *Subway, interaction discord.Interaction) (*discord.InteractionResponse, error)
Invoke handles the execution of a command or a group.
func (*InteractionCommandable) IsGroup ¶
func (ic *InteractionCommandable) IsGroup() bool
IsGroup returns true if the command contains other commands.
func (*InteractionCommandable) MapApplicationCommands ¶
func (ic *InteractionCommandable) MapApplicationCommands() []discord.ApplicationCommand
func (*InteractionCommandable) MapApplicationOptions ¶
func (ic *InteractionCommandable) MapApplicationOptions() (applicationOptions []discord.ApplicationCommandOption)
func (*InteractionCommandable) MustAddInteractionCommand ¶
func (ic *InteractionCommandable) MustAddInteractionCommand(interactionCommandable *InteractionCommandable) (icc *InteractionCommandable)
func (*InteractionCommandable) RecursivelyRemoveAllCommands ¶
func (ic *InteractionCommandable) RecursivelyRemoveAllCommands()
func (*InteractionCommandable) RemoveCommand ¶
func (ic *InteractionCommandable) RemoveCommand(name string) *InteractionCommandable
type InteractionCommandableType ¶
type InteractionCommandableType uint8
const ( InteractionCommandableTypeCommand InteractionCommandableType = iota InteractionCommandableTypeSubcommandGroup InteractionCommandableTypeSubcommand )
type InteractionConverter ¶
type InteractionConverter struct {
// contains filtered or unexported fields
}
type InteractionConverters ¶
type InteractionConverters struct { Converters map[ArgumentType]*InteractionConverter // contains filtered or unexported fields }
func NewInteractionConverters ¶
func NewInteractionConverters() *InteractionConverters
func (*InteractionConverters) GetConverter ¶
func (co *InteractionConverters) GetConverter(converterType ArgumentType) *InteractionConverter
GetConverter returns a converter based on the converterType passed.
func (*InteractionConverters) RegisterConverter ¶
func (co *InteractionConverters) RegisterConverter(converterName ArgumentType, converter InteractionArgumentConverterType, defaultValue interface{})
RegisterConverter adds a new converter. If there is already a converter registered with its name, it will be overridden.
type InteractionErrorHandler ¶
type InteractionErrorHandler func(ctx context.Context, sub *Subway, interaction discord.Interaction, err error) (*discord.InteractionResponse, error)
type InteractionHandler ¶
type InteractionHandler func(ctx context.Context, sub *Subway, interaction discord.Interaction) (*discord.InteractionResponse, error)
type InteractionResponseHandler ¶
type InteractionResponseHandler func(ctx context.Context, sub *Subway, interaction discord.Interaction, resp *discord.InteractionResponse, err error) error
type PanicError ¶
type PanicError struct {
Recover interface{}
}
func (PanicError) Error ¶
func (cp PanicError) Error() string
type Subway ¶
type Subway struct { context.Context Logger zerolog.Logger `json:"-"` StartTime time.Time `json:"start_time" yaml:"start_time"` Commands *InteractionCommandable `json:"-"` Converters *InteractionConverters `json:"-"` Cogs map[string]Cog `json:"-"` SandwichClient protobuf.SandwichClient `json:"-"` GRPCInterface sandwich.GRPC `json:"-"` RESTInterface discord.RESTInterface `json:"-"` EmptySession *discord.Session `json:"-"` ComponentListenersMu sync.RWMutex ComponentListeners map[string]*ComponentListener OnBeforeInteraction InteractionRequestHandler OnAfterInteraction InteractionResponseHandler // contains filtered or unexported fields }
func (*Subway) CanRun ¶
CanRun checks all global bot checks and returns if the message passes them all. If an error occurs, the message will be treated as not being able to run.
func (*Subway) HandleComponent ¶
func (sub *Subway) HandleComponent(interaction discord.Interaction, customID string, timeout time.Duration, handler InteractionHandler) *ComponentListener
WaitForComponent allows you to wait for a specific component interaction. You can either use a callback function which is automatically handled or use a channel.
func (*Subway) HandleSubwayRequest ¶
func (sub *Subway) HandleSubwayRequest(w http.ResponseWriter, r *http.Request)
func (*Subway) InteractionCleanupJob ¶
func (*Subway) ListenAndServe ¶
Listen handles starting up the webserver and services for you.
func (*Subway) MustRegisterCog ¶
func (*Subway) NewGRPCContext ¶
func (sub *Subway) NewGRPCContext(ctx context.Context) *sandwich.GRPCContext
func (*Subway) ProcessApplicationCommandInteraction ¶
func (sub *Subway) ProcessApplicationCommandInteraction(ctx context.Context, interaction discord.Interaction) (*discord.InteractionResponse, error)
ProcessApplicationCommandInteraction processes the application command that has been received.
func (*Subway) ProcessMessageComponentInteraction ¶
func (sub *Subway) ProcessMessageComponentInteraction(ctx context.Context, interaction discord.Interaction) (*discord.InteractionResponse, error)
ProcessMessageComponentInteraction processes the message component that has been received.
func (*Subway) RegisterCog ¶
func (*Subway) RegisterCogInteractionCommandable ¶
func (sub *Subway) RegisterCogInteractionCommandable(cog Cog, interactionCommandable *InteractionCommandable)
func (*Subway) SetupPrometheus ¶
SetupPrometheus sets up prometheus.
func (*Subway) SyncCommands ¶
func (sub *Subway) SyncCommands(ctx context.Context, token string, applicationID discord.Snowflake) error
SyncCommands syncs all registered commands with the discord API. Use sandwichClient.FetchIdentifier to get the token for an identifier. Token must have "Bot " added.
type SubwayContextKey ¶
type SubwayContextKey int
const ( SubwayKey SubwayContextKey = iota InteractionKey InteractionCommandKey ArgumentsKey RawOptionsKey CommandBranchKey CommandTreeKey IdentifierKey ComponentListenerKey )
type SubwayOptions ¶
type SubwayOptions struct { SandwichClient protobuf.SandwichClient RESTInterface discord.RESTInterface Logger zerolog.Logger OnBeforeInteraction InteractionRequestHandler OnAfterInteraction InteractionResponseHandler PublicKey string PrometheusAddress string // Maximum age for component listeners. Defaults to 15 minutes. // This is the absolute maximum age of a component listener, // ignoring a listener with a longer age. MaximumInteractionAge time.Duration }
SubwayOptions represents the options to create a new subway service.