commands

package
v0.0.0-...-80caa2b Latest Latest
Warning

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

Go to latest
Published: May 2, 2022 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownCommand   = errors.New("unknown command")
	ErrPermissionDenied = errors.New("permission denied")
)
View Source
var Default = NewRegistry()

Functions

func HandleCommand

func HandleCommand(cmd *Command) (string, error)

func HandleCommandLine

func HandleCommandLine(line string, actor Actor) (string, error)

func Register

func Register(name Name, description string, permission Permission, handler Handler)

func RegisterDefinition

func RegisterDefinition(def Definition)

Types

type Actor

type Actor interface {
	HasPermission(Permission) bool
}

type Command

type Command struct {
	Name
	Arguments []string
	Actor
}

func NewCommand

func NewCommand(line string, actor Actor) *Command

func (*Command) Fields

func (c *Command) Fields() log.Fields

func (*Command) String

func (c *Command) String() string

type Definition

type Definition struct {
	Name
	Description string
	Permission
	Handler
}

type Handler

type Handler interface {
	HandleCommand(*Command) (string, error)
}

type HandlerFunc

type HandlerFunc func(*Command) (string, error)

func (HandlerFunc) HandleCommand

func (f HandlerFunc) HandleCommand(cmd *Command) (string, error)

type Name

type Name string
const (
	HelpCommand  Name = "help"
	PermsCommand Name = "perms"
)

type Permission

type Permission interface{}
var AllowAll Permission = all("allow")

type Registry

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

func NewRegistry

func NewRegistry() *Registry

func (*Registry) HandleCommand

func (r *Registry) HandleCommand(cmd *Command) (string, error)

func (*Registry) Register

func (r *Registry) Register(name Name, description string, permission Permission, handler Handler)

func (*Registry) RegisterDefinition

func (r *Registry) RegisterDefinition(def Definition)

Jump to

Keyboard shortcuts

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