client

package
v0.0.0-...-4396b45 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2015 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	REGISTER     = "REGISTER"
	CONNECTED    = "CONNECTED"
	DISCONNECTED = "DISCONNECTED"
	ACTION       = "ACTION"
	AWAY         = "AWAY"
	CTCP         = "CTCP"
	CTCPREPLY    = "CTCPREPLY"
	INVITE       = "INVITE"
	JOIN         = "JOIN"
	KICK         = "KICK"
	MODE         = "MODE"
	NICK         = "NICK"
	NOTICE       = "NOTICE"
	OPER         = "OPER"
	PART         = "PART"
	PASS         = "PASS"
	PING         = "PING"
	PONG         = "PONG"
	PRIVMSG      = "PRIVMSG"
	QUIT         = "QUIT"
	TOPIC        = "TOPIC"
	USER         = "USER"
	VERSION      = "VERSION"
	VHOST        = "VHOST"
	WHO          = "WHO"
	WHOIS        = "WHOIS"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Set this to provide the Nick, Ident and Name for the client to use.
	Me *state.Nick

	// Hostname to connect to and optional connect password.
	Server, Pass string

	// Are we connecting via SSL? Do we care about certificate validity?
	SSL       bool
	SSLConfig *tls.Config

	// Local address to connect to the server.
	LocalAddr string

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

	// 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

	// Sent as the reply to a CTCP VERSION message
	Version string

	// Sent as the QUIT message.
	QuitMessage string

	// Configurable panic recovery for all handlers.
	Recover func(*Conn, *Line)

	// Split PRIVMSGs, NOTICEs and CTCPs longer than
	// SplitLen characters over multiple lines.
	SplitLen int

	// Timeout, The amount of time in seconds until a timeout is triggered.
	Timeout time.Duration
}

Misc knobs to tweak client behaviour go in here

func NewConfig

func NewConfig(nick string, args ...string) *Config

type Conn

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

An IRC connection is represented by this struct.

func Client

func Client(cfg *Config) *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) 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) Config

func (conn *Conn) Config() *Config

func (*Conn) Connect

func (conn *Conn) Connect() error

func (*Conn) ConnectTo

func (conn *Conn) ConnectTo(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) Connected

func (conn *Conn) Connected() bool

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) Handle

func (conn *Conn) Handle(name string, h Handler) Remover

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) HandleBG

func (conn *Conn) HandleBG(name string, h Handler) Remover

func (*Conn) HandleFunc

func (conn *Conn) HandleFunc(name string, hf HandlerFunc) Remover

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, key ...string)

Join() sends a JOIN command to the server with an optional key

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) LogPanic

func (conn *Conn) LogPanic(line *Line)

func (*Conn) Me

func (conn *Conn) Me() *state.Nick

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) Ping

func (conn *Conn) Ping(message string)

Ping() sends a PING command to the server A PONG response is to be expected afterwards

func (*Conn) Pong

func (conn *Conn) Pong(message string)

Pong() sends a PONG 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) StateTracker

func (conn *Conn) StateTracker() state.Tracker

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) VHost

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

VHost() sends a VHOST 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 interface {
	Handle(*Conn, *Line)
}

An IRC Handler looks like this:

type HandlerFunc

type HandlerFunc func(*Conn, *Line)

A HandlerFunc implements Handler.

func (HandlerFunc) Handle

func (hf HandlerFunc) Handle(conn *Conn, line *Line)

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 ParseLine

func ParseLine(s string) *Line

ParseLine() creates a Line from an incoming message from the IRC server.

func (*Line) Copy

func (l *Line) Copy() *Line

Copy() returns a deep copy of the Line.

func (*Line) Public

func (line *Line) Public() bool

NOTE: Makes the assumption that all channels start with #.

func (*Line) Target

func (line *Line) Target() string

Return the target of the line, usually the first Arg for the IRC verb. If the line was broadcast from a channel, the target will be that channel. If the line was broadcast by a user, the target will be that user. TODO(fluffle): Add 005 CHANTYPES parsing for this?

func (*Line) Text

func (line *Line) Text() string

Return the contents of the text portion of a line. This only really makes sense for lines with a :text part, but there are a lot of them.

type Remover

type Remover interface {
	Remove()
}

And when they've been added to the client they are removable.

Jump to

Keyboard shortcuts

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