cmdrouter

package module
v0.0.0-...-666c165 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2021 License: MIT Imports: 1 Imported by: 4

README

CommandRouterGo

Coverage Status MIT License Go Reference

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetachCommandFrom

func DetachCommandFrom(str string) (command string, argument string)

DetachCommandFrom function detaches the command from the string and returns it and its arguments

func MakeCommandMapFrom

func MakeCommandMapFrom(commands []*Command) map[string]*Command

MakeCommandMapFrom function make the map from the command slice with the command alias as the key.

Types

type Command

type Command struct {
	Name        string
	Alias       string
	Summary     string
	Usage       string
	Example     string
	SubCommands map[string]*Command
	Handler     CommandHandler
}

Command holds data about the command

func NewCommand

func NewCommand(
	name string,
	alias string,
	summary string,
	usage string,
	example string,
	subCommands []*Command,
	handler CommandHandler,
) *Command

NewCommand is a constructor for Command

type CommandHandler

type CommandHandler interface {
	Handle(ctx *Context)
}

CommandHandler is an interface for command execution

type CommandHelpPresenter

type CommandHelpPresenter interface {
	Help(c *Command, props map[string]interface{})
}

CommandHelpPresenter is the interface for displaying help messages for commands

type Context

type Context struct {
	Argument string
	Props    map[string]interface{}
}

Context is the Context passed to the command handler

type RouteHandler

type RouteHandler struct {
	Command       *Command
	HelpPresenter CommandHelpPresenter
}

RouteHandler is a struct that implements CommandHandler

func (*RouteHandler) Handle

func (rh *RouteHandler) Handle(ctx *Context)

Handle of RouteHandler calls the subcommand handle according to Argument

type Router

type Router struct {
	Prefix   string
	Commands map[string]*Command
}

Router represents the router for discord commands

func NewRouter

func NewRouter(prefix string, commands []*Command) *Router

NewRouter is a constructor for Router

func (*Router) Route

func (r *Router) Route(ctx *Context)

Route is a router handler provided to discordgo session

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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