Documentation ¶
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) Connect() (err error)
- func (c *Client) Disconnect()
- func (c *Client) Join(channels ...string)
- func (c *Client) OnMessage(cb func(msg *Message, err error))
- func (c *Client) Part(channels ...string)
- func (c *Client) Send(line []byte)
- func (c *Client) SendString(line string)
- func (c *Client) WithCapabilities(caps ...string) *Client
- type Message
- type MessageType
Constants ¶
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 ¶
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" )
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 NewAnon ¶
func NewAnon() *Client
NewAnon returns an anonymous client, useful for testing, or small read-only bots
func (*Client) Send ¶
Send a []byte message to the server (does not need \r\n at the end of the line)
func (*Client) SendString ¶
SendString sends a string message to the server (does not need \r\n at the end of the line)
func (*Client) WithCapabilities ¶
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 ¶
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
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 )