commandrouter

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2016 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChatBuffer

func ChatBuffer(input chan *model.ChatMessage, done chan struct{}) chan *model.ChatMessage

ChatBuffer provides an unbounded buffer for ChatMessage objects

func MatchBuffer

func MatchBuffer(input chan Match, done chan struct{}) chan Match

MatchBuffer provides an unbounded buffer for Match objects

Types

type Command

type Command struct {
	// Tag is the value sent to the destination when a command matches.
	Tag int
	// The command to match on. If the command is not a regexp (see below), the
	// command must be a single word and will only be matched if it occurs at
	// the beginning of the message.
	Command string
	// IsRegExp is true if Command should be compiled as a regex.
	IsRegexp bool
	// MatchAll is true if the command should match on all messages. If false,
	// the command will match only on messages directed to the bot user.
	MatchAll bool
}

Command defines a single command, how it should be detected, and what value should be used to notify the client.

type Match

type Match struct {
	// The tag supplied when the command was added.
	Tag     int
	Message *model.ChatMessage
	// RegexpMatch contains the matching subgroups, if any, when a Regexp
	// command matches.
	RegexpMatch []string
}

Match contains all the information needed for a client to process an incoming message.

type Router

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

Router is the command router itself.

func New

func New() *Router

New creates a new Router

func (*Router) AddDestination

func (r *Router) AddDestination(name string, commands []Command) (chan Match, error)

AddDestination adds a new destination and associated commands to the router.

func (*Router) Close

func (r *Router) Close()

Close shuts down the router and closes all it outgoing channels.

func (*Router) Route

func (r *Router) Route(msg *model.ChatMessage) (bool, error)

Route processes a ChatMessage and routes it to the correct destination, if any.

Jump to

Keyboard shortcuts

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