ezbot

package
v0.0.0-...-bfe6551 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2017 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CONNECTED = iota
	CONNECTING
	DISCONNECTED
)

Bot status

Variables

View Source
var ErrAlreadyConnected = errors.New("Bot already connected")

Error if an connection is already open

Functions

This section is empty.

Types

type Bot

type Bot struct {
	Log chan string
	// contains filtered or unexported fields
}

Bot contains Log channel for getting propagated logs

func New

func New() *Bot

New creates instance of Bot with initial state

func (*Bot) AddCmd

func (b *Bot) AddCmd(commands ...ICommand)

Adds commands to be executed

func (*Bot) Connect

func (b *Bot) Connect(config Config) error

Connect to server, init commands, start send and read loops.

func (*Bot) Disconnect

func (b *Bot) Disconnect()

Disconnect bot

func (*Bot) Join

func (b *Bot) Join(message *irc.Message)

Channel joins

func (*Bot) JoinCmds

func (b *Bot) JoinCmds(taken bool)

JoinCmds sends commands to set nick and it retries if nick is taken

func (*Bot) Leave

func (b *Bot) Leave(message *irc.Message)

Channel leaves

func (*Bot) Msg

func (b *Bot) Msg(message *irc.Message)

Channel messages

func (*Bot) OnConnect

func (b *Bot) OnConnect(onconnect func())

OnConnect sets callback to fire connecting

func (*Bot) Pong

func (b *Bot) Pong(message *irc.Message)

PONG reply

func (*Bot) Send

func (b *Bot) Send(msg string)

Send text message

type Command

type Command struct {
	Pattern string
	Reg     *regexp.Regexp
	SChan   chan string
	Log     chan string
}

func (*Command) Execute

func (c *Command) Execute(user string, msg string, args []string)

Executes when it matches with the regex.

func (*Command) Init

func (c *Command) Init(schan chan string, log chan string)

Sets channel with one passed by Bot Compiles regex for performance

func (*Command) Match

func (c *Command) Match(msg string) bool

Getting around interface restriction

func (*Command) OnJoin

func (c *Command) OnJoin(user string)

Executes when a user joins channel

func (*Command) OnLeave

func (c *Command) OnLeave(user string)

Executes when a user leaves channel

func (*Command) OnMsg

func (c *Command) OnMsg(user string, msg string)

Executes when user sends a message

func (*Command) Once

func (c *Command) Once()

Only executes once

type Config

type Config struct {
	Nick    string
	Addr    string
	Channel string
}

Config contains Bot configuration

type ICommand

type ICommand interface {
	Init(schan chan string, log chan string)
	Match(msg string) bool
	Once()
	Execute(user string, msg string, args []string)
	OnJoin(user string)
	OnLeave(user string)
	OnMsg(user string, msg string)
}

Jump to

Keyboard shortcuts

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