Version: v0.2.1 Latest Latest

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

Go to latest
Published: Oct 7, 2014 License: Apache-2.0 Imports: 10 Imported by: 0




View Source
const (
	INIT         = "init"
	CONNECTED    = "connected"
	DISCONNECTED = "disconnected"

Consts for unnamed events.


This section is empty.


func NewHandler

func NewHandler(f Handler) event.Handler

Wrap f in an anonymous unboxing function


type Conn

type Conn struct {
	// Connection Hostname and Nickname
	Host    string
	Me      *state.Nick
	Network string

	// Replaceable function to customise the 433 handler's new nick
	NewNick func(string) string

	// Event handler registry and dispatcher
	ER event.EventRegistry
	ED event.EventDispatcher

	// State tracker for nicks and channels
	ST state.StateTracker

	// Use the State field to store external state that handlers might need.
	// Remember ... you might need locking for this ;-)
	State interface{}

	Connected bool

	// Misc knobs to tweak client behaviour:
	// Are we connecting via SSL? Do we care about certificate validity?
	SSL       bool
	SSLConfig *tls.Config

	// Client->server ping frequency, in seconds. Defaults to 3m.
	PingFreq time.Duration

	// Set this to true to disable flood protection and false to re-enable
	Flood bool
	// contains filtered or unexported fields

An IRC connection is represented by this struct.

func Client

func Client(nick, ident, name string, r event.EventRegistry) *Conn

func SimpleClient

func SimpleClient(nick string, args ...string) *Conn

Creates a new IRC connection object, but doesn't connect to anything so that you can add event handlers to it. See AddHandler() for details.

func (*Conn) Action

func (conn *Conn) Action(t, msg string)

Action() sends a CTCP "ACTION" to the target t

func (*Conn) AddHandler

func (conn *Conn) AddHandler(name string, f Handler) event.Handler

AddHandler() adds an event handler for a specific IRC command.

Handlers are triggered on incoming Lines from the server, with the handler "name" being equivalent to Line.Cmd. Read the RFCs for details on what replies could come from the server. They'll generally be things like "PRIVMSG", "JOIN", etc. but all the numeric replies are left as ascii strings of digits like "332" (mainly because I really didn't feel like putting massive constant tables in).

func (*Conn) Away

func (conn *Conn) Away(message ...string)

Away() sends an AWAY command to the server

Away() resets away status
Away(message) sets away with the given message

func (*Conn) Connect

func (conn *Conn) Connect(host string, pass ...string) error

Connect the IRC connection object to "host[:port]" which should be either a hostname or an IP address, with an optional port. To enable explicit SSL on the connection to the IRC server, set Conn.SSL to true before calling Connect(). The port will default to 6697 if ssl is enabled, and 6667 otherwise. You can also provide an optional connect password.

func (*Conn) Ctcp

func (conn *Conn) Ctcp(t, ctcp string, arg ...string)

Ctcp() sends a (generic) CTCP message to the target t with an optional argument

func (*Conn) CtcpReply

func (conn *Conn) CtcpReply(t, ctcp string, arg ...string)

CtcpReply() sends a generic CTCP reply to the target t with an optional argument

func (*Conn) DisableStateTracking

func (conn *Conn) DisableStateTracking()

func (*Conn) EnableStateTracking

func (conn *Conn) EnableStateTracking()

func (*Conn) Invite

func (conn *Conn) Invite(nick, channel string)

Invite() sends an INVITE command to the server

func (*Conn) Join

func (conn *Conn) Join(channel string)

Join() sends a JOIN command to the server

func (*Conn) Kick

func (conn *Conn) Kick(channel, nick string, message ...string)

Kick() sends a KICK command to remove a nick from a channel

func (*Conn) Mode

func (conn *Conn) Mode(t string, modestring ...string)

Mode() sends a MODE command to the server. This one can get complicated if we try to be too clever, so it's deliberately simple:

Mode(t) retrieves the user or channel modes for target t
Mode(t, "modestring") sets user or channel modes for target t, where...
  modestring == e.g. "+o <nick>" or "+ntk <key>" or "-is"

This means you'll need to do your own mode work. It may be linked in with the state tracking and ChanMode/NickMode/ChanPrivs objects later...

func (*Conn) Nick

func (conn *Conn) Nick(nick string)

Nick() sends a NICK command to the server

func (*Conn) Notice

func (conn *Conn) Notice(t, msg string)

Notice() sends a NOTICE to the target t

func (*Conn) Oper

func (conn *Conn) Oper(user, pass string)

Oper() sends an OPER command to the server

func (*Conn) Part

func (conn *Conn) Part(channel string, message ...string)

Part() sends a PART command to the server with an optional part message

func (*Conn) Pass

func (conn *Conn) Pass(password string)

Pass() sends a PASS command to the server

func (*Conn) Privmsg

func (conn *Conn) Privmsg(t, msg string)

Privmsg() sends a PRIVMSG to the target t

func (*Conn) Quit

func (conn *Conn) Quit(message ...string)

Quit() sends a QUIT command to the server with an optional quit message

func (*Conn) Raw

func (conn *Conn) Raw(rawline string)

Raw() sends a raw line to the server, should really only be used for debugging purposes but may well come in handy.

func (*Conn) String

func (conn *Conn) String() string

Dumps a load of information about the current state of the connection to a string for debugging state tracking and other such things.

func (*Conn) Topic

func (conn *Conn) Topic(channel string, topic ...string)

Topic() sends a TOPIC command to the channel

Topic(channel) retrieves the current channel topic (see "332" handler)
Topic(channel, topic) sets the topic for the channel

func (*Conn) User

func (conn *Conn) User(ident, name string)

User() sends a USER command to the server

func (*Conn) Version

func (conn *Conn) Version(t string)

Version() sends a CTCP "VERSION" to the target t

func (*Conn) Who

func (conn *Conn) Who(nick string)

Who() sends a WHO command to the server

func (*Conn) Whois

func (conn *Conn) Whois(nick string)

Whois() sends a WHOIS command to the server

type Handler

type Handler func(*Conn, *Line)

An IRC handler looks like this:

type Line

type Line struct {
	Nick, Ident, Host, Src string
	Cmd, Raw               string
	Args                   []string
	Time                   time.Time

We parse an incoming line into this struct. Line.Cmd is used as the trigger name for incoming event handlers, see *Conn.recv() for details.

Raw =~ ":nick!user@host cmd args[] :text"
Src == "nick!user@host"
Cmd == e.g. PRIVMSG, 332

func (*Line) Copy

func (l *Line) Copy() *Line

NOTE: this doesn't copy l.Time (this should be read-only anyway)

Jump to

Keyboard shortcuts

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