bot

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2023 License: Apache-2.0 Imports: 9 Imported by: 31

Documentation

Overview

Package bot implements an IRC bot with plugins.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Channels

func Channels(channels []string) func(*botImpl)

Channels is an option to configure the channels for the bot to join.

func CommandPrefix added in v1.0.2

func CommandPrefix(commandPrefix string) func(impl *botImpl)

CommandPrefix is an option to configure the prefix of commands (default is !).

func Host

func Host(host string) func(*botImpl)

Host is an option to configure the IRC server host.

func Ident

func Ident(ident string) func(*botImpl)

Ident is an option to configure the bot ident.

func Nick

func Nick(nick string) func(*botImpl)

Nick is an option to configure the bot nick.

func Password

func Password(password string) func(*botImpl)

Password is an option to configure the IRC server password.

func Proxy

func Proxy(proxy string) func(*botImpl)

Proxy is an option to configure a proxy to connect to the IRC server.

func RealName

func RealName(realName string) func(*botImpl)

RealName is an option to configure the bot real name.

func SSL

func SSL(ssl bool) func(*botImpl)

SSL is an option to configure SSL (TLS) on the connection.

Types

type Bot

type Bot interface {
	Run()                                                     // Run bot, reconnect if disconnect.
	Quit(msg string)                                          // Quit bot from IRC with a msg.
	Commands() *Commands                                      // For plugins to Add/Del commands.
	Action(t, msg string)                                     // Shortcut to Conn().Action()
	Connected() bool                                          // Shortcut to Conn().Connected()
	HandleFunc(n string, h client.HandlerFunc) client.Remover // Shortcut to Conn().HandleFunc()
	Invite(nick, channel string)                              // Shortcut to Conn().Nick()
	Join(c string)                                            // Shortcut to Conn().Join()
	Me() *state.Nick                                          // Shortcut to Conn().Me()
	Mode(t string, m ...string)                               // Shortcut to Conn().Mode()
	Nick(nick string)                                         // Shortcut to Conn().Nick()
	Notice(t, msg string)                                     // Shortcut to Conn().Notice()
	Part(c string, m ...string)                               // Shortcut to Conn().Part()
	Privmsg(t, msg string)                                    // Shortcut to Conn().Privmsg()
	Conn() *client.Conn                                       // Conn returns the underlying goirc client connection.
	Channels() []string                                       // Channels returns list of channels which bot has joined.
	CommandPrefix() string                                    // Return's the bot's prefix used to specify commands
}

Bot represents an IRC bot, with IRC client object, settings, commands.

func NewBot deprecated

func NewBot(host string, ssl bool, nick, ident string, channels []string) Bot

NewBot creates a new Bot implementation with a set of parameters.

Deprecated: use NewBotOptions instead.

func NewBotOptions

func NewBotOptions(options ...Option) (Bot, error)

NewBotOptions creates a new Bot implementation with options.

func NewBotWithProxy deprecated

func NewBotWithProxy(host string, ssl bool, nick, ident string, channels []string, proxy string) Bot

NewBotWithProxy creates a new Bot implementation with a set of parameters including a proxy.

Deprecated: use NewBotOptions instead.

type Command

type Command struct {
	Help          string  // Help string for help command.
	Handler       Handler // Handler to call.
	Pub           bool    // Command can be accessed publicly on a channel.
	NoExclamation bool    // Disallow calling command as "!command".
	Priv          bool    // Command can be accessed privately in query.
	Hidden        bool    // Hide command from list of all available commands.
}

Command represents a command that plugins can add.

func (*Command) String

func (c *Command) String() string

String formats a command with its attributes for display in help.

type Commands

type Commands struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Commands holds commands by their name.

func NewCommands

func NewCommands() *Commands

NewCommands initializes a new Commands.

func (*Commands) Add

func (s *Commands) Add(name string, c Command) error

Add allows plugins to add commands with help.

func (*Commands) Del

func (s *Commands) Del(name string)

Del allows plugins to remove commands added with Add (no error if not present).

func (*Commands) Handle

func (s *Commands) Handle(b Bot, line *client.Line)

Handle parses a line, matches with commands and dispatches to handler. A command can be triggered

  • in public on a channel with: /msg #chan !cmd [args] or directly at a bot: /msg #chan bot: cmd [args] works also with a comma: /msg #chan bot, cmd [args]
  • in private in a query: /msg bot cmd [args]

func (*Commands) Help

func (s *Commands) Help(e *Event)

Help displays all commands available or help on a single command.

type Event

type Event struct {
	Bot    Bot
	Target string // Channel if public, nick if private.
	Args   string // Command args (excluding command name).
	Line   *client.Line
}

Event is given to a command's Handler when a command matched by name.

type Handler

type Handler func(e *Event)

Handler is a callback used by plugins to receive command events.

type Option added in v1.0.4

type Option func(*botImpl)

Option represents a configurable option.

Jump to

Keyboard shortcuts

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