ircon

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2021 License: BSD-2-Clause Imports: 6 Imported by: 4

Documentation

Overview

Package ircon maintains a connection to the Twitch IRC service.

Index

Constants

View Source
const (
	// DefaultIRCServer is the default Twitch IRC server
	DefaultIRCServer = "ircs://irc.chat.twitch.tv:6697/"

	// DefaultWebChat is the default Twitch "IRC" server used by e.g. web chat
	DefaultWebChat = "wss://irc-ws.chat.twitch.tv/"

	// DefaultServer is the default server.
	DefaultServer = DefaultIRCServer
)
View Source
const DefaultCaps = "twitch.tv/tags twitch.tv/commands"

DefaultCaps is the default set of capabilities. The twitch.tv/membership capability is omitted for performance reasons and its general lack of usefulness in most scenarios.

Variables

View Source
var ErrNotConnected = errors.New("Not connected")

Functions

This section is empty.

Types

type Handler

type Handler interface {
	// Connected is called when a connection is fully established and the
	// connection is ready to send messages.
	Connected()

	// Disconnected is called when an active connection ends, potentially due
	// to an error. It will also be called when establishing a connection
	// fails, before it was fully Connected.
	Disconnected(err error)

	// Message is called for every incoming message. Note that it can be called
	// before Connected or after Disconnected are called.
	Message(*irc.Message)
}

A Handler receives events from IRCon.

type Handshaker added in v0.2.0

type Handshaker interface {
	Handshake(s Sender) error
}

type IRCHandshake added in v0.2.0

type IRCHandshake struct {
	// Caps contains the set of capabilities that are requested on connect.
	// Advanced users can specify their own set.
	Caps string

	Nick   string
	Ident  string
	GECOS  string
	Passwd string
}

IRCHandshake implements a standard pre-registered-state handshake for the IRC protocol.

func TwitchHandshaker added in v0.2.0

func TwitchHandshaker(nick, passwd string) IRCHandshake

TwitchHandshaker creates an IRCHandshake with some Twitch-specific details.

func (IRCHandshake) Handshake added in v0.2.0

func (irc IRCHandshake) Handshake(con Sender) error

type IRCon

type IRCon struct {
	// Server allows connecting to a different TMI server.
	Server string
	// contains filtered or unexported fields
}

An IRCon is an automatically reconnecting IRC connection.

func New

func New(d irc.Dialer, h Handshaker) *IRCon

New creates a new IRCon with the given credentials.

func (*IRCon) Run

func (i *IRCon) Run(ctx context.Context, h Handler)

Run maintains a connection to the IRC server until the context is done.

func (*IRCon) Send

func (i *IRCon) Send(s string) error

Send sends a message to the currently active IRC connection. If there is no active connection, the message is lost.

TODO: typically we want to associate message sending with a specific connection instance, and not confuse it during reconnects. TODO: make a variant that can wait for a succesful connection.

type Message

type Message = irc.Message

Message aliases irc.Message for import convenience.

type Sender added in v0.2.0

type Sender interface {
	Send(msg string) error
}

Sender abstraction for Handshaker

Jump to

Keyboard shortcuts

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