commands

package
v0.0.0-...-e218727 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2018 License: ISC Imports: 5 Imported by: 0

Documentation

Overview

Package commands provides a basic commands manager for a bot to use

View the example bot under github.com/foxbot/awg/bot to see its intended use.

Index

Constants

View Source
const (
	// Prefix is the bot's prefix (TODO: dynamic)
	Prefix = "~>>"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	Aliases []string
	Func    Executor
}

Command is a command that may be invoked

type Commands

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

Commands is a structure to manage commands

func NewCommands

func NewCommands(prefixFunc PrefixFunc) *Commands

NewCommands returns a Commands manager

func (*Commands) Add

func (c *Commands) Add(command Command)

Add registers a command with the Commands manager

func (*Commands) Invoke

func (c *Commands) Invoke(ctx *Context) error

Invoke runs a command

type Context

type Context struct {
	Message  wumpus.Message
	Worker   *awg.Worker
	Name     string
	Argument string
}

Context contains the context for a command

type ErrorResult

type ErrorResult struct {
	Error error
}

ErrorResult is a result for a command that threw an error

func Error

func Error(e error) ErrorResult

Error creates an ErrorResult

func (ErrorResult) Act

func (r ErrorResult) Act(ctx *Context) error

Act logs the error and writes a message to the channel

type Executor

type Executor func(ctx *Context) Result

Executor defines the delegate for a command

type PrefixFunc

type PrefixFunc func(ctx *Context) (int, bool)

PrefixFunc defines the delegate to check a prefix

type Result

type Result interface {
	Act(ctx *Context) error
}

Result is a contract for a command result

type TextResult

type TextResult struct {
	Message string
}

TextResult is a result for a command that writes text

func Text

func Text(msg string) TextResult

Text creates a TextResult

func Textf

func Textf(format string, args ...interface{}) TextResult

func (TextResult) Act

func (r TextResult) Act(ctx *Context) error

Act writes a message to the channel

Jump to

Keyboard shortcuts

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