Documentation ¶
Index ¶
- Variables
- type Bot
- type BulkCommandSyncer
- type Command
- type CommandSyncer
- type Ctx
- type Handler
- type HandlerFunc
- type MessageCtx
- type MessageHandler
- type MessageHandlerConfig
- type MessageHandlerFunc
- type OptionsMap
- type Router
- func (r *Router) Count() (c int)
- func (r *Router) Get(name string) *Command
- func (r *Router) HandleInteraction(s *discordgo.Session, i *discordgo.InteractionCreate)
- func (r *Router) List() (list []*Command)
- func (r *Router) MakeMessageHandler(cfg *MessageHandlerConfig) func(s *discordgo.Session, m *discordgo.MessageCreate)
- func (r *Router) Register(cmd *Command)
- func (r *Router) Sync(s *discordgo.Session, application, guild string) error
- func (r *Router) Unregister(name string) (command *Command, existed bool)
- func (r *Router) Update(name string, newcmd *Command) (cmd *Command, err error)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCommandNotExists means that the requested command does not exist. ErrCommandNotExists = errors.New("command not exists") )
Functions ¶
This section is empty.
Types ¶
type BulkCommandSyncer ¶
type BulkCommandSyncer struct{}
BulkCommandSyncer syncs all the commands using ApplicationCommandBulkOverwrite function.
type Command ¶
type Command struct { Name string Description string Options []*discordgo.ApplicationCommandOption Type discordgo.ApplicationCommandType Handler Handler Middlewares []Handler MessageHandler MessageHandler MessageMiddlewares []MessageHandler // NOTE: nesting of more than 3 level has no effect SubCommands *Router // Custom payload for the command. Useful for module names, and such stuff. Custom interface{} }
Command represents a command.
func (Command) ApplicationCommand ¶
func (cmd Command) ApplicationCommand() *discordgo.ApplicationCommand
ApplicationCommand converts Command to discordgo.ApplicationCommand.
func (Command) ApplicationCommandOption ¶
func (cmd Command) ApplicationCommandOption() *discordgo.ApplicationCommandOption
ApplicationCommandOption converts Command to discordgo.ApplicationCommandOption (subcommand).
type CommandSyncer ¶
type CommandSyncer interface {
Sync(r *Router, s *discordgo.Session, application, guild string) error
}
A CommandSyncer syncs all the commands with Discord.
type Ctx ¶
type Ctx struct { *discordgo.Session `json:"-"` Caller *Command `json:"caller"` Interaction *discordgo.Interaction `json:"interaction"` Options OptionsMap `json:"options"` OptionsRaw []*discordgo.ApplicationCommandInteractionDataOption `json:"options_raw"` // contains filtered or unexported fields }
Ctx is a context provided to a command. It embeds session for easier use, and contains interaction and preprocessed options.
func NewCtx ¶
func NewCtx(s *discordgo.Session, caller *Command, i *discordgo.Interaction, parent *discordgo.ApplicationCommandInteractionDataOption, handlers []Handler) *Ctx
NewCtx constructs ctx from given parameters.
type HandlerFunc ¶
type HandlerFunc func(ctx *Ctx)
HandlerFunc is a wrapper around Handler for functions
func (HandlerFunc) HandleCommand ¶
func (f HandlerFunc) HandleCommand(ctx *Ctx)
HandleCommand implements Handler interface and calls the function with provided context
type MessageCtx ¶
type MessageCtx struct { *discordgo.Session Caller *Command Message *discordgo.Message Arguments []string // contains filtered or unexported fields }
MessageCtx is a context provided to message command handler. It contains the message
func NewMessageCtx ¶
func NewMessageCtx(s *discordgo.Session, caller *Command, m *discordgo.Message, arguments []string, handlers []MessageHandler) *MessageCtx
NewMessageCtx constructs context from a message. If argdelim is not empty it is a delimiter for the arguments, otherwise the arguments are split by a space.
func (*MessageCtx) Next ¶
func (ctx *MessageCtx) Next()
Next calls the next middleware / command handler.
func (*MessageCtx) Reply ¶
Reply sends and returns a simple (content-only) message replying to the command message. If mention is true the command author is mentioned in the reply. It is a wrapper for discordgo.Session.ChannelMessageSendReply.
func (*MessageCtx) ReplyComplex ¶
func (ctx *MessageCtx) ReplyComplex(message *discordgo.MessageSend, mention bool) (*discordgo.Message, error)
ReplyComplex sends and returns a complex (with embds, attachments, etc) message replying to the command message. If mention is true the command author is mentioned in the reply. It is a wrapper for discordgo.Session.ChannelMessageSendComplex
type MessageHandler ¶
type MessageHandler interface {
HandleMessageCommand(ctx *MessageCtx)
}
A MessageHandler processes the message command
type MessageHandlerConfig ¶
type MessageHandlerFunc ¶
type MessageHandlerFunc func(ctx *MessageCtx)
HandlerFunc is a wrapper around MessageHandler for functions
func (MessageHandlerFunc) HandleMessageCommand ¶
func (f MessageHandlerFunc) HandleMessageCommand(ctx *MessageCtx)
HandleCommand implements MessageHandler interface and calls the function with provided context
type OptionsMap ¶
type OptionsMap = map[string]*discordgo.ApplicationCommandInteractionDataOption
OptionsMap is an alias for map of discordgo.ApplicationCommandInteractionDataOption
type Router ¶
type Router struct { // Commands is a map of registered commands. // Key is command name. Value is command instance. // // NOTE: it is not recommended to use it directly, use Register, Get, Update, Unregister functions instead. Commands map[string]*Command Syncer CommandSyncer }
A Router stores all the commands and routes the interactions
func (*Router) HandleInteraction ¶
func (r *Router) HandleInteraction(s *discordgo.Session, i *discordgo.InteractionCreate)
HandleInteraction is an interaction handler passed to discordgo.Session.AddHandler.
func (*Router) MakeMessageHandler ¶
func (r *Router) MakeMessageHandler(cfg *MessageHandlerConfig) func(s *discordgo.Session, m *discordgo.MessageCreate)
func (*Router) Unregister ¶
Unregister removes a command from router