irc

package module
v0.0.0-...-73dd7ce Latest Latest
Warning

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

Go to latest
Published: May 11, 2014 License: MIT Imports: 9 Imported by: 1

README

irc

You shouldn't be using this, you should waste time rolling your own IRC stuff.

Documentation

Overview

Package irc provides a framework for writing IRC clients, specifically bots.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBadMsg = errors.New("Invalid IRC message.")
)

Functions

This section is empty.

Types

type Client

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

Client is an IRC connection which handles message dispatch to a MsgHandler.

func Dial

func Dial(address string) (*Client, error)

Dial connects to an IRC host.

func (*Client) Handle

func (client *Client) Handle(handler Handler)

Register registers a handler for dispatch.

func (*Client) Join

func (client *Client) Join(channel string)

func (*Client) Listen

func (client *Client) Listen()

Listen puts an irc connection into a loop, parsing and dispatching recieved messages to a handler, as well as sending outgoing messages.

func (*Client) Nick

func (client *Client) Nick(user string)

type Cmd

type Cmd interface {
	Respond(body, source string, w io.Writer)
}

The Cmd interface responds to incoming chat commands.

type CmdFunc

type CmdFunc func(body, source string, w io.Writer)

A CmdFunc responds to incoming chat commands.

func (CmdFunc) Respond

func (f CmdFunc) Respond(body, source string, w io.Writer)

type CmdHandler

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

A CmdHandler dispatches for a group of commands with a common prefix.

func NewCmdHandler

func NewCmdHandler(prefix string) *CmdHandler

NewCmdHandler creates a new CmdHandler with the given command prefix.

func (*CmdHandler) Accepts

func (c *CmdHandler) Accepts(msg *Msg) bool

Accepts for a CmdHandler ensures the msg contains a chat command.

func (*CmdHandler) Handle

func (c *CmdHandler) Handle(msg *Msg, send chan<- *Msg)

Handle for a CmdHandler extracts the relevant parts of a command msg and dispatches to a Cmd, if one is found with the given name.

func (*CmdHandler) Register

func (c *CmdHandler) Register(name string, cmd Cmd)

Register adds a Cmd to be executed when the given name is matched.

func (*CmdHandler) RegisterFunc

func (c *CmdHandler) RegisterFunc(name string, cmdFunc CmdFunc)

RegisterFunc adds a CmdFunc to be executed when the given name is matched.

func (*CmdHandler) RegisteredNames

func (c *CmdHandler) RegisteredNames() (names []string)

type Handler

type Handler interface {
	Accepts(msg *Msg) bool
	Handle(msg *Msg, send chan<- *Msg)
}

MsgHandler handles messages and optionally sends responses on chan send.

type Msg

type Msg struct {
	Raw    string
	Prefix string
	Cmd    string
	Params []string
}

Msg represents the essential components identifying a received for to-be-sent IRC message.

func ParseMsg

func ParseMsg(raw string) (*Msg, error)

ParseMsg accepts a raw IRC message string and parses it into a Msg struct.

func (*Msg) ExtractNick

func (msg *Msg) ExtractNick() (nick string, err error)

ExtractNick attempts to extract the sender nick from the message prefix.

func (*Msg) ExtractPrivmsg

func (msg *Msg) ExtractPrivmsg() (receiver string, body string, err error)

ExtractPrivmsg attempts to extract the relevant parts of a privmessage.

func (Msg) String

func (msg Msg) String() string

String converts the Msg struct to an IRC message string.

Jump to

Keyboard shortcuts

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