bot

package
v0.0.0-...-eaa097e Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBotExists occurs when the manager already
	// has a bot with the same name.
	ErrBotExists = errors.New("manager: Bot with that name already exists")
	// ErrBotNotFound occurs when no bot is found with
	// the same name.
	ErrBotNotFound = errors.New("manager: Could not find a bot with that name")
	// ErrHandlerExists occurs when you try to add a handler
	// that already exists
	ErrHandlerExists = errors.New("manager: Handler already exists")
)
View Source
var (
	// Handlers holds list of all registered handlers
	Handlers map[string]map[string]Handler

	// HandlerList holds a list of all handler
	HandlerList map[string]Handler
)

Functions

func RegisterHandler

func RegisterHandler(handler Handler) error

RegisterHandler will register the given handler for use with bots

Types

type Bot

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

Bot is the structure for an IRC bot

func NewBot

func NewBot(config Config) (*Bot, error)

NewBot creates a new bot

func (*Bot) Close

func (b *Bot) Close()

Close will disconnect the bot from the server

func (*Bot) Config

func (b *Bot) Config() Config

Config returns the configuration

func (*Bot) Connect

func (b *Bot) Connect() error

Connect will connect the bot to the server

func (*Bot) Db

func (b *Bot) Db() *badger.DB

Db returns the active database for this bot

func (*Bot) ErrorHandler

func (b *Bot) ErrorHandler()

ErrorHandler will handle all errors

func (*Bot) Handler

func (b *Bot) Handler()

Handler will start processing messages

func (*Bot) InitHandlers

func (b *Bot) InitHandlers()

InitHandlers will run Init on all registered handlers

func (*Bot) Join

func (b *Bot) Join(channel string)

Join will join the given channel

func (*Bot) Nick

func (b *Bot) Nick(nick string)

Nick will send the nick command to the server and update the stored nick.

func (*Bot) Ping

func (b *Bot) Ping(message string)

Ping will send ping to the server

func (*Bot) Pinger

func (b *Bot) Pinger()

Pinger will ping the server every 2 minutes

func (*Bot) Pong

func (b *Bot) Pong(message string)

Pong will send pong to the server

func (*Bot) Reconnect

func (b *Bot) Reconnect()

Reconnect will reconnect the bot to the server

func (*Bot) Run

func (b *Bot) Run()

Run will start all handlers

func (*Bot) Send

func (b *Bot) Send(recv, msg string)

Send will send the given message to the given receiver

func (*Bot) User

func (b *Bot) User(user, name string)

User will send the user command to the server and update the stored name and user

type Config

type Config struct {
	BotName  string `mapstructure:"name"`
	Hostname string `mapstructure:"host"`
	Port     int
	Secure   struct {
		Enable bool
		Verify bool
	}
	Identification struct {
		Nick string
		User string
		Name string
	}
	Channels []string
	Timings  struct {
		Timeout int
	}
	Limits struct {
		Messages int `mapstructure:"rate"`
		Timeout  int `mapstructure:"retries"`
	}
	Plugins  []string
	Database string
	Settings map[interface{}]interface{}
}

Config is the configuration structure for Bot

type Handler

type Handler struct {
	Name        string
	Description string
	Run         HandlerFunc
	Event       string
	Init        InitFunc
}

Handler is an OnEvent handler

type HandlerFunc

type HandlerFunc func(*Bot, *msg.Message) (bool, error)

HandlerFunc is function signature for OnEvent handlers.

type InitFunc

type InitFunc func(*Bot) (bool, error)

InitFunc is run once on bot startup to initialize and setup the plugin.

type Manager

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

Manager is a bot manager for multiple bots

func NewManager

func NewManager() *Manager

NewManager creates and returns a new manager

func (*Manager) Add

func (m *Manager) Add(name string, bot *Bot) error

Add adds a bot to the manager and starts it if the manager is currently running.

func (*Manager) Remove

func (m *Manager) Remove(name string) error

Remove removes the bot from the manager. It will also stop the bot if its currently running.

func (*Manager) Run

func (m *Manager) Run() error

Run will start all bots and start to handle all messages

func (*Manager) Start

func (m *Manager) Start() error

Start will start the manager and all added bots. It will only return successfully if *ALL* bots start. If one bot fails it will stop all other bots.

func (*Manager) Stop

func (m *Manager) Stop()

Stop will stop all running bots

type MessageHandler

type MessageHandler func(*Bot, string)

MessageHandler is the function type for message handlers

Jump to

Keyboard shortcuts

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