command

package
v0.0.0-...-ec10a6c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 23, 2024 License: GPL-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SuccessEmbedColor = 0x50fa7b
	ErrorEmbedColor   = 0xff5555
	PendingEmbedColor = 0x00add8
)
View Source
const (
	InteractionBaseIDLength = 10
)

Variables

View Source
var (
	ErrRequireParameter    = errors.New("required parameter missing")
	ErrCannotParseArgument = errors.New("cannot parse argument")
	ErrInvalidValue        = errors.New("invalid value")
)
View Source
var Prefix string

Functions

func GetCommandMap

func GetCommandMap() map[string]*Command

func HandleCommand

func HandleCommand(
	usedCommandName string,
	args []string,
	command *Command,
	bot discord.BotAdapter,
	trigger *TriggerEvent,
)

func HandleInteraction

func HandleInteraction(fullID, userID string) *model.ComplexMessage

func NewErrCannotParseParameter

func NewErrCannotParseParameter(lang *i18n.Language, err error) error

func NewErrInvalidValue

func NewErrInvalidValue(lang *i18n.Language, cmd *Command, param *Parameter) error

func NewErrRequiredParameter

func NewErrRequiredParameter(lang *i18n.Language, cmd *Command, param *Parameter) error

func RegisterCategory

func RegisterCategory(category Category)

func RegisterCommand

func RegisterCommand(command *Command)

func RemoveInteractionHandler

func RemoveInteractionHandler(baseID string)

func RunValidation

func RunValidation(ctx *Context, validation *Validation) (bool, string)

Types

type BaseType

type BaseType struct {
	Name string
}

type Category

type Category struct {
	Commands    []*Command
	Name, Emoji string
	OnLoad      func()
}

type Command

type Command struct {
	Validations []*Validation
	Parameters  []*Parameter
	Aliases     []string
	SubCommands []*Command
	Name        string
	Handler     Handler
	Permission  *Permission

	Deferred  bool
	Ephemeral bool
	// contains filtered or unexported fields
}

func GetCommand

func GetCommand(name string) *Command

func GetCommandList

func GetCommandList() []*Command

func (*Command) GetCategory

func (c *Command) GetCategory() *Category

func (*Command) ValidateParameters

func (command *Command) ValidateParameters(ctx *Context) (values []any, syntaxError error)

type Context

type Context struct {
	Lang *i18n.Language
	T    any

	RawArgs                      []string
	Args                         []any
	Bot                          discord.BotAdapter
	Channel                      model.TextChannel
	MessageID, AuthorID, GuildID string
	UsedName                     string
	Locals                       map[string]any
	Command                      *Command
	TriggerType                  TriggerType
	// contains filtered or unexported fields
}

func (*Context) EditComplexMessage

func (ctx *Context) EditComplexMessage(message *model.ComplexMessage) error

func (*Context) Embed

func (ctx *Context) Embed(embed *model.Embed) Result

func (*Context) Empty

func (ctx *Context) Empty() Result

func (*Context) Error

func (ctx *Context) Error(message string) Result

func (*Context) ErrorEmbed

func (ctx *Context) ErrorEmbed(embed *model.Embed) Result

func (*Context) Errorf

func (ctx *Context) Errorf(format string, args ...any) Result

func (*Context) RegisterInteractionHandler

func (ctx *Context) RegisterInteractionHandler(baseID string, handler InteractionHandler)

func (*Context) ReplyRaw

func (ctx *Context) ReplyRaw(content string) Result

func (*Context) ReplyWithInteraction

func (ctx *Context) ReplyWithInteraction(
	baseID string,
	message *model.ComplexMessage,
	handler InteractionHandler,
) Result

func (*Context) Success

func (ctx *Context) Success(message string) Result

func (*Context) SuccessEmbed

func (ctx *Context) SuccessEmbed(embed *model.Embed) Result

func (*Context) Successf

func (ctx *Context) Successf(format string, args ...any) Result

type Handler

type Handler func(*Context) Result

type InteractionHandler

type InteractionHandler func(id, userID, baseID string) (newMessage *model.ComplexMessage, done bool)

type Parameter

type Parameter struct {
	ValidValues     []any
	Name            string
	Type            *ParameterType
	ValidValuesFunc func() []any
	Required        bool
}

func (*Parameter) GetValidValues

func (param *Parameter) GetValidValues() []any

type ParameterType

type ParameterType struct {
	Name     string
	BaseType *BaseType
	Parser   ParameterTypeParser
}

type ParameterTypeParser

type ParameterTypeParser func(ctx *Context, index int, args []string) (any, error)

type Permission

type Permission struct {
	Name    string
	Checker PermissionChecker
}

type PermissionChecker

type PermissionChecker func(*Context) bool

type Result

type Result struct {
	Success bool
	Message *model.ComplexMessage
}

type TriggerEvent

type TriggerEvent struct {
	EventTime                    time.Time
	PreferedLanguage             i18n.LanguageName
	Type                         TriggerType
	Channel                      model.TextChannel
	MessageID, GuildID, AuthorID string
	DeferResponse                func() error
	Reply                        func(*Context, *model.ComplexMessage) error
	Edit                         func(*Context, *model.ComplexMessage) error
}

type TriggerType

type TriggerType string
const (
	CommandTriggerSlash   TriggerType = "SLASH"
	CommandTriggerMessage TriggerType = "MESSAGE"
)

type Validation

type Validation struct {
	Name      string
	DependsOn []*Validation
	Checker   ValidationChecker
}

type ValidationChecker

type ValidationChecker func(*Context) (bool, string)

Directories

Path Synopsis
categories
bot
fun

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL