irc

package module
v0.0.0-...-9ea7cf4 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2022 License: MIT Imports: 12 Imported by: 0

README

IRC

Pipeline Status Coverage Report Go Report Card License MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
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.

View Source
var ErrConnClosed = errors.New("irc: client closed")

ErrConnClosed is returned by the Client's Listen method after a call to Shutdown or Close.

View Source
var ErrConnReadFailed = errors.New("irc: connection read failed")

ErrConnReadFailed error

View Source
var ErrConnWriteFailed = errors.New("irc: connection read failed")

ErrConnWriteFailed error

View Source
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.

View Source
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.

View Source
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.

View Source
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.

View Source
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

View Source
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

func DialTLSTimeout(address string, insecure bool, timeout time.Duration) (net.Conn, error)

DialTLSTimeout func

func DialTimeout

func DialTimeout(address string, timeout time.Duration) (net.Conn, error)

DialTimeout func

Types

type Client

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

Client struct

func NewClient

func NewClient(nickName string, options ...Option) *Client

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

func (c *Client) CapReq(cap ...string)

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

func (c *Client) Close() error

Close func

func (*Client) Disconnect

func (c *Client) Disconnect(msg ...string) time.Duration

Disconnect func

func (*Client) Invite

func (c *Client) Invite(nickname, channel string)

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.

https://tools.ietf.org/html/rfc1459#section-4.2.7

func (*Client) Join

func (c *Client) Join(channel string) error

Join is used by client to start listening a specific channel.

https://tools.ietf.org/html/rfc1459#section-4.2.1

func (*Client) Kick

func (c *Client) Kick(channel string, user string, reason string)

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.

https://tools.ietf.org/html/rfc1459#section-4.2.8

func (*Client) ListenAndHandle

func (c *Client) ListenAndHandle(conn net.Conn, handler Handler) error

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

func (c *Client) Mode(target string, flags string)

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.

https://tools.ietf.org/html/rfc1459#section-4.2.3

func (*Client) Nick

func (c *Client) Nick(nick string)

Nick command is used to give user a nickname or change the previous one.

https://tools.ietf.org/html/rfc1459#section-4.1.2

func (*Client) Part

func (c *Client) Part(channel string)

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.

https://tools.ietf.org/html/rfc1459#section-4.2.2

func (*Client) Pass

func (c *Client) Pass(password string)

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.

https://tools.ietf.org/html/rfc1459#section-4.1.1

func (*Client) Pong

func (c *Client) Pong(daemon string)

Pong message is a reply to ping message.

https://tools.ietf.org/html/rfc1459#section-4.6.3

func (*Client) PrivMsg

func (c *Client) PrivMsg(msg string, receiver ...string)

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

https://tools.ietf.org/html/rfc1459#section-4.4.1

func (*Client) Quit

func (c *Client) Quit(msg string)

Quit command is used to end the client session.

https://tools.ietf.org/html/rfc1459#section-4.1.6

func (*Client) Sendln

func (c *Client) Sendln(format string, args ...interface{})

Sendln func

func (*Client) Topic

func (c *Client) Topic(channel string, topic ...string)

Topic is used to change or view the topic of a channel.

https://tools.ietf.org/html/rfc1459#section-4.2.4

func (*Client) User

func (c *Client) User(username, hostname, servername, realname string)

User command is used at the beginning of connection to specify the username, hostname, servername and realname of a new user.

https://tools.ietf.org/html/rfc1459#section-4.1.3

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

func (mux *HandleMux) Handle(command, name string, handler Handler) error

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

func (mux *HandleMux) HandleIRCMessage(c *Client, msg *Message) error

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

func (mux *HandleMux) RemoveHandler(command, name string) error

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

type Handler interface {
	HandleIRCMessage(c *Client, m *Message) error
}

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

type HandlerFunc func(*Client, *Message) error

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

func ParseMessage(msg string) (*Message, error)

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

func (msg *Message) Copy() *Message

Copy returns a deep copy of the Message

func (*Message) Directive

func (msg *Message) Directive(prefix rune) (cmd string, params string, ok bool)

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

func (msg *Message) Receiver() string

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.

func (*Message) Sender

func (msg *Message) Sender() string

Sender returns the source of the message. If it's a server generated message it returns the servername (e.g irc.foonet.com). If it's a user generated message it returns the nick (e.g johndoe). Some messages don't specify the sender in which case an empty string is returned.

func (*Message) String

func (msg *Message) String() string

String returns the IRC message in its raw format

type Option

type Option func(*Options)

Option is a function on the options for a connection.

func Password

func Password(password string) Option

Password is an Option to connect to the IRC server with the password provided.

func Realname

func Realname(realname string) Option

Realname is an Option to connect to the IRC server with the password provided.

func RequestCapabilities

func RequestCapabilities(caps ...string) Option

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

See also

https://tools.ietf.org/html/rfc1459#section-2.3.1

type Tags

type Tags map[string]string

Tags represents a structured format of IRCv3.2 message tags.

<tag> [';' <tag>]*

See also

https://ircv3.net/specs/core/message-tags-3.2.html

Jump to

Keyboard shortcuts

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