router

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2020 License: ISC Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ArgumentTypeBasic = iota
	ArgumentTypeInt
	ArgumentTypeFloat
	ArgumentTypeBool
	ArgumentTypeEmoji
	ArgumentTypeUserMention
	ArgumentTypeChannelMention
)

Variables

View Source
var (
	ErrEmptyText = errors.New("text is empty")
)
View Source
var (
	UsageError = errors.New("usage")
)

Functions

This section is empty.

Types

type Argument

type Argument struct {
	Index    int
	Name     string
	Required bool
	Type     int
}

Argument type contains defined arguments, parsed from the command signature

type Context

type Context struct {
	Session        *discordgo.Session
	Event          *discordgo.MessageCreate
	Guild          *discordgo.Guild
	Channel        *discordgo.Channel
	User           *discordgo.User
	Prefix         string
	Command        string
	ArgumentString string
	Arguments      []string
	ArgumentCount  int
	Vars           map[string]interface{}
	// contains filtered or unexported fields
}

func ContextFrom

func ContextFrom(session *discordgo.Session, event *discordgo.MessageCreate, r *Route, command string, args []string, argString string) (*Context, error)

Create a new Context from the session and event

func (*Context) Arg

func (c *Context) Arg(name string) string

Find and return a named argument

func (*Context) BoolArg

func (c *Context) BoolArg(name string) bool

Find and return a named bool argument

func (*Context) ChannelArg

func (c *Context) ChannelArg(name string) *discordgo.Channel

Find and return a named Channel argument

func (*Context) ChannelArgType

func (c *Context) ChannelArgType(name string, t discordgo.ChannelType) *discordgo.Channel

Find and return a named Channel argument with a specified type

func (*Context) FloatArg

func (c *Context) FloatArg(name string) float64

Find and return a named float argument

func (*Context) Get

func (c *Context) Get(key string) interface{}

Get retrieves a variable from the context

func (*Context) IntArg

func (c *Context) IntArg(name string) int64

Find and return a named int argument

func (*Context) Reply

func (c *Context) Reply(text string) (*discordgo.Message, error)

Reply with a user mention

func (*Context) ReplyEmbed

func (c *Context) ReplyEmbed(embed *discordgo.MessageEmbed) (*discordgo.Message, error)

Reply to a user with an embed object

func (*Context) ReplyFile

func (c *Context) ReplyFile(name string, r io.Reader) (*discordgo.Message, error)

Reply to a user with a file object

func (*Context) ReplyTo

func (c *Context) ReplyTo(to, text string) (*discordgo.Message, error)

Reply to a specific user

func (*Context) Replyf

func (c *Context) Replyf(format string, a ...interface{}) (*discordgo.Message, error)

Reply with formatted text

func (*Context) Send

func (c *Context) Send(text string) (*discordgo.Message, error)

Send text to the originating channel

func (*Context) SendFile

func (c *Context) SendFile(name string, r io.Reader) (*discordgo.Message, error)

Send a file by name and read from r

func (*Context) Sendf

func (c *Context) Sendf(format string, a ...interface{}) (*discordgo.Message, error)

Send formattable text to the originating channel

func (*Context) Set

func (c *Context) Set(key string, d interface{})

Set sets a variable on the context

func (*Context) Usage

func (c *Context) Usage(usage ...string) (*discordgo.Message, error)

Show context usage

func (*Context) UserArg

func (c *Context) UserArg(name string) *discordgo.User

Find and return a named User argument

type FindOpts added in v1.1.0

type FindOpts struct {
	Args      []string
	MatchCase bool
}

Options for FindComplex. Default is just Args in Find.

type Handler

type Handler func(*Context)

type MiddlewareFunc

type MiddlewareFunc func(Handler) Handler

A middleware handler

type Route

type Route struct {
	Routes map[string]*Route

	Name                  string
	Usage                 string
	Description           string
	Arguments             map[string]*Argument
	ArgumentCount         int
	RequiredArgumentCount int
	// contains filtered or unexported fields
}

Route type contains information about a route, such as middleware, routes, etc

func New

func New() *Route

Create a new, empty route.

func (*Route) Add

func (r *Route) Add(n *Route) *Route

Add a sub route to this route.

func (*Route) Alias

func (r *Route) Alias(alias string) *Route

Add an alias to the parent route for the current route.

func (*Route) Call

func (r *Route) Call(ctx *Context) error

Execute a route. Handlers are called synchronously. Sub-routes will be walked until the stack is empty or a match couldn't be found.

func (*Route) Desc

func (r *Route) Desc(description string) *Route

Set this route's description

func (*Route) Find

func (r *Route) Find(args ...string) *Route

Find a route by arguments

func (*Route) FindComplex added in v1.1.0

func (r *Route) FindComplex(opts FindOpts) *Route

Find route by options, including args, case sensitive matching, etc

func (*Route) Group

func (r *Route) Group(fn func(*Route)) *Route

Create a temporary route to use for registering sub routes. All routes will be copied into this route, with middleware applied.

func (*Route) On

func (r *Route) On(signature string, f Handler) *Route

Adds a handler for a specific command. Signature can be a simple command, or a string like the following:

command <arg1> <arg2> [arg3] [#channel] [@user]

The library will automatically parse and validate the required arguments. <> means an argument will be required, [] says it's optional As well as required and optional types, you can use # and @ to signify That routes must match a valid user or channel.

func (*Route) Use

func (r *Route) Use(f ...MiddlewareFunc) *Route

Apply middleware to this route. All sub-routes will also inherit this middleware.

func (*Route) Validate

func (r *Route) Validate(ctx *Context) error

Validate checks the context against the Route's defined arguments and ensures all required arguments and types are satisfied.

Jump to

Keyboard shortcuts

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