Documentation ¶
Index ¶
- Variables
- func RegisterCommands(r *Route, s *state.State, appID discord.AppID) ([]discord.Command, error)
- func RegisterGuildCommands(r *Route, s *state.State, appID discord.AppID, guildID discord.GuildID) ([]discord.Command, error)
- type Argument
- type ArgumentType
- type AutocompleteChoice
- type AutocompleteHandler
- type Context
- func (c *Context) Acknowledge() error
- func (c *Context) Arg(name string) string
- func (c *Context) BoolArg(name string) bool
- func (c *Context) ChannelArg(name string) *discord.Channel
- func (c *Context) ChannelArgType(name string, t discord.ChannelType) *discord.Channel
- func (c *Context) EmojiArg(name string) *discord.Emoji
- func (c *Context) FloatArg(name string) float64
- func (c *Context) IntArg(name string) int64
- func (c *Context) Reply(text string) (*discord.Message, error)
- func (c *Context) ReplyEmbed(embed *discord.Embed) (*discord.Message, error)
- func (c *Context) ReplyFile(name string, r io.Reader) (*discord.Message, error)
- func (c *Context) ReplyTo(to discord.UserID, text string) (*discord.Message, error)
- func (c *Context) Replyf(format string, a ...interface{}) (*discord.Message, error)
- func (c *Context) Respond(r Response) (*discord.Message, error)
- func (c *Context) RoleArg(name string) *discord.Role
- func (c *Context) Send(text string) (*discord.Message, error)
- func (c *Context) SendFile(name string, r io.Reader) (*discord.Message, error)
- func (c *Context) Sendf(format string, a ...interface{}) (*discord.Message, error)
- func (c *Context) Usage(usage ...string) (*discord.Message, error)
- func (c *Context) UserArg(name string) *discord.User
- type FindOpts
- type Handler
- type InteractionResponder
- func (m *InteractionResponder) Acknowledge() error
- func (m *InteractionResponder) Reply(text string) (*discord.Message, error)
- func (m *InteractionResponder) ReplyEmbed(embed *discord.Embed) (*discord.Message, error)
- func (m *InteractionResponder) ReplyFile(name string, r io.Reader) (*discord.Message, error)
- func (m *InteractionResponder) ReplyTo(to discord.UserID, text string) (*discord.Message, error)
- func (m *InteractionResponder) Replyf(format string, a ...interface{}) (*discord.Message, error)
- func (m *InteractionResponder) Respond(r Response) (*discord.Message, error)
- func (m *InteractionResponder) Send(text string) (*discord.Message, error)
- func (m *InteractionResponder) SendFile(name string, r io.Reader) (*discord.Message, error)
- func (m *InteractionResponder) Sendf(format string, a ...interface{}) (*discord.Message, error)
- func (m *InteractionResponder) Usage(usage ...string) (*discord.Message, error)
- type InvalidValueError
- type MessageResponder
- func (m *MessageResponder) Acknowledge() error
- func (m *MessageResponder) Reply(text string) (*discord.Message, error)
- func (m *MessageResponder) ReplyEmbed(embed *discord.Embed) (*discord.Message, error)
- func (m *MessageResponder) ReplyFile(name string, r io.Reader) (*discord.Message, error)
- func (m *MessageResponder) ReplyTo(to discord.UserID, text string) (*discord.Message, error)
- func (m *MessageResponder) Replyf(format string, a ...interface{}) (*discord.Message, error)
- func (m *MessageResponder) Respond(r Response) (*discord.Message, error)
- func (m *MessageResponder) Send(text string) (*discord.Message, error)
- func (m *MessageResponder) SendFile(name string, r io.Reader) (*discord.Message, error)
- func (m *MessageResponder) Sendf(format string, a ...interface{}) (*discord.Message, error)
- func (m *MessageResponder) Usage(usage ...string) (*discord.Message, error)
- type MiddlewareFunc
- type Responder
- type Response
- type Route
- func (r *Route) Add(n *Route) *Route
- func (r *Route) Alias(alias string) *Route
- func (r *Route) Argument(name string, f func(*Argument)) *Route
- func (r *Route) Autocomplete(name string, f AutocompleteHandler) *Route
- func (r *Route) Call(ctx *Context) error
- func (r *Route) CallAutocomplete(ctx *Context, options []discord.AutocompleteOption) error
- func (r *Route) Desc(description string) *Route
- func (r *Route) Export(export bool) *Route
- func (r *Route) Find(path ...string) *Route
- func (r *Route) FindAutocomplete(parentRoute string, options []discord.AutocompleteOption) (*Route, []discord.AutocompleteOption)
- func (r *Route) FindComplex(opts FindOpts) *Route
- func (r *Route) FindInteraction(parentRoute string, options []discord.CommandInteractionOption) *Route
- func (r *Route) Group(fn func(*Route)) *Route
- func (r *Route) On(signature string, f Handler) *Route
- func (r *Route) Path() []string
- func (r *Route) RegisterCommand(s *state.State, appID discord.AppID, guildID discord.GuildID) (*discord.Command, error)
- func (r *Route) UpdateCommand(s *state.State, appID discord.AppID, commandID discord.CommandID, ...) (*discord.Command, error)
- func (r *Route) Use(f ...MiddlewareFunc) *Route
- func (r *Route) Validate(ctx *Context) error
- type StringChoice
- type VariableBag
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoUser = errors.New("no user found") ErrNoChannel = errors.New("no channel found") ErrNoRole = errors.New("no role found") )
var ( ErrUnknownOption = errors.New("unknown option") ErrNotAutocomplete = errors.New("option is not registered to autocomplete") )
var (
ErrEmptyText = errors.New("text is empty")
)
var (
UsageError = errors.New("usage")
)
Functions ¶
func RegisterCommands ¶
RegisterCommands registers all sub routes as interaction/slash commands
Types ¶
type Argument ¶
type Argument struct { Index int Name string Description string Required bool Type ArgumentType Choices []StringChoice Min interface{} Max interface{} // contains filtered or unexported fields }
Argument type contains defined arguments, parsed from the command signature
func (*Argument) Autocomplete ¶
func (a *Argument) Autocomplete(f AutocompleteHandler) *Argument
Autocomplete registers an autocomplete handler for this argument
type ArgumentType ¶
type ArgumentType int
const ( ArgumentTypeBasic ArgumentType = iota ArgumentTypeInt ArgumentTypeFloat ArgumentTypeBool ArgumentTypeEmoji ArgumentTypeUserMention ArgumentTypeChannelMention ArgumentTypeRole )
func (ArgumentType) DiscordType ¶
func (t ArgumentType) DiscordType() discord.CommandOptionType
DiscordType returns the Discord CommandOptionType for an argument
type AutocompleteChoice ¶
type AutocompleteHandler ¶
type AutocompleteHandler func(*Context, discord.AutocompleteOption) []StringChoice
AutocompleteHandler is a handler for autocomplete events.
type Context ¶
type Context struct { *VariableBag Session *state.State Event *gateway.MessageCreateEvent Interaction *gateway.InteractionCreateEvent Guild *discord.Guild Channel *discord.Channel Message discord.Message User discord.User Prefix string Command string ArgumentString string Arguments map[string]interface{} ArgumentCount int // contains filtered or unexported fields }
Context is the base "context" object. It contains all fields that are present on both Messages and Interactions.
func ContextFrom ¶
func ContextFrom(state *state.State, event *gateway.MessageCreateEvent, r *Route, args []string) (*Context, error)
ContextFrom creates a new MessageContext from the session and event
func ContextFromInteraction ¶
func ContextFromInteraction(state *state.State, event *gateway.InteractionCreateEvent, r *Route) (*Context, error)
ContextFromInteraction creates a new Context from an interaction event
func (*Context) Acknowledge ¶
func (*Context) ChannelArg ¶
ChannelArg finds and returns a named Channel argument
func (*Context) ChannelArgType ¶
ChannelArgType finds and returns Channel argument with a specified type
func (*Context) ReplyEmbed ¶
type InteractionResponder ¶
type InteractionResponder struct {
// contains filtered or unexported fields
}
func (*InteractionResponder) Acknowledge ¶
func (m *InteractionResponder) Acknowledge() error
func (*InteractionResponder) Reply ¶
func (m *InteractionResponder) Reply(text string) (*discord.Message, error)
Reply with a user mention
func (*InteractionResponder) ReplyEmbed ¶
ReplyEmbed replies to a user with an embed object
func (*InteractionResponder) Replyf ¶
func (m *InteractionResponder) Replyf(format string, a ...interface{}) (*discord.Message, error)
Replyf Builds a message and replies with formatted text
func (*InteractionResponder) Respond ¶
func (m *InteractionResponder) Respond(r Response) (*discord.Message, error)
Respond replies to a user by serializing Response
func (*InteractionResponder) Send ¶
func (m *InteractionResponder) Send(text string) (*discord.Message, error)
Send text to the originating channel
type InvalidValueError ¶
type InvalidValueError struct { Argument string Value interface{} }
InvalidValueError is an error type thrown when a value is invalid/unknown
func (InvalidValueError) Error ¶
func (i InvalidValueError) Error() string
Error constructs a string for the error with the argument and value
type MessageResponder ¶
type MessageResponder struct {
// contains filtered or unexported fields
}
func (*MessageResponder) Acknowledge ¶
func (m *MessageResponder) Acknowledge() error
func (*MessageResponder) Reply ¶
func (m *MessageResponder) Reply(text string) (*discord.Message, error)
Reply to a message
func (*MessageResponder) ReplyEmbed ¶
ReplyEmbed replies to a user with an embed object
func (*MessageResponder) Replyf ¶
func (m *MessageResponder) Replyf(format string, a ...interface{}) (*discord.Message, error)
Replyf Builds a message and replies with formatted text
func (*MessageResponder) Respond ¶
func (m *MessageResponder) Respond(r Response) (*discord.Message, error)
Respond replies to a user by serializing Response
func (*MessageResponder) Send ¶
func (m *MessageResponder) Send(text string) (*discord.Message, error)
Send text to the originating channel
type Responder ¶
type Responder interface { Usage(usage ...string) (*discord.Message, error) Send(text string) (*discord.Message, error) Sendf(format string, a ...interface{}) (*discord.Message, error) SendFile(name string, r io.Reader) (*discord.Message, error) Reply(text string) (*discord.Message, error) Replyf(format string, a ...interface{}) (*discord.Message, error) ReplyTo(to discord.UserID, text string) (*discord.Message, error) ReplyEmbed(embed *discord.Embed) (*discord.Message, error) ReplyFile(name string, r io.Reader) (*discord.Message, error) Respond(r Response) (*discord.Message, error) Acknowledge() error }
Responder represents an available responder This can send messages to channels, direct messages, interactions, etc.
type Route ¶
type Route struct { Name string Usage string Description string Arguments map[string]*Argument ArgumentCount int RequiredArgumentCount int // contains filtered or unexported fields }
Route type contains information about a route, such as middleware, routes, etc
func (*Route) Argument ¶
Argument is a quick helper that lets you pull a route's argument into a func and modify it.
func (*Route) Autocomplete ¶
func (r *Route) Autocomplete(name string, f AutocompleteHandler) *Route
Autocomplete is a helper func to pass through autocomplete functions into options
func (*Route) Call ¶
Call executes a route. Handlers are called synchronously. Sub-routes will no longer be recursed automatically, and must be found using Find(...)
func (*Route) CallAutocomplete ¶
func (r *Route) CallAutocomplete(ctx *Context, options []discord.AutocompleteOption) error
CallAutocomplete calls the autocomplete handler for a route's argument
func (*Route) FindAutocomplete ¶
func (r *Route) FindAutocomplete(parentRoute string, options []discord.AutocompleteOption) (*Route, []discord.AutocompleteOption)
FindAutocomplete finds a route path from an autocomplete interaction
func (*Route) FindComplex ¶
FindComplex finds a route by options, including args, case sensitive matching, etc
func (*Route) FindInteraction ¶
func (r *Route) FindInteraction(parentRoute string, options []discord.CommandInteractionOption) *Route
FindInteraction finds a route path from a command interaction
func (*Route) Group ¶
Group creates a temporary route to use for registering sub routes. All routes will be copied into this route, with middleware applied.
func (*Route) On ¶
On adds a handler for a specific command. Signature can be a simple command, or a string like the following:
command <arg1> <arg2> [arg3] [#channel] [@user]
The library will automatically parse and validate the required arguments. <> means an argument will be required, [] says it's optional As well as required and optional types, you can use # and @ to signify That routes must match a valid user or channel.
func (*Route) RegisterCommand ¶
func (r *Route) RegisterCommand(s *state.State, appID discord.AppID, guildID discord.GuildID) (*discord.Command, error)
RegisterCommand registers a single command, with sub routes as subcommands.
func (*Route) UpdateCommand ¶
func (r *Route) UpdateCommand(s *state.State, appID discord.AppID, commandID discord.CommandID, guildID discord.GuildID) (*discord.Command, error)
UpdateCommand registers a single command, with sub routes as subcommands.
func (*Route) Use ¶
func (r *Route) Use(f ...MiddlewareFunc) *Route
Use applies middleware to this route. All sub-routes will also inherit this middleware.
type StringChoice ¶
StringChoice is a basic wrapper for name/value choices
type VariableBag ¶
type VariableBag struct {
// contains filtered or unexported fields
}
func NewVariableBag ¶
func NewVariableBag() *VariableBag
func (*VariableBag) Get ¶
func (v *VariableBag) Get(key string) interface{}
Get retrieves a variable from the context
func (*VariableBag) Set ¶
func (v *VariableBag) Set(key string, d interface{})
Set sets a variable on the context