Documentation
¶
Overview ¶
Package Kombo is a simple, yet powerful command handler for the [DisGo].
Index ¶
- type Command
- type CommandHandler
- type CommandOption
- func WithDescription(description string) CommandOption
- func WithDescriptionLocalization(locale discord.Locale, description string) CommandOption
- func WithHandler(handler HandlerFunc) CommandOption
- func WithLocalizedDescription(locale discord.Locale, key string) CommandOption
- func WithLocalizedName(locale discord.Locale, key string) CommandOption
- func WithNSFW(nsfw bool) CommandOption
- func WithName(name string) CommandOption
- func WithNameLocalization(locale discord.Locale, name string) CommandOption
- func WithOption(option discord.ApplicationCommandOption) CommandOption
- func WithOptions(options []discord.ApplicationCommandOption) CommandOption
- func WithSubCommand(subCommand ...CommandOption) CommandOption
- type Context
- type HandlerFunc
- type Locale
- type LocalizationManager
- type Reply
- type ReplyOption
- func WithContent(content string, vars ...any) ReplyOption
- func WithEmbed(embed discord.Embed) ReplyOption
- func WithEmbeds(embeds ...discord.Embed) ReplyOption
- func WithEphemeral(ephemeral bool) ReplyOption
- func WithFile(file *discord.File) ReplyOption
- func WithFiles(files ...*discord.File) ReplyOption
- func WithFlags(flags discord.MessageFlags) ReplyOption
- func WithLocalizedContent(locale string, key string, args ...any) ReplyOption
- func WithSticker(sticker discord.Sticker) ReplyOption
- func WithStickers(stickers ...discord.Sticker) ReplyOption
- type TypeLocaleGroups
- type TypeMessageGroup
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command struct {
// Base struct of Discord's slash command to build command on top of.
*discord.SlashCommandCreate
// contains filtered or unexported fields
}
Command struct represents a single command that are registered in command handler.
type CommandHandler ¶
type CommandHandler struct {
LocalizationManager LocalizationManager // Localization manager instance.
// contains filtered or unexported fields
}
CommandHandler is a general struct that are used to register commands, handle events and more.
func NewCommandHandler ¶
func NewCommandHandler(client bot.Client) *CommandHandler
NewCommandHandler creates a new instance of CommandHandler with the provided client. There should be only a one instance of the CommandHandler per runtime.
func (*CommandHandler) InitCommands ¶
func (ch *CommandHandler) InitCommands() error
InitCommands sends the request to create all registered commands and attaches a new event listener to the client that listens to the slash command executions. It can return an error if we were unable to register a slash command for some reason (e.g. rate-limiting).
func (*CommandHandler) RegisterCommand ¶
func (ch *CommandHandler) RegisterCommand(opts ...CommandOption)
RegisterCommand registers a new command with the provided options and adds it into the local mapping.
type CommandOption ¶
type CommandOption func(*Command)
CommandOption is a type that represents a single option for the command construction.
func WithDescription ¶
func WithDescription(description string) CommandOption
WithDescription sets the description of the current command to the provided string.
func WithDescriptionLocalization ¶ added in v0.3.1
func WithDescriptionLocalization(locale discord.Locale, description string) CommandOption
WithDescriptionLocalization adds a new localization for the description. Note that this function doesn't call LocalizationManager internally.
func WithHandler ¶
func WithHandler(handler HandlerFunc) CommandOption
WithHandler sets the handler for the current command.
func WithLocalizedDescription ¶ added in v0.3.1
func WithLocalizedDescription(locale discord.Locale, key string) CommandOption
WithLocalizedDescription localizes command description using the LocalizationManager.
func WithLocalizedName ¶ added in v0.3.1
func WithLocalizedName(locale discord.Locale, key string) CommandOption
WithLocalizedName localizes command name using the LocalizationManager.
func WithNSFW ¶
func WithNSFW(nsfw bool) CommandOption
WithNSFW sets whether command is NSFW or not. If it is, then it can be only used in NSFW channels.
func WithName ¶
func WithName(name string) CommandOption
WithName sets the name of the current command to the provided string.
func WithNameLocalization ¶ added in v0.3.1
func WithNameLocalization(locale discord.Locale, name string) CommandOption
WithNameLocalization adds a new localization for the name. Note that this function doesn't call LocalizationManager internally.
func WithOption ¶
func WithOption(option discord.ApplicationCommandOption) CommandOption
WithOption adds a new option to the current command's options.
func WithOptions ¶
func WithOptions(options []discord.ApplicationCommandOption) CommandOption
WithOptions sets current command's options to the provided slice.
func WithSubCommand ¶
func WithSubCommand(subCommand ...CommandOption) CommandOption
WithSubCommand turns the current command into the subcommand group and allows you to create a subcommands of the current command. You should add a single command per WithSubCommand call. See documentation for other functions that returns CommandOption for more information (e.g. WithName).
type Context ¶
type Context struct {
// LocalizationManager is an instance of the LocalizationManager.
LocalizationManager LocalizationManager
// Event is an event that Discord sent us for this specific command.
Event *events.ApplicationCommandInteractionCreate
}
Context is a struct that contains information about the event and allows to reply to the received event.
func (*Context) Reply ¶ added in v0.2.0
func (ctx *Context) Reply(opts ...ReplyOption) error
Reply creates reply to the context's event with the provided ReplyOption(s).
type HandlerFunc ¶
HandlerFunc is a type that represents handler's function type.
type Locale ¶ added in v0.3.0
type Locale struct {
// contains filtered or unexported fields
}
Locale is a type that contains all available messages for the specific locale.
func NewLocale ¶ added in v0.3.0
func NewLocale() *Locale
NewLocale creates a new instance of the Locale.
func (*Locale) GetMessage ¶ added in v0.3.0
GetMessage returns string by the provided path with formatted arguments if there are any. This method will return error != nil if you're trying to get message by unknown group or key.
func (*Locale) LoadMessages ¶ added in v0.3.0
LoadMessages loads messages from the provided path. It can return error != nil, if there was an error opening or reading file or while unmarshalling it from JSON string to an object.
type LocalizationManager ¶ added in v0.3.0
type LocalizationManager struct {
// contains filtered or unexported fields
}
LocalizationManager is a manager for the localization module.
func NewLocalizationManager ¶ added in v0.3.0
func NewLocalizationManager() LocalizationManager
NewLocalizationManager creates a new instance of the LocalizationManager.
func (*LocalizationManager) GetLocale ¶ added in v0.3.0
func (lm *LocalizationManager) GetLocale(locale string) (*Locale, error)
GetLocale returns the locale by its name. It will return an error != nil if there are no locale by the provided name.
func (*LocalizationManager) GetMessage ¶ added in v0.3.0
GetMessage gets message by the locale and key. See documentation for the GetLocale and GetMessage for more info.
func (*LocalizationManager) RegisterLocale ¶ added in v0.3.0
func (lm *LocalizationManager) RegisterLocale(localeName string, path string) error
RegisterLocale registers a new locale by its name and path to load the messages. This method will return error != nil if there was an error while loading messages.
type Reply ¶ added in v0.2.0
type Reply struct {
// contains filtered or unexported fields
}
Reply is a struct that contains information about the reply that client should send.
type ReplyOption ¶ added in v0.2.0
type ReplyOption func(*Reply)
ReplyOption is a type that represents a single option for the reply construction.
func WithContent ¶ added in v0.2.0
func WithContent(content string, vars ...any) ReplyOption
WithContent sets a new content with possible variables formatting for the reply.
func WithEmbed ¶ added in v0.2.0
func WithEmbed(embed discord.Embed) ReplyOption
WithEmbed adds a new embed to the reply.
func WithEmbeds ¶ added in v0.2.0
func WithEmbeds(embeds ...discord.Embed) ReplyOption
WithEmbeds appends a slice of embeds to the reply.
func WithEphemeral ¶ added in v0.2.0
func WithEphemeral(ephemeral bool) ReplyOption
WithEphemeral sets whether message should be ephemeral or not.
func WithFile ¶ added in v0.2.0
func WithFile(file *discord.File) ReplyOption
WithFile adds a new file to the reply.
func WithFiles ¶ added in v0.2.0
func WithFiles(files ...*discord.File) ReplyOption
WithFiles appends a slice of files to the reply.
func WithFlags ¶ added in v0.2.0
func WithFlags(flags discord.MessageFlags) ReplyOption
WithFlags sets flags for the reply.
func WithLocalizedContent ¶ added in v0.3.0
func WithLocalizedContent(locale string, key string, args ...any) ReplyOption
WithLocalizedContent sets the content for this reply according to the provided localization. See LocalizationManager.GetMessage method for more information.
func WithSticker ¶ added in v0.2.0
func WithSticker(sticker discord.Sticker) ReplyOption
WithSticker adds a new sticker to the reply.
func WithStickers ¶ added in v0.2.0
func WithStickers(stickers ...discord.Sticker) ReplyOption
WithStickers appends a slice of stickers to the reply.
type TypeLocaleGroups ¶ added in v0.3.0
type TypeLocaleGroups = map[string]TypeMessageGroup
TypeLocaleGroups represents all available locales with their messages.
type TypeMessageGroup ¶ added in v0.3.0
TypeMessageGroup represents a single group of messages.