Documentation ¶
Overview ¶
Package ken provides an object-oriented and highly modular slash command handler for discordgo.
Index ¶
- Variables
- type AutoCompleteOptions
- type AutocompleteCommand
- type AutocompleteContext
- func (t *AutocompleteContext) Channel() (*discordgo.Channel, error)
- func (t *AutocompleteContext) Event() *discordgo.InteractionCreate
- func (c *AutocompleteContext) Get(key string) (v interface{})
- func (t *AutocompleteContext) GetData() discordgo.ApplicationCommandInteractionData
- func (t *AutocompleteContext) GetInput(optionName string) (value string, ok bool)
- func (t *AutocompleteContext) GetKen() *Ken
- func (t *AutocompleteContext) GetSession() *discordgo.Session
- func (t *AutocompleteContext) Guild() (*discordgo.Guild, error)
- func (t *AutocompleteContext) Member() (u *discordgo.Member)
- func (t *AutocompleteContext) ResetState()
- func (t *AutocompleteContext) SubCommand(name ...string) AutoCompleteOptions
- func (t *AutocompleteContext) User() (u *discordgo.User)
- type Command
- type CommandHandler
- type CommandInfo
- type CommandInfoList
- type CommandOption
- type CommandOptions
- type ComponentAssembler
- type ComponentBuilder
- func (t *ComponentBuilder) Add(component discordgo.MessageComponent, handler ComponentHandlerFunc, ...) *ComponentBuilder
- func (t *ComponentBuilder) AddActionsRow(build func(b ComponentAssembler), once ...bool) *ComponentBuilder
- func (t *ComponentBuilder) Build() (unreg func() error, err error)
- func (t *ComponentBuilder) Condition(cond ComponentHandlerFunc) *ComponentBuilder
- type ComponentContext
- type ComponentHandler
- func (t *ComponentHandler) Add(messageId, channelId string) *ComponentBuilder
- func (t *ComponentHandler) AppendToMessage(messageId string, channelId string, components []discordgo.MessageComponent) error
- func (t *ComponentHandler) Register(customId string, handler ComponentHandlerFunc) func()
- func (t *ComponentHandler) Unregister(customId ...string)
- func (t *ComponentHandler) UnregisterDiscordHandler()
- type ComponentHandlerFunc
- type Context
- type ContextResponder
- type Ctx
- func (c *Ctx) Channel() (*discordgo.Channel, error)
- func (c *Ctx) Defer() (err error)
- func (c *Ctx) FollowUp(wait bool, data *discordgo.WebhookParams) (fumb *FollowUpMessageBuilder)
- func (c *Ctx) FollowUpEmbed(emb *discordgo.MessageEmbed) (fumb *FollowUpMessageBuilder)
- func (c *Ctx) FollowUpError(content, title string) (fumb *FollowUpMessageBuilder)
- func (c *Ctx) FollowUpMessage(message string) (fumb *FollowUpMessageBuilder)
- func (c *Ctx) Get(key string) (v interface{})
- func (c *Ctx) GetCommand() Command
- func (c *Ctx) GetEphemeral() bool
- func (c *Ctx) GetEvent() *discordgo.InteractionCreate
- func (c *Ctx) GetKen() *Ken
- func (c *Ctx) GetSession() *discordgo.Session
- func (c *Ctx) Guild() (*discordgo.Guild, error)
- func (c *Ctx) HandleSubCommands(handler ...CommandHandler) (err error)
- func (c *Ctx) MessageCommand() (cmd MessageCommand, ok bool)
- func (c *Ctx) Options() CommandOptions
- func (c *Ctx) ResetState()
- func (c *Ctx) Respond(r *discordgo.InteractionResponse) (err error)
- func (c *Ctx) RespondEmbed(emb *discordgo.MessageEmbed) (err error)
- func (c *Ctx) RespondError(content, title string) (err error)
- func (c *Ctx) RespondMessage(message string) (err error)
- func (c *Ctx) SetEphemeral(v bool)
- func (c *Ctx) SlashCommand() (cmd SlashCommand, ok bool)
- func (c *Ctx) User() (u *discordgo.User)
- func (c *Ctx) UserCommand() (cmd UserCommand, ok bool)
- type DmCapable
- type EmbedColors
- type EphemeralCommand
- type FollowUpMessage
- func (m *FollowUpMessage) AddComponents() *ComponentBuilder
- func (m *FollowUpMessage) Delete() (err error)
- func (m *FollowUpMessage) DeleteAfter(d time.Duration) *FollowUpMessage
- func (m *FollowUpMessage) Edit(data *discordgo.WebhookEdit) (err error)
- func (m *FollowUpMessage) EditEmbed(emb *discordgo.MessageEmbed) (err error)
- func (m *FollowUpMessage) HasError() bool
- func (m *FollowUpMessage) UnregisterComponentHandlers() error
- type FollowUpMessageBuilder
- type GuildScopedCommand
- type IKen
- type Ken
- func (k *Ken) Components() *ComponentHandler
- func (k *Ken) GetCommandInfo(keyTransformer ...KeyTransformerFunc) (cis CommandInfoList)
- func (k *Ken) RegisterCommands(cmds ...Command) (err error)
- func (k *Ken) RegisterMiddlewares(mws ...interface{}) (err error)
- func (k *Ken) Session() *discordgo.Session
- func (k *Ken) Unregister() (err error)
- type KeyTransformerFunc
- type MessageCommand
- type MessageComponent
- type Middleware
- type MiddlewareAfter
- type MiddlewareBefore
- type ModalContext
- type ModalHandlerFunc
- type ObjectInjector
- type ObjectMap
- type ObjectProvider
- type Options
- type ResponsePolicy
- type ResponsePolicyCommand
- type SlashCommand
- type SubCommandContext
- type SubCommandGroup
- type SubCommandHandler
- type UserCommand
Constants ¶
This section is empty.
Variables ¶
var ( ErrEmptyCommandName = errors.New("command name can not be empty") ErrCommandAlreadyRegistered = errors.New("command with the same name has already been rgistered") ErrInvalidMiddleware = errors.New("the instance must implement MiddlewareBefore, MiddlewareAfter or both") ErrNotDMCapable = errors.New("The executed command is not able to be executed in DMs") )
Functions ¶
This section is empty.
Types ¶
type AutoCompleteOptions ¶ added in v0.20.0
type AutoCompleteOptions struct {
// contains filtered or unexported fields
}
func (AutoCompleteOptions) GetInput ¶ added in v0.20.0
func (t AutoCompleteOptions) GetInput(optionName string) (value string, ok bool)
func (AutoCompleteOptions) Name ¶ added in v0.20.0
func (t AutoCompleteOptions) Name() string
type AutocompleteCommand ¶ added in v0.19.0
type AutocompleteCommand interface { // Autocomplete will be called every time an autocomplete input event has veen received // for the registered command. It is getting passed a context which contains the event // data. // // Return the choises that shall be displayed or an error if something went wrong // during fetching the choises. // // The context object should not be used after the handler call has been completed. Autocomplete(ctx *AutocompleteContext) ([]*discordgo.ApplicationCommandOptionChoice, error) }
AutocompleteCommand can be implemented by your command to enable autocomplete support for your command options.
type AutocompleteContext ¶ added in v0.19.0
type AutocompleteContext struct { ObjectMap // contains filtered or unexported fields }
AutocompleteContext provides easy acces to the underlying event data.
func (*AutocompleteContext) Channel ¶ added in v0.19.0
func (t *AutocompleteContext) Channel() (*discordgo.Channel, error)
Channel tries to fetch the channel object from the contained channel ID using the specified state manager.
func (*AutocompleteContext) Event ¶ added in v0.19.0
func (t *AutocompleteContext) Event() *discordgo.InteractionCreate
Event returns the underlying InteractionCreate event.
func (*AutocompleteContext) Get ¶ added in v0.20.0
func (c *AutocompleteContext) Get(key string) (v interface{})
Get either returns an instance from the internal object map - if existent. Otherwise, the object is looked up in the specified dependency provider, if available. When no object was found in either of both maps, nil is returned.
func (*AutocompleteContext) GetData ¶ added in v0.19.0
func (t *AutocompleteContext) GetData() discordgo.ApplicationCommandInteractionData
GetData returns the ApplicationCommandInteractionData of the internal event.
func (*AutocompleteContext) GetInput ¶ added in v0.19.0
func (t *AutocompleteContext) GetInput(optionName string) (value string, ok bool)
GetInput takes the name of a command option and returns the input value from the event for that option.
If ok is false, no value could be found for the given option.
func (*AutocompleteContext) GetKen ¶ added in v0.19.0
func (t *AutocompleteContext) GetKen() *Ken
GetKen returns the Ken instance.
func (*AutocompleteContext) GetSession ¶ added in v0.19.0
func (t *AutocompleteContext) GetSession() *discordgo.Session
GetSession returns the Discordgo Session instance.
func (*AutocompleteContext) Guild ¶ added in v0.19.0
func (t *AutocompleteContext) Guild() (*discordgo.Guild, error)
Guild tries to fetch the guild object from the contained guild ID using the specified state manager.
func (*AutocompleteContext) Member ¶ added in v0.19.0
func (t *AutocompleteContext) Member() (u *discordgo.Member)
Member returns the user object of the event caller. It may be nil if no member has been set to the event.
func (*AutocompleteContext) ResetState ¶ added in v0.19.0
func (t *AutocompleteContext) ResetState()
func (*AutocompleteContext) SubCommand ¶ added in v0.20.0
func (t *AutocompleteContext) SubCommand(name ...string) AutoCompleteOptions
SubCommand returns the sub command options for any of the given sub command or sub command group. If no command name is passed, the sub command options are returned from the first sub command found in the event.
func (*AutocompleteContext) User ¶ added in v0.19.0
func (t *AutocompleteContext) User() (u *discordgo.User)
User returns the user object of the event caller. It may be nil if no user has been set to the event.
type Command ¶
type Command interface { // Name returns the unique name of the command. Name() string // Description returns a brief text which concisely // describes the commands purpose. // // Currently, this is ignored by user and message // commands, because the API currently does not // support descriptions for these types of // application commands. Description() string // Run is called on command invokation getting // passed the invocation context. // // When something goes wrong during command // execution, you can return an error which is // then handled by Ken's OnCommandError handler. Run(ctx Context) (err error) }
Command specifies the base interface for an application command.
type CommandHandler ¶ added in v0.20.0
type CommandHandler interface { Type() discordgo.ApplicationCommandOptionType OptionName() string RunHandler(ctx SubCommandContext) error }
CommandHandler defines either a SubCommandHandler or a SubCommandGroup.
type CommandInfo ¶ added in v0.7.0
type CommandInfo struct { ApplicationCommand *discordgo.ApplicationCommand `json:"application_command"` Implementations map[string][]interface{} `json:"implementations"` }
CommandInfo contains the parsed application command structure of a command as well as additional method implementations. This also includes external implementations aside from the Command interface.
func (CommandInfo) String ¶ added in v0.7.0
func (c CommandInfo) String() string
String returns the parsed JSON data of the CommandInfo.
type CommandInfoList ¶ added in v0.7.0
type CommandInfoList []*CommandInfo
CommandInfoList is a slice of CommandInfo elements.
func (CommandInfoList) String ¶ added in v0.7.0
func (c CommandInfoList) String() string
String returns the parsed JSON data of the CommandInfoList.
type CommandOption ¶ added in v0.3.0
type CommandOption struct {
*discordgo.ApplicationCommandInteractionDataOption
}
CommandOption wraps a ApplicationCommandInteractionDataOption to provide additional functionalities and method overrides.
func (*CommandOption) ChannelValue ¶ added in v0.3.0
func (o *CommandOption) ChannelValue(ctx Context) *discordgo.Channel
ChannelValue is a utility function for casting option value to channel object.
The object is taken from the specified state instance.
func (*CommandOption) RoleValue ¶ added in v0.3.0
func (o *CommandOption) RoleValue(ctx Context) *discordgo.Role
RoleValue is a utility function for casting option value to role object.
The object is taken from the specified state instance.
func (*CommandOption) StringValue ¶ added in v0.8.0
func (o *CommandOption) StringValue() (v string)
StringValue is a utility function for casting option value to string.
Because you can not pass multiline string entries to slash commands, this converts `\n` in a message to an actual line break.
type CommandOptions ¶ added in v0.2.0
type CommandOptions []*discordgo.ApplicationCommandInteractionDataOption
CommandOptions provides additional functionailities to an array of ApplicationCommandInteractionDataOptions.
func (CommandOptions) Get ¶ added in v0.2.0
func (co CommandOptions) Get(i int) *CommandOption
Get safely returns an options from command options by index.
func (CommandOptions) GetByName ¶ added in v0.2.0
func (co CommandOptions) GetByName(name string) (opt *CommandOption)
GetByName returns an option by name.
This should only be used on required options.
func (CommandOptions) GetByNameOptional ¶ added in v0.2.0
func (co CommandOptions) GetByNameOptional(name string) (opt *CommandOption, ok bool)
GetByNameOptional returns an option by name. If the option with the name does not exist, the returned value for ok is false.
This should be used for non-required options.
func (CommandOptions) Options ¶ added in v0.2.0
func (co CommandOptions) Options(i int) CommandOptions
Options returns wrapped underlying options of a sub command by ID.
type ComponentAssembler ¶ added in v0.15.0
type ComponentAssembler interface { // AddActionsRow adds an Action Row component to // the message. Use the builder passed by the // build function to assemble the components of // the Action Row. // // If you pass once as `true`, after the first // interaction inside the Action Row, all handlers // of the Action Row children are removed as well // as the Action Row component itself from the message. AddActionsRow(build func(b ComponentAssembler), once ...bool) ComponentAssembler // Add appends the passed message component to the // message with the given handler called on // interaction with the component. // // If you pass once as `true`, the handler is // removed after interaction with the component // as well as the component itself from the message. Add( component discordgo.MessageComponent, handler ComponentHandlerFunc, once ...bool, ) ComponentAssembler }
ComponentAssembler helps to build the message component tree.
type ComponentBuilder ¶ added in v0.15.0
type ComponentBuilder struct {
// contains filtered or unexported fields
}
ComponentBuilder helps to build the message component tree, attaches the components to the given message and registers the interaction handlers for the given components.
func (*ComponentBuilder) Add ¶ added in v0.15.0
func (t *ComponentBuilder) Add( component discordgo.MessageComponent, handler ComponentHandlerFunc, once ...bool, ) *ComponentBuilder
Add appends the passed message component to the message with the given handler called on interaction with the component.
If you pass once as `true`, the handler is removed after interaction with the component as well as the component itself from the message.
func (*ComponentBuilder) AddActionsRow ¶ added in v0.15.0
func (t *ComponentBuilder) AddActionsRow(build func(b ComponentAssembler), once ...bool) *ComponentBuilder
AddActionsRow adds an Action Row component to the message. Use the builder passed by the build function to assemble the components of the Action Row.
If you pass once as `true`, after the first interaction inside the Action Row, all handlers of the Action Row children are removed as well as the Action Row component itself from the message.
func (*ComponentBuilder) Build ¶ added in v0.15.0
func (t *ComponentBuilder) Build() (unreg func() error, err error)
Build attaches the registered messgae components to the specified message and registers the interaction handlers to the handler registry.
It returns an unregister function which can be called to remove all message components appendet and and all interaction handler registered with this builder.
func (*ComponentBuilder) Condition ¶ added in v0.17.1
func (t *ComponentBuilder) Condition(cond ComponentHandlerFunc) *ComponentBuilder
Condition sets a condition handler which needs to be met so that the component handler is activated.
type ComponentContext ¶ added in v0.15.0
type ComponentContext interface { ContextResponder // GetData returns the underlying // MessageComponentInteractionData. GetData() discordgo.MessageComponentInteractionData // OpenModal opens a new modal with the given // title, content and components built with the // passed build function. A channel is returned // which will receive a ModalContext when the user // has interacted with the modal. OpenModal( title string, content string, build func(b ComponentAssembler), ) (<-chan ModalContext, error) }
ComponentContext gives access to the underlying MessageComponentInteractionData and gives the ability to open a Modal afterwards.
type ComponentHandler ¶ added in v0.15.0
type ComponentHandler struct {
// contains filtered or unexported fields
}
ComponentHandler keeps a registry of component handler callbacks to be executed when a given component has been interacted with.
func NewComponentHandler ¶ added in v0.15.0
func NewComponentHandler(ken *Ken) *ComponentHandler
NewComponentHandler returns a new instance of ComponentHandler using the given instance of Ken.
func (*ComponentHandler) Add ¶ added in v0.15.0
func (t *ComponentHandler) Add(messageId, channelId string) *ComponentBuilder
Add returns a new ComponentBuilder which attaches the added components to the given message by messageId and channelId on build.
func (*ComponentHandler) AppendToMessage ¶ added in v0.15.0
func (t *ComponentHandler) AppendToMessage( messageId string, channelId string, components []discordgo.MessageComponent, ) error
AppendToMessage edits the given message by messageId and channelId which adds the passed message components to the message.
func (*ComponentHandler) Register ¶ added in v0.15.0
func (t *ComponentHandler) Register(customId string, handler ComponentHandlerFunc) func()
Register registers a raw ComponentHandlerFunc which is fired when the component with the specified customId has been interacted with.
Te returned function unregisters the specified handler from the registry but does not remove the added message components from the message.
Registering a handler twice on the smae customId overwrites the previously registered handler function.
func (*ComponentHandler) Unregister ¶ added in v0.15.0
func (t *ComponentHandler) Unregister(customId ...string)
Unregister removes one or more handlers from the registry set to the given customId(s) of the message component(s).
func (*ComponentHandler) UnregisterDiscordHandler ¶ added in v0.15.0
func (t *ComponentHandler) UnregisterDiscordHandler()
UnregisterDiscordHandler removes the Discord event handler function from the internal DiscordGo Session.
type ComponentHandlerFunc ¶ added in v0.15.0
type ComponentHandlerFunc func(ctx ComponentContext) bool
ComponentHandleFunc is the handler function for message component interactions. It is getting passed a ComponentContext which contians the interaction event data and can be used to respond to the interaction.
A boolean is returned to indicate the success of the execution of the handler.
type Context ¶ added in v0.13.0
type Context interface { ContextResponder ObjectProvider safepool.ResetState // Channel tries to fetch the channel object from the contained // channel ID using the specified state manager. Channel() (*discordgo.Channel, error) // Channel tries to fetch the guild object from the contained // guild ID using the specified state manager. Guild() (*discordgo.Guild, error) // Options returns the application command data options // with additional functionality methods. Options() CommandOptions // SlashCommand returns the contexts Command as a // SlashCommand interface. SlashCommand() (cmd SlashCommand, ok bool) // UserCommand returns the contexts Command as a // UserCommand interface. UserCommand() (cmd UserCommand, ok bool) // MessageCommand returns the contexts Command as a // MessageCommand interface. MessageCommand() (cmd MessageCommand, ok bool) // HandleSubCommands takes a list of sub command handles. // When the command is executed, the options are scanned // for the sib command calls by their names. If one of // the registered sub commands has been called, the specified // handler function is executed. // // If the call occured, the passed handler function is // getting passed the scoped sub command Ctx. // // The SubCommandCtx passed must not be stored or used // after command execution. HandleSubCommands(handler ...CommandHandler) (err error) // GetKen returns the root instance of Ken. GetKen() *Ken // GetCommand returns the command instance called. GetCommand() Command }
Context defines the implementation of an interaction command context passed to the command handler.
type ContextResponder ¶ added in v0.15.0
type ContextResponder interface { // Respond to an interaction event with the given // interaction response payload. // // When an interaction has already been responded to, // the response will be edited instead on execution. Respond(r *discordgo.InteractionResponse) (err error) // RespondMessage is shorthand for Respond with a simple // message as response content. RespondMessage(message string) (err error) // RespondEmbed is shorthand for Respond with an // embed payload as passed. RespondEmbed(emb *discordgo.MessageEmbed) (err error) // RespondError is shorthand for RespondEmbed with an // error embed as message with the passed content and // title. RespondError(content, title string) (err error) // FollowUp creates a follow up message to the // interaction event and returns a FollowUpMessage // object containing the created message as well as // an error instance, if an error occurred. // // This way it allows to be chained in one call with // subsequent FollowUpMessage method calls. FollowUp(wait bool, data *discordgo.WebhookParams) (fumb *FollowUpMessageBuilder) // FollowUpEmbed is shorthand for FollowUp with a simple // message as response content. FollowUpMessage(message string) (fumb *FollowUpMessageBuilder) // FollowUpEmbed is shorthand for FollowUp with an // embed payload as passed. FollowUpEmbed(emb *discordgo.MessageEmbed) (fumb *FollowUpMessageBuilder) // FollowUpError is shorthand for FollowUpEmbed with an // error embed as message with the passed content and // title. FollowUpError(content, title string) (fumb *FollowUpMessageBuilder) // Defer is shorthand for Respond with an InteractionResponse // of the type InteractionResponseDeferredChannelMessageWithSource. // // It should be used when the interaction response can not be // instantly returned. Defer() (err error) // GetEphemeral returns the current emphemeral state // of the command invokation. GetEphemeral() bool // SetEphemeral sets the emphemeral state of the command // invokation. // // Ephemeral can be set to true which will // send all subsequent command responses // only to the user which invoked the command. SetEphemeral(v bool) // GetSession returns the current Discordgo session instance. GetSession() *discordgo.Session // GetEvent returns the InteractionCreate event instance which // invoked the interaction command. GetEvent() *discordgo.InteractionCreate // User returns the User object of the executor either from // the events User object or from the events Member object. User() (u *discordgo.User) }
ContextResponder defines the implementation of an interaction context with functionalities to respond to the interaction, to set the ephemeral state and to retrieve the nested session and event.
type Ctx ¶
type Ctx struct { ObjectMap // Command provides the called command instance. Command Command // contains filtered or unexported fields }
Ctx holds the invokation context of a command.
The Ctx must not be stored or used after command execution.
func (*Ctx) Channel ¶
Channel tries to fetch the channel object from the contained channel ID using the specified state manager.
func (*Ctx) FollowUp ¶
func (c *Ctx) FollowUp(wait bool, data *discordgo.WebhookParams) (fumb *FollowUpMessageBuilder)
func (*Ctx) FollowUpEmbed ¶
func (c *Ctx) FollowUpEmbed(emb *discordgo.MessageEmbed) (fumb *FollowUpMessageBuilder)
func (*Ctx) FollowUpError ¶
func (c *Ctx) FollowUpError(content, title string) (fumb *FollowUpMessageBuilder)
func (*Ctx) FollowUpMessage ¶ added in v0.20.0
func (c *Ctx) FollowUpMessage(message string) (fumb *FollowUpMessageBuilder)
func (*Ctx) Get ¶
Get either returns an instance from the internal object map - if existent. Otherwise, the object is looked up in the specified dependency provider, if available. When no object was found in either of both maps, nil is returned.
func (*Ctx) GetCommand ¶ added in v0.13.0
GetCommand returns the command instance called.
func (*Ctx) GetEphemeral ¶ added in v0.13.0
func (c *Ctx) GetEphemeral() bool
func (*Ctx) GetEvent ¶ added in v0.13.0
func (c *Ctx) GetEvent() *discordgo.InteractionCreate
func (*Ctx) GetSession ¶ added in v0.13.0
func (*Ctx) Guild ¶
Guild tries to fetch the guild object from the contained guild ID using the specified state manager.
func (*Ctx) HandleSubCommands ¶ added in v0.6.0
func (c *Ctx) HandleSubCommands(handler ...CommandHandler) (err error)
HandleSubCommands takes a list of sub command handles. When the command is executed, the options are scanned for the sib command calls by their names. If one of the registered sub commands has been called, the specified handler function is executed.
If the call occured, the passed handler function is getting passed the scoped sub command Ctx.
The SubCommandCtx passed must not be stored or used after command execution.
func (*Ctx) MessageCommand ¶ added in v0.11.0
func (c *Ctx) MessageCommand() (cmd MessageCommand, ok bool)
MessageCommand returns the contexts Command as a MessageCommand interface.
func (*Ctx) Options ¶ added in v0.2.0
func (c *Ctx) Options() CommandOptions
Options returns the application command data options with additional functionality methods.
func (*Ctx) ResetState ¶ added in v0.19.0
func (c *Ctx) ResetState()
func (*Ctx) Respond ¶
func (c *Ctx) Respond(r *discordgo.InteractionResponse) (err error)
func (*Ctx) RespondEmbed ¶ added in v0.10.0
func (c *Ctx) RespondEmbed(emb *discordgo.MessageEmbed) (err error)
func (*Ctx) RespondError ¶ added in v0.10.0
func (*Ctx) RespondMessage ¶ added in v0.19.0
func (*Ctx) SetEphemeral ¶ added in v0.13.0
func (c *Ctx) SetEphemeral(v bool)
func (*Ctx) SlashCommand ¶ added in v0.11.0
func (c *Ctx) SlashCommand() (cmd SlashCommand, ok bool)
SlashCommand returns the contexts Command as a SlashCommand interface.
func (*Ctx) User ¶
User returns the User object of the executor either from the events User object or from the events Member object.
func (*Ctx) UserCommand ¶ added in v0.11.0
func (c *Ctx) UserCommand() (cmd UserCommand, ok bool)
UserCommand returns the contexts Command as a UserCommand interface.
type DmCapable ¶
type DmCapable interface { // IsDmCapable returns true if the command can // be used in DMs. IsDmCapable() bool }
DmCapable extends a command to specify if it is able to be executed in DMs or not.
type EmbedColors ¶
type EmbedColors struct { // Default defines the default embed color used when // no other color is specified. Default int // Error specifies the embed color of error embeds. Error int }
EmbedColors lets you define custom colors for embeds.
type EphemeralCommand ¶ added in v0.12.1
type EphemeralCommand struct{}
EphemeralCommand can be added to your command to make all command responses ephemeral. This means, that all responses to the command from the bot will only be received by the sender of the command.
func (EphemeralCommand) ResponsePolicy ¶ added in v0.12.1
func (EphemeralCommand) ResponsePolicy() ResponsePolicy
type FollowUpMessage ¶
type FollowUpMessage struct { *discordgo.Message // Error contains the error instance of // error occurrences during method execution. Error error // contains filtered or unexported fields }
FollowUpMessage wraps an interaction follow up message and collected errors.
func (*FollowUpMessage) AddComponents ¶ added in v0.15.0
func (m *FollowUpMessage) AddComponents() *ComponentBuilder
AddComponents returns a new component builder to add message components with handlers to the FollowUpMessage.
func (*FollowUpMessage) Delete ¶
func (m *FollowUpMessage) Delete() (err error)
Delete removes the follow up message.
func (*FollowUpMessage) DeleteAfter ¶
func (m *FollowUpMessage) DeleteAfter(d time.Duration) *FollowUpMessage
DeleteAfter queues a deletion of the follow up message after the specified duration.
func (*FollowUpMessage) Edit ¶
func (m *FollowUpMessage) Edit(data *discordgo.WebhookEdit) (err error)
Edit overwrites the given follow up message with the data specified.
func (*FollowUpMessage) EditEmbed ¶ added in v0.7.1
func (m *FollowUpMessage) EditEmbed(emb *discordgo.MessageEmbed) (err error)
EditEmbed is shorthand for edit with the passed embed as WebhookEdit data.
func (*FollowUpMessage) HasError ¶ added in v0.15.0
func (m *FollowUpMessage) HasError() bool
HasError returns true if the value of Error is not nil.
func (*FollowUpMessage) UnregisterComponentHandlers ¶ added in v0.18.0
func (m *FollowUpMessage) UnregisterComponentHandlers() error
UnregisterComponentHandlers removes all handlers of attached componets from the register.
type FollowUpMessageBuilder ¶ added in v0.18.0
type FollowUpMessageBuilder struct {
// contains filtered or unexported fields
}
FollowUpMessageBuilder builds a followup message interaction response.
func (*FollowUpMessageBuilder) AddComponents ¶ added in v0.18.0
func (b *FollowUpMessageBuilder) AddComponents(cb func(*ComponentBuilder)) *FollowUpMessageBuilder
AddComponents is getting passed a builder function where you can attach message components and handlers which will be applied to the followup message when sent.
func (*FollowUpMessageBuilder) Send ¶ added in v0.18.0
func (b *FollowUpMessageBuilder) Send() *FollowUpMessage
Send builds the followup message and sends it as response to the interaction.
type GuildScopedCommand ¶ added in v0.15.0
type GuildScopedCommand interface {
Guild() string
}
GuildScopedCommand can be implemented by your commands to scope them to specific guilds.
The command then will be only registered on the guild returned by the Guild method.
type IKen ¶ added in v0.17.0
type IKen interface { Components() *ComponentHandler GetCommandInfo(keyTransformer ...KeyTransformerFunc) (cis CommandInfoList) RegisterCommands(cmds ...Command) (err error) RegisterMiddlewares(mws ...interface{}) (err error) Session() *discordgo.Session Unregister() (err error) }
type Ken ¶
type Ken struct {
// contains filtered or unexported fields
}
Ken is the handler to register, manage and life-cycle commands as well as middlewares.
func New ¶
New initializes a new instance of Ken with the passed discordgo Session s and optional Options.
If no options are passed, default parameters will be applied.
func (*Ken) Components ¶ added in v0.15.0
func (k *Ken) Components() *ComponentHandler
Components returns the component handler.
func (*Ken) GetCommandInfo ¶ added in v0.7.0
func (k *Ken) GetCommandInfo(keyTransformer ...KeyTransformerFunc) (cis CommandInfoList)
GetCommandInfo returns a list with information about all registered commands.
This call is defaultly cached after first execution because it uses reflection to inspect external implementations. Because this can be performance straining when the method is called frequently, the result is cached until the number of commands changes.
If you want to disable this behavior, you can set Config.DisableCommandInfoCache to true on intializing Ken.
func (*Ken) RegisterCommands ¶
RegisterCommands registers the passed commands to the command register.
Keep in mind that commands are registered by Name, so there can be only one single command per name.
func (*Ken) RegisterMiddlewares ¶
RegisterMiddlewares allows to register passed commands to the middleware callstack.
Therefore, you can register MiddlewareBefore, which is called before the command handler is executed, or MiddlewareAfter, which is called directly after the command handler has been called. Of course, you can also implement both interfaces in the same middleware.
The middleware call order is determined by the order of middleware registration in each area ('before' or 'after').
func (*Ken) Unregister ¶
Unregister should be called to cleanly unregister all registered slash commands from the discord backend.
This can be skipped if you are using a CommandStore.
type KeyTransformerFunc ¶ added in v0.17.0
type MessageCommand ¶ added in v0.11.0
type MessageCommand interface { Command // TypeMessage is used to differenciate between // UserCommand and MessageCommand which have // the same structure otherwise. // // This method must only be implemented and // will never be called by ken, so it can be // completely empty. TypeMessage() }
MessageCommand defines a callable message command.
type MessageComponent ¶ added in v0.17.0
type MessageComponent struct {
discordgo.MessageComponent
}
func (MessageComponent) GetValue ¶ added in v0.17.0
func (t MessageComponent) GetValue() string
func (MessageComponent) IsEmpty ¶ added in v0.17.0
func (t MessageComponent) IsEmpty() bool
type Middleware ¶
type Middleware interface { MiddlewareBefore MiddlewareAfter }
Middleware combines MiddlewareBefore and MiddlewareAfter.
type MiddlewareAfter ¶
type MiddlewareAfter interface { // After is called after a command has been executed. // // It is getting passed the Ctx which was also passed // to the command Run handler. Also, the method is // getting passed potential errors which were returned // from the executed command to be custom handled. // // The error returned is finally passed to the // OnCommandError handler. After(ctx *Ctx, cmdError error) (err error) }
MiddlewareAfter specifies a middleware which is called after the execution of a command.
type MiddlewareBefore ¶
type MiddlewareBefore interface { // Before is called before a command is executed. // It is getting passed the same context as which // will be passed to the command. So you are able // to attach or alter data of the context. // // Ctx contains an ObjectMap which can be used to // pass data to the command. // // The method returns a bool which specifies if // the subsequent command should be executed. If // it is set to false, the execution will be // canceled. // // The error return value is either bubbled up to // the OnCommandError, when next is set to false. // Otherwise, the error is passed to OnCommandError // but the execution continues. Before(ctx *Ctx) (next bool, err error) }
MiddlewareBefore specifies a middleware which is called before the execution of a command.
type ModalContext ¶ added in v0.17.0
type ModalContext interface { ContextResponder // GetData returns the underlying // ModalSubmitInteractionData. GetData() discordgo.ModalSubmitInteractionData // GetComponentByID tries to find a message component // by CustomID in the response data and returns it // wrapped into MessageComponent. // // The returned MessageComponent will contain a nil // value for the wrapped discordgo.MessageComponent // if it could not be found in the response. // // Subsequent method calls to MessageComponent will // not fail though to ensure the ability to chain // method calls. GetComponentByID(customId string) MessageComponent }
ModalContext provides access to the underlying ModalSubmitInteractionData and some utility methods to access component data from the response.
type ModalHandlerFunc ¶ added in v0.17.0
type ModalHandlerFunc func(ctx ModalContext) bool
type ObjectInjector ¶
type ObjectInjector interface { // Set stores the given object by given // key. Set(key string, obj interface{}) }
ObjectInjector specifies an instance which allows storing an object by string key.
type ObjectMap ¶
type ObjectMap interface { ObjectProvider ObjectInjector // Purge cleans all stored objects and // keys from the provider. Purge() }
ObjectMap combines ObjectProvider and ObjectInjector.
type ObjectProvider ¶
type ObjectProvider interface { // Get returns a stored object by its // key, if existent. Get(key string) interface{} }
ObjectProvider specifies an instance providing objects by string key.
type Options ¶
type Options struct { // State specifies the state manager to be used. // When not specified, the default discordgo state // manager is used. State state.State // CommandStore specifies a storage instance to // cache created commands. CommandStore store.CommandStore // DependencyProvider can be used to inject dependencies // to be used in a commands or middlewares Ctx by // a string key. DependencyProvider ObjectProvider // EmbedColors lets you define custom colors for embeds. EmbedColors EmbedColors // DisableCommandInfoCache disabled caching // the result of Ken#GetCommandInfo() after // first call of the method. // // Only disable if you change information of // a command during runtime. DisableCommandInfoCache bool // OnSystemError is called when a recoverable // system error occurs inside Ken's lifecycle. OnSystemError func(context string, err error, args ...interface{}) // OnCommandError is called when an error occurs // during middleware or command execution. OnCommandError func(err error, ctx *Ctx) // OnEventError is called when any other user // event based error occured. OnEventError func(context string, err error) }
Options holds configurations for Ken.
type ResponsePolicy ¶ added in v0.12.1
type ResponsePolicy struct { // When set to true, the command response will // only be received by the sender of the command. // // This sets the `Ephemeral` flag of the `Context` // to true before any middleware is invoked. So, // you are able to modify the ephemeral flag either // in your middleware or directly in your command // logic, if you desire. Ephemeral bool }
ResponsePolicy describes rules for context followups and responses.
type ResponsePolicyCommand ¶ added in v0.12.1
type ResponsePolicyCommand interface {
ResponsePolicy() ResponsePolicy
}
ResponsePolicyCommand defines a command which provides a ResponsePolicy.
type SlashCommand ¶ added in v0.11.0
type SlashCommand interface { Command // Version returns the commands semantic version. Version() string // Options returns an array of application // command options. Options() []*discordgo.ApplicationCommandOption }
SlashCommand defines a callable slash command.
type SubCommandContext ¶ added in v0.17.0
type SubCommandContext interface { Context // GetSubCommandName returns the sub command // name which has been invoked. GetSubCommandName() string }
SubCommandContext wraps the current command Context and with the called sub command name and scopes the command options to the options of the called sub command.
The SubCommandCtx must not be stored or used after command execution.
type SubCommandGroup ¶ added in v0.20.0
type SubCommandGroup struct { Name string SubHandler []CommandHandler }
SubCommandGroup is the handler used to group sub commands.
func (SubCommandGroup) OptionName ¶ added in v0.20.0
func (t SubCommandGroup) OptionName() string
func (SubCommandGroup) RunHandler ¶ added in v0.20.0
func (t SubCommandGroup) RunHandler(ctx SubCommandContext) error
func (SubCommandGroup) Type ¶ added in v0.20.0
func (t SubCommandGroup) Type() discordgo.ApplicationCommandOptionType
type SubCommandHandler ¶ added in v0.5.0
type SubCommandHandler struct { Name string Run func(ctx SubCommandContext) error }
SubCommandHandler is the handler function used to handle sub command calls.
func (SubCommandHandler) OptionName ¶ added in v0.20.0
func (t SubCommandHandler) OptionName() string
func (SubCommandHandler) RunHandler ¶ added in v0.20.0
func (t SubCommandHandler) RunHandler(ctx SubCommandContext) error
func (SubCommandHandler) Type ¶ added in v0.20.0
func (t SubCommandHandler) Type() discordgo.ApplicationCommandOptionType
type UserCommand ¶ added in v0.11.0
type UserCommand interface { Command // TypeUser is used to differenciate between // UserCommand and MessageCommand which have // the same structure otherwise. // // This method must only be implemented and // will never be called by ken, so it can be // completely empty. TypeUser() }
UserCommand defines a callable user command.