ircx

package module
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2019 License: Apache-2.0 Imports: 8 Imported by: 3

README

ircx

Build Status

ircx is a very basic IRC bot written on top of the wonderfully small sorcix/irc library. It's designed to be a small building block, a small example of one way to use the library.

Using it is very simple, see the example.

This example doesn't do anything other than connect to specified channels and idle, but it's trivial to add additional handlers for any IRC event you want.

Context can be passed around by creating custom Handlers and Senders and using them, versus the default sender created, and an empty handler struct.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot

type Bot struct {
	Server       string
	OriginalName string
	Config       Config
	Data         chan *irc.Message
	Sender       Sender
	// contains filtered or unexported fields
}

Bot contains all of the information necessary to run a single IRC client

func Classic

func Classic(server string, name string) *Bot

Classic creates an instance of ircx poised to connect to the given server with the given IRC name.

func New

func New(server, name string, config Config) *Bot

New creates a new IRC bot with the specified server, name and config

func WithLogin

func WithLogin(server string, name string, user string, password string) *Bot

WithLogin creates an instance with the specified server, name user and password for the IRC server

func WithLoginTLS

func WithLoginTLS(server string, name string, user string, password string, tlsConfig *tls.Config) *Bot

WithLoginTLS creates an instance with the specified information + TLS config

func WithTLS

func WithTLS(server string, name string, tlsConfig *tls.Config) *Bot

WithTLS creates an instance of ircx poised to connect to the given server using TLS with the given IRC name.

func (*Bot) Connect

func (b *Bot) Connect() error

Connect attempts to connect to the given IRC server

func (*Bot) Handle

func (b *Bot) Handle(cmd string, handler Handler)

Handle registers the handler for the given command

func (*Bot) HandleFunc

func (b *Bot) HandleFunc(cmd string, handler func(s Sender, m *irc.Message))

HandleFunc registers the handler function for the given command

func (*Bot) HandleLoop

func (b *Bot) HandleLoop()

HandleLoop reads from the ReadLoop channel and initiates a handler check for every message it recieves.

func (*Bot) Logger

func (b *Bot) Logger() log.Logger

func (*Bot) ReadLoop

func (b *Bot) ReadLoop() error

ReadLoop sets a timeout of 300 seconds, and then attempts to read from the IRC server. If there is an error, it calls Reconnect

func (*Bot) Reconnect

func (b *Bot) Reconnect() error

Reconnect checks to make sure we want to, and then attempts to reconnect to the server

func (*Bot) SetLogger

func (b *Bot) SetLogger(l log.Logger)

type Config

type Config struct {
	Password   string
	User       string
	TLSConfig  *tls.Config
	MaxRetries int
}

Config contains optional configuration options for an IRC Bot

type Handler

type Handler interface {
	Handle(Sender, *irc.Message)
}

Handler is an interface to handle IRC messages

type HandlerFunc

type HandlerFunc func(s Sender, m *irc.Message)

HandlerFunc is a type that represents the method necessary to implement Handler

func (HandlerFunc) Handle

func (f HandlerFunc) Handle(s Sender, m *irc.Message)

Handle calls the HandlerFunc with the sender and irc message

type Sender

type Sender interface {
	// Send sends the given message and returns any errors.
	Send(*irc.Message) error
}

Sender is an interface for sending IRC messages

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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