Documentation
¶
Index ¶
- Variables
- func DialTLSTimeout(address string, insecure bool, timeout time.Duration) (net.Conn, error)
- func DialTimeout(address string, timeout time.Duration) (net.Conn, error)
- type Client
- func (c *Client) CapReq(cap ...string)
- func (c *Client) Close() error
- func (c *Client) Disconnect(msg ...string) time.Duration
- func (c *Client) Invite(nickname, channel string)
- func (c *Client) Join(channel string) error
- func (c *Client) Kick(channel string, user string, reason string)
- func (c *Client) ListenAndHandle(conn net.Conn, handler Handler) error
- func (c *Client) Mode(target string, flags string)
- func (c *Client) Nick(nick string)
- func (c *Client) Part(channel string)
- func (c *Client) Pass(password string)
- func (c *Client) Pong(daemon string)
- func (c *Client) PrivMsg(msg string, receiver ...string)
- func (c *Client) Quit(msg string)
- func (c *Client) Sendln(format string, args ...interface{})
- func (c *Client) Topic(channel string, topic ...string)
- func (c *Client) User(username, hostname, servername, realname string)
- type HandleMux
- type Handler
- type HandlerFunc
- type Message
- type Option
- type Options
- type Prefix
- type Tags
Constants ¶
This section is empty.
Variables ¶
var ErrAuthFailed = errors.New("irc: authentication failed")
ErrAuthFailed is returned by the Client's Listen method after connecting to a password protected server with invalid credentials.
var ErrConnClosed = errors.New("irc: client closed")
ErrConnClosed is returned by the Client's Listen method after a call to Shutdown or Close.
var ErrConnReadFailed = errors.New("irc: connection read failed")
ErrConnReadFailed error
var ErrConnWriteFailed = errors.New("irc: connection read failed")
ErrConnWriteFailed error
var ErrEmptyMessage = errors.New("irc: empty message")
ErrEmptyMessage is returned by ParseMessage if the IRC message string passed in for parsing is an empty string. The IRC message is considered empty if it doesn't contain anything other than trailing <crlf> and/or whitespace.
var ErrHandlerNotFound = errors.New("irc: handler not found")
ErrHandlerNotFound is returned by the Client's Listen method if a message is received but the Client doesn't have a Handler set to handle the incoming messages.
var ErrInvalidChannelName = errors.New("irc: invalid channel name")
ErrInvalidChannelName is returned by Join if the IRC channel name(s) given do not conform to the rfc1459 specification.
var ErrInvalidMessage = errors.New("irc: invalid message")
ErrInvalidMessage is returned by ParseMessage if the message string passed in for parsing is invalid. A message is considered invalid if it doesn't conform to the RFC 1459 specification.
var ErrNotConnected = errors.New("irc: not connected")
ErrNotConnected error is returned by the Client's Listen method when the client is initialized with a nil Connection
var ErrUnregisteredHandler = errors.New("irc: unregistered handler")
ErrUnregisteredHandler is returned by RemoveHandler and RemoveDirectiveHandler if there is no handler registered for the given command or directive with the given name, respectively.
Functions ¶
func DialTLSTimeout ¶
DialTLSTimeout func
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client struct
func NewClient ¶
NewClient returns a new Client given a conn, which is used by the Client to read IRC Messages from and write IRC Messages to.
func (*Client) CapReq ¶
CapReq is used to request a change in capabilities associated with the active connection. The last parameter is a space-separated list of capabilities. Each capability identifier may be prefixed with a dash (-) to designate that the capability should be disabled.
https://ircv3.net/specs/core/capability-negotiation#the-cap-req-subcommand
func (*Client) Disconnect ¶
Disconnect func
func (*Client) Invite ¶
Invite is used to invite users to a channel. To invite a user to a channel which is invite only (MODE +i), the client sending the invite must be recognised as being a channel operator on the given channel.
func (*Client) Kick ¶
Kick can be used to forcibly remove a user from a channel. It 'kicks them out' of the channel (forced `Part`). Only a channel operator may kick another user out of a channel.
func (*Client) ListenAndHandle ¶
ListenAndHandle listens on the given connenction for IRC messages and handles them as defined by the provided Handler. If no Handler is provided, a default system handler (NewSysHandleMux) is used for essential operations such as maintaining the connection and basic error handling.
func (*Client) Mode ¶
Mode is a dual-purpose command. It allows both usernames and channels to have their mode changed. The rationale for this choice is that one day nicknames will be obsolete and the equivalent property will be the channel.
func (*Client) Part ¶
Part causes the client sending the message to be removed from the list of active users for all given channels listed in the parameter string.
func (*Client) Pass ¶
Pass command is used to set a 'connection password'. The password can and must be set before any attempt to register the connection is made.
func (*Client) PrivMsg ¶
PrivMsg is used to send private messages between users. `receiver` is the nickname of the receiver of the message. `receiver` can also be a list of names or channels
type HandleMux ¶
type HandleMux struct {
// contains filtered or unexported fields
}
HandleMux is an IRC message handler multiplexer. It matches the contents of each incoming message against a list of registered patterns and calls the handler for the pattern that matches the message, if any.
Commands are IRC commands as defined in RFC 1459 and RFC 2810 through 2813.
mux := irc.NewHandleMux() // Matches PING :irc.foonet.com mux.HandleFunc("PING", "print-ping", func(c *irc.Client, msg *irc.Message) { // Prints the raw PING message to standard output fmt.Println(msg.String()) })
func NewHandleMux ¶
func NewHandleMux() *HandleMux
NewHandleMux allocates and returns a new HandleMux.
func NewSysHandleMux ¶
func NewSysHandleMux() *HandleMux
NewSysHandleMux allocates and returns a new HandleMux with essential message handlers.
func (*HandleMux) Handle ¶
Handle registers the handler for the given command with the given name. Multiple handlers can be registered for the same command as long as they are registered with a unique name. Registering a handler with a name with which a handler has already been registered for the same command, the original handler will be removed and the new one will take its place.
func (*HandleMux) HandleFunc ¶
func (mux *HandleMux) HandleFunc(command, name string, handler HandlerFunc) error
HandleFunc registers the handler function for the given command with the given name.
func (*HandleMux) HandleIRCMessage ¶
HandleIRCMessage dispatches the request to all handlers that is registered either registered to handle the Command of the IRC Message or pattern most closely matches the request URL.
func (*HandleMux) RemoveHandler ¶
RemoveHandler deregisters the handler for the given command with the given name. Returns ErrUnregisteredHandler if there is no handler registered for the given command with the given name.
type Handler ¶
A Handler responds to an IRC message.
HandleIRCMessage is called when a client receives a message. If HandleIRCMessage panics the client doesn't recover the panic.
type HandlerFunc ¶
The HandlerFunc type is an adapter to allow the use of ordinary functions as IRC Message handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler that calls f.
func (HandlerFunc) HandleIRCMessage ¶
func (f HandlerFunc) HandleIRCMessage(c *Client, m *Message) error
HandleIRCMessage calls f(c, m).
type Message ¶
type Message struct { // Tags represent optional IRCv3.2 <tags>. *Tags // Prefix represents the optional <prefix>. *Prefix // Command represents the IRC <command> being called. Command string // Params represents the list of <middle> <params>. Params []string // Trailing represents the last ':' prefixed <trailing> <params>. Trailing string // contains filtered or unexported fields }
Message represents a structured format of an IRC message as per RFC 1459 specification. IRCv3.2 Message Tags are also supported.
['@' <tags> <SPACE>] [':' <prefix> <SPACE> ] <command> <params> <crlf>
See also ¶
https://tools.ietf.org/html/rfc1459#section-2.3.1 and https://ircv3.net/specs/core/message-tags-3.2.html
func ParseMessage ¶
ParseMessage parses the raw IRC message and returns the result as a Message struct. If the raw IRC message is empty or invalid, ParseMessage returns an ErrEmptyMessage or ErrInvalidMessage respectively. For an IRC message to be considered valid, it has to conform to the RFC1459 specification. Optional IRCv3.2 Message Tags are also supported.
func (*Message) Directive ¶
Directive converts the `Message`'s `Trailing` parameter into a directive based on the prefix provided. The directive consists of a command and its parameters, returned as whitespace trimmed strings and the ok flag true, meaning success. In case the `Message` isn't a directive, two empty strings are returned along with the ok flag set to false.
func (*Message) Receiver ¶
Receiver returns the target of the message. Generally messages are targeted at either channels (e.g #golang) or users (e.g johndoe). Some messages don't specify a receiver in which case an empty string is returned.
type Option ¶
type Option func(*Options)
Option is a function on the options for a connection.
func RequestCapabilities ¶
RequestCapabilities is an Option to request IRC server capabilites to be enabled upon successful connection.
type Options ¶
type Options struct { // Password Password string // Realname Realname string // RequestCapabilities RequestCapabilities []string }
Options can be used to a create a customized connection.
func GetDefaultOptions ¶
func GetDefaultOptions() Options
GetDefaultOptions returns default configuration options for the client.
type Prefix ¶
type Prefix struct { // Nick contains the <nick> of the sender of the message. // Only set if the message is a user generated message. Nick string // Server contains the <servername> of the sender of the message. // Only set if the message is a server generated message. Server string // User contains the <user> ident of the sender, if available. User string // Host contains the <host> of the sender, if available. Host string }
Prefix represents the optional prefix of an IRC Message as per RFC1459 specification.
<servername> | <nick> [ '!' <user> ] [ '@' <host> ]