irc

package module
v0.0.0-...-14833f9 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2014 License: MIT Imports: 9 Imported by: 0

README

IRC

irc-go GoDoc

Go-IRC is tiny IRC library which additionally supports concurrent writes from multiple Handlers to the same conneciton object. Please see the examples to learn how to use this library. Other useful sources of information include:

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidMessage is used by irc.ParseLine to indicate that the given
	// "raw" string does not conform to RFC1459.
	ErrInvalidMessage = errors.New("invalid message format")
	// ErrUnknownCommand by irc.ParseLine to indicate error condition in which no command was
	// found in the given "raw" message.
	ErrUnknownCommand = errors.New("unknown command")
)

Functions

This section is empty.

Types

type Connection

type Connection struct {

	// MessageChan is passed to handlers to provide a way for handlers to
	// synchronize write access to the underlying IRC connection.
	MessageChan chan *Message

	// Terminate is used to signal the underlying IRC connection is ready to be
	// shut down.
	Terminate chan bool
	// contains filtered or unexported fields
}

Connection represents a connection, as returned by net.Dial(), to an IRC server with methods for synchronizing access.

func Connect

func Connect(address string, verbose bool) (*Connection, error)

Connect to the given address and return a connected Connection object.

func (*Connection) GetHandlers

func (c *Connection) GetHandlers() (handlers []Handler)

GetHandlers returns a slice representing the Handlers currently handling messages from the Connection.

func (*Connection) HandleMessage

func (c *Connection) HandleMessage(message *Message) (err error)

HandleMessage provides a convenient way to handle details of IRC protocol such as server PING commands, passed in by the Connection object's incoming message handling loop.

func (*Connection) Initialize

func (c *Connection) Initialize(ch chan *Message) (err error)

Initialize currently does nothing, but exists as a way to allow Connection objects to be treated as Handler's

func (*Connection) Queue

func (c *Connection) Queue(format string, args ...interface{})

Queue synchronizes access to the given Connection using MessageChan channel.

func (*Connection) ReadMessage

func (c *Connection) ReadMessage() (*Message, error)

ReadMessage allows direct access to a bufio.Reader. It returns an irc.Message representing the next line in the incoming buffer.

func (*Connection) RegisterHandler

func (c *Connection) RegisterHandler(handler Handler)

RegisterHandler adds a Handler intended to accept incoming messages from the IRC server represented by the Connection.

func (*Connection) Send

func (c *Connection) Send(format string, args ...interface{})

Send is intended to be used by clients to pass IRC messages to the server represented by Connection. This happens directly whenever the loops initiated by Serve are not running--that is to say, a call to Send will directly pass the given parameters to the underlying connection object through fmt.Fprintf

After the loops initiated by Serve have begun, Send becomes and alias for Queue in order to synchronize access to the underlying connection object with whatever handlers may be registered.

func (*Connection) Serve

func (c *Connection) Serve()

Serve initiates the incoming message handling loop to pass incoming Message instances to all available Message handlers registered with the Connection object.

Serve also initiates the loop which, after Serve is run, synchronizes all outgoing messages passed through the Connection.MessageChan channel by handlers.

type Handler

type Handler interface {
	// Used by irc.Connection to provide access to its chan *Message when
	// registering a new Handler with RegisterHandler.
	Initialize(chan *Message) (err error)

	// Used by irc.Connection to pass in messages from the server.
	HandleMessage(*Message) (err error)
}

Handler interface provides a means for users to implement "handlers" for irc.Message objects. This interface is used by irc.Connection to dispatch messages to custom handlers.

The user may choose to do as she wishes with these messages or to respond in her own time to the underlying Server by queuing messages through the chan *Message passed in through the Initialize method.

type Message

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

Message is a struct representing a go message according to http://tools.ietf.org/html/rfc1459.html#section-2.3.1

func ParseLine

func ParseLine(raw string) (*Message, error)

ParseLine is used to create irc.Message objects out of raw strings.

When sending messages, <prefix> is automatically determined by the receiving end of the connection based on available TCP/IP and DNS connection information. ParseLine takes this into account by making the ":<prefix> " optional.

When used to construct messages, the raw string must follow the guidelines in RFC1459: http://tools.ietf.org/html/rfc1459

Please note that it is NOT the user's responsibility to deal with prefixes--this is determined upon arrival at the IRC server or client. Therefore, for the purpose of this library please use the following format for "raw" strings, where <command> is a valied ASCII command as described in the RFC1459.

<command>[ <params> [:<trailing>]]

func (*Message) Command

func (m *Message) Command() string

Command provides read-only public access to the internal IRC "command".

func (*Message) Params

func (m *Message) Params() []string

Params provides read-only public access to the internal IRC "params".

func (*Message) Prefix

func (m *Message) Prefix() string

Prefix provides read-only public access to the internal IRC "prefix".

func (*Message) String

func (m *Message) String() string

String provides read-only public access to the internal IRC raw representation of the message.

func (*Message) Trailing

func (m *Message) Trailing() string

Trailing provides read-only public access to the internal IRC "trailing".

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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