router

package
v0.0.0-...-efb1bcf Latest Latest
Warning

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

Go to latest
Published: May 3, 2022 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const Sep = ' '

Sep is the separator for the arguments

Variables

View Source
var (
	ErrAlreadyExist = errors.New("Router already exist")
	ErrNotFound     = errors.New("Router not found")
)

Error variables

Functions

This section is empty.

Types

type Args

type Args []string

Args is the list of router arguments

func ParseArgs

func ParseArgs(str string) Args

ParseArgs will extract arguments from a string

type Context

type Context struct {
	Route  *Route
	Routes []*Route
	Evt    interface{}
	Ses    *discordgo.Session

	Args Args
}

Context is the object for the router context

func NewContext

func NewContext(route *Route, routes []*Route, evt interface{}, ses *discordgo.Session, args Args) *Context

NewContext create and return new router context object

func (*Context) ChannelID

func (c *Context) ChannelID() string

ChannelID get the ChannelID

func (*Context) GuildID

func (c *Context) GuildID() string

GuildID get the GuildID

func (*Context) Reply

func (c *Context) Reply(msg string) error

Reply is the function for replying a message

func (*Context) SendEmbed

func (c *Context) SendEmbed(chid string, msg *discordgo.MessageEmbed) error

SendEmbed send an embeded message

type HandlerFunc

type HandlerFunc func(*Context)

HandlerFunc is the handler function for thenrouter

type MiddlewareFunc

type MiddlewareFunc func(HandlerFunc) HandlerFunc

MiddlewareFunc is the middleware function for the router

type Route

type Route struct {
	Name        string
	Description string
	Category    string

	// Routes is list of registered routers
	Routes []*Route

	Handler HandlerFunc

	// Middleware is the list of registered middlewares
	Middleware []MiddlewareFunc

	// Usage is the help details
	Usage string
}

Route is the router object

func NewRouter

func NewRouter() *Route

NewRouter create and return new Route object

func (*Route) AddRoute

func (r *Route) AddRoute(route *Route) error

AddRoute add route to the routers

func (*Route) Cat

func (r *Route) Cat(cat string) *Route

Cat is the setter function for router category

func (*Route) Desc

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

Desc is the setter function for router description

func (*Route) Find

func (r *Route) Find(name string) *Route

Find will find a matching router

func (*Route) FindAll

func (r *Route) FindAll(args ...string) (*Route, int)

FindAll will find a matching router from slices of strings

func (*Route) HandleFunc

func (r *Route) HandleFunc(name string, handler HandlerFunc) *Route

HandleFunc register the new handler for the given route

func (*Route) Listen

func (r *Route) Listen(ses *discordgo.Session, evt interface{}, prefix string) error

Listen will listen to all event and find a matchhandler

func (*Route) Use

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

Use register the middleware to the router

func (*Route) Usg

func (r *Route) Usg(usg string) *Route

Usg is the setter function for router usage

Jump to

Keyboard shortcuts

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