chatcommand

package
v0.0.0-...-df918ef Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2022 License: ISC Imports: 10 Imported by: 1

Documentation

Overview

Package chatcommand implements event.Handler for PRIVMSG based IRC commands. It integrates with permissions.Handler

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCmdExists      = errors.New("command exists")
	ErrCmdNoExist     = errors.New("command does not exist")
	ErrInvalidCmdName = errors.New("invalid command name")
	ErrNoHelp         = errors.New("cannot add a command with no help message")
)

AddCommand errors

Functions

This section is empty.

Types

type Argument

type Argument struct {
	CommandName string
	Arguments   []string

	Event  *event.Message
	Target string
	Reply  func(string)
}

Argument represents an argument to a command

func (*Argument) ArgString

func (a *Argument) ArgString() string

ArgString returns the arguments as a space joined string

func (*Argument) CurrentNick

func (a *Argument) CurrentNick() string

CurrentNick is a shortcut to event.CurrentNick. It will be inlined

func (*Argument) Replyf

func (a *Argument) Replyf(format string, args ...interface{})

Replyf is a thin wrapper around reply that allows for easy printf formatting of replies

func (*Argument) SourceUser

func (a *Argument) SourceUser() *user.EphemeralUser

SourceUser is a shortcut to event.SourceUser. It will be inlined

type Callback

type Callback func(*Argument) error

Callback type used by chatcommand.Handler

type CommandPanicedError

type CommandPanicedError struct {
	CommandName string

	PanicData interface{}
	// contains filtered or unexported fields
}

CommandPanicedError is returned from OnMessage if a command panics

func (*CommandPanicedError) Error

func (e *CommandPanicedError) Error() string

type Handler

type Handler struct {
	Prefix string

	// Function used to send messages. It is expected that this can handle overlong lines cleanly.
	MessageFunc func(string, string) error
	// A permission system to use. If nil, no permission checks take place
	PermissionHandler permissions.Handler
	// contains filtered or unexported fields
}

Handler implements a chat message command system. You must provide a prefix and MessageFunc for replies

func (*Handler) AddCommand

func (h *Handler) AddCommand(
	name, help string, requiredPermissions []string, requiredArgs int, callback Callback,
) error

AddCommand adds a new command to the Handler

func (*Handler) DoHelp

func (h *Handler) DoHelp(commandName string) string

DoHelp generates the help message for a given command, or a general help message if the command is ""

func (*Handler) OnMessage

func (h *Handler) OnMessage(msg *event.Message) error

OnMessage implements event.MessageHandler

func (*Handler) RemoveCommand

func (h *Handler) RemoveCommand(name string) error

Jump to

Keyboard shortcuts

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