cmdhandler

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CmdHandler

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

CmdHandler is an irc command parser and execution format which you could use as an example for building your own version/bot.

An example of how you would register this with girc:

ch, err := cmdhandler.New("!")
if err != nil {
	panic(err)
}

ch.Add(&cmdhandler.Command{
	Name:    "ping",
	Help:    "Sends a pong reply back to the original user.",
	Fn: func(c *girc.Client, input *cmdhandler.Input) {
		c.Commands.ReplyTo(*input.Origin, "pong!")
	},
})

client.Handlers.AddHandler(girc.PRIVMSG, ch)

func New

func New(prefix string) (*CmdHandler, error)

New returns a new CmdHandler based on the specified command prefix. A good prefix is a single character, and easy to remember/use. E.g. "!", or ".".

func (*CmdHandler) Add

func (ch *CmdHandler) Add(cmd *Command) error

Add registers a new command to the handler. Note that you cannot remove commands once added, unless you add another CmdHandler to the client.

func (*CmdHandler) Execute

func (ch *CmdHandler) Execute(client *girc.Client, event girc.Event)

Execute satisfies the girc.Handler interface.

type Command

type Command struct {
	// Name of command, e.g. "search" or "ping".
	Name string
	// Aliases for the above command, e.g. "s" for search, or "p" for "ping".
	Aliases []string
	// Help documentation. Should be in the format "<arg> <arg> [arg] --
	// something useful here"
	Help string
	// MinArgs is the minimum required arguments for the command. Defaults to
	// 0, which means multiple, or no arguments can be supplied. If set
	// above 0, this means that the command handler will throw an error asking
	// the person to check "<prefix>help <command>" for more info.
	MinArgs int
	// Fn is the function which is executed when the command is ran from a
	// private message, or channel.
	Fn func(*girc.Client, *Input)
}

Command is an IRC command, supporting aliases, help documentation and easy wrapping for message inputs.

type Input

type Input struct {
	Origin  *girc.Event
	Args    []string
	RawArgs string
}

Input is a wrapper for events, based around private messages.

Jump to

Keyboard shortcuts

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