irc

package
v0.0.0-...-9fdc65e Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CapTags adds additional metadata to the command and membership messages. Such as user ID, display name, badges etc.
	CapTags = "twitch.tv/tags"
	// CapCommands lets your bot send PRIVMSG messages that include Twitch chat commands and receive Twitch-specific IRC messages.
	CapCommands = "twitch.tv/commands"
	// CapMembership lets your bot receive JOIN and PART messages when users join and leave the chat room.
	CapMembership = "twitch.tv/membership"
)

Variables

View Source
var (
	// ReadBuffer assigns a buffer size to the read channel
	ReadBuffer = 32
	// WriteBuffer assigns a buffer size to the write channel
	WriteBuffer = 0
	// Address sets the address that the client will connect to
	Address = "irc.chat.twitch.tv:6667"
	// AddressTLS sets the address that the client will connect to in TLS mode
	AddressTLS = "irc.chat.twitch.tv:6697"
)
View Source
var (
	// ErrClientDisconnected is returned when the client has disconnected
	ErrClientDisconnected = errors.New("client disconnected")
	// ErrServerDisconnect is returned when the server disconnected us
	ErrServerDisconnect = errors.New("server disconnectd")
	// ErrPartialMessage is returned when the message doesn't contain all expected data
	ErrPartialMessage = errors.New("partial message")
)

Functions

This section is empty.

Types

type Client

type Client struct {

	// UseTLS determines whether the IRC connects with or without TLS, needs to be set before you call Connect, default = true
	UseTLS bool

	// Connected gets closed when the connection to the IRC has been established.
	// Meaning reading from its C channel is no longer blocking.
	Connected util.Closer
	// contains filtered or unexported fields
}

Client handles the IRC connection and incoming & outgoing messages. The client requires you to respond to PING messages manually as well as keep track of which channels you're connected to using the incoming JOIN & PART messages

func New

func New(user, oauth string) *Client

New returns a new client

func NewAnon

func NewAnon() *Client

NewAnon returns an anonymous client, useful for testing, or small read-only bots

func (*Client) Connect

func (c *Client) Connect() (err error)

Connect starts the IRC connection

func (*Client) Disconnect

func (c *Client) Disconnect()

Disconnect closes the IRC connection

func (*Client) Join

func (c *Client) Join(channels ...string)

Join makes the client join the passed channels

func (*Client) OnMessage

func (c *Client) OnMessage(cb func(msg *Message, err error))

OnMessage sets a callback to handle the raw incoming IRC messages

func (*Client) Part

func (c *Client) Part(channels ...string)

Part makes the client leave the passed channels

func (*Client) Send

func (c *Client) Send(line []byte)

Send a []byte message to the server (does not need \r\n at the end of the line)

func (*Client) SendString

func (c *Client) SendString(line string)

SendString sends a string message to the server (does not need \r\n at the end of the line)

func (*Client) WithCapabilities

func (c *Client) WithCapabilities(caps ...string) *Client

WithCapabilities adds twitch-irc specific capabilities to a New client, use the constants defined in capabilities.go

type Message

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

func ParseMessage

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

ParseMessage returns a new message pointer containing the raw data & the message type. returns an error if something went wrong, but will still contain the message object, so you can access the raw data.

func (*Message) GetType

func (m *Message) GetType() MessageType

GetType returns message type, if it has not yet been set, it parses the message to find its type and sets m.messageType for future reference

func (*Message) String

func (m *Message) String() string

String returns the raw IRC message as a string

type MessageType

type MessageType int

MessageType is a type with the underlying type int, it is used with enum constants defined below to help classify incoming IRC messages

const (
	// Unknown means the message type is currently not supported
	Unknown MessageType = iota - 1
	// Unset means the message type has not yet been parsed
	Unset
	// Ping is a PING message coming from the IRC and must be replied to with a PONG message
	Ping
	// Reconnect when this is sent by the IRC, the server is about to disconnect the client, usually means there's a server update
	Reconnect
	// Join means the IRC added the given channel to the current active subscriptions
	Join
	// Part means the bot has been removed from the given channel, could be a timeout/ban, or could be because we asked the IRC to disconnect us
	Part
	// PrivMessage is a chat message sent in a Twitch channel
	PrivMessage
	// Cap is a message pertaining to the twitch-specific capabilities requested on connect
	Cap
	// Notice is a message about a command issues by the client, indicating whether it succeeded or failed
	Notice
)

Jump to

Keyboard shortcuts

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