cmd

package
v0.0.0-...-9bc5058 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PromptAccept for acceptance of a prompt.
	PromptAccept = iota

	// PromptDeny for denial of a prompt.
	PromptDeny

	// PromptTimeout is when the prompt times out.
	PromptTimeout
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder ensures easy command creation.

func New

func New() *Builder

New creates a command builder instance.

func (*Builder) Aliases

func (bldr *Builder) Aliases(aliases ...string)

Aliases sets the aliases of the command.

func (*Builder) Arg

func (bldr *Builder) Arg(arg *arg.Argument)

Arg adds an argument for the command.

func (*Builder) Command

func (bldr *Builder) Command() *Command

Command returns the constructed command.

func (*Builder) Description

func (bldr *Builder) Description(desc string)

Description sets the description of the command

func (*Builder) Name

func (bldr *Builder) Name(name string)

Name sets the name of the command.

func (*Builder) Use

func (bldr *Builder) Use(middleware Middleware)

Use adds a middleware to the stack.

type Category

type Category struct {
	Commands []*Command
	// contains filtered or unexported fields
}

Category an incubator for commands of a specific type.

func NewCategory

func NewCategory(name, emoji string) *Category

NewCategory creates new command category.

func (*Category) AddCommand

func (cat *Category) AddCommand(cmd *Command)

AddCommand adds a command to the category.

func (*Category) DisplayName

func (cat *Category) DisplayName() string

DisplayName provides a string suitable for the help menu.

type Command

type Command struct {
	Name        string
	Aliases     []string
	Description string
	Permission  int

	Category *Category
	// contains filtered or unexported fields
}

Command is a command

func (*Command) Help

func (cmd *Command) Help() string

Help builds or returns the pre-build help string for the command.

type Context

type Context struct {
	Session *discordgo.Session
	Msg     *discordgo.Message
	Cmd     *Command

	// String used to call the command
	CallKey string
	RawArgs []string
	Args    map[string]interface{}

	StartTime time.Time
	// contains filtered or unexported fields
}

Context is the message context used for command execution

func (*Context) CleanUp

func (ctx *Context) CleanUp()

CleanUp deletes the last recently sent message.

func (*Context) Collect

func (ctx *Context) Collect(time time.Duration, amnt ...int) (chan *discordgo.Message, error)

Collect collects messages.

func (*Context) Delete

func (ctx *Context) Delete(msg ...*discordgo.Message) error

Delete deletes the last recently sent message or the supplied one.

func (*Context) Edit

func (ctx *Context) Edit(content string) (*discordgo.Message, error)

Edit edits the last msg sent by the context.

func (*Context) Prompt

func (ctx *Context) Prompt(prompt string) (int, error)

Prompt sends a prompt to accept or deny within 10 seconds.

func (*Context) Send

func (ctx *Context) Send(content string, deleteTime ...time.Duration) (*discordgo.Message, error)

Send sends a message to the channel the msg came from.

func (*Context) SendError

func (ctx *Context) SendError(err error)

SendError reports an error to the err channel and to the user

type Middleware

type Middleware func(ctx *Context, next NextFunc)

Middleware runs a chain of commands.

type NextFunc

type NextFunc func(err ...error)

NextFunc runs the next middleware in the chain. Optionally supply an error to cancel the chain and report an error.

func Dispatch

func Dispatch(session *discordgo.Session, msg *discordgo.Message) NextFunc

Dispatch dispatches a command.

type Registry

type Registry struct {
	Categories map[string]*Category
	// contains filtered or unexported fields
}

Registry holds all the commands and uses a radix trie for lookups.

func GetRegistry

func GetRegistry() *Registry

GetRegistry gets the command registry.

func (*Registry) AddCategory

func (reg *Registry) AddCategory(cat *Category)

AddCategory adds a command category and registers all of its commands.

func (*Registry) FindClosestCmdMatch

func (reg *Registry) FindClosestCmdMatch(nonExistentCmd string) (string, int)

FindClosestCmdMatch aids in supplying "did you mean" functionality for a command.

func (*Registry) LookupCommand

func (reg *Registry) LookupCommand(cmdNameOrAlias string) (*Command, error)

LookupCommand looks up a command using either its name or alias.

func (*Registry) Populate

func (reg *Registry) Populate()

Populate constructs the radix trie that looks up commands.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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