Categorygithub.com/gempir/go-twitch-irc/v3
modulepackage
3.3.0
Repository: https://github.com/gempir/go-twitch-irc.git
Documentation: pkg.go.dev

# README

go-twitch-irc Coverage Status

This is an irc client for connecting to twitch. It handles the annoying stuff like irc tag parsing. I highly recommend reading the documentation below, but this readme gives a basic overview of the functionality.

Documentation: https://pkg.go.dev/github.com/gempir/go-twitch-irc/v3?tab=doc

Getting Started

package main

import (
	"fmt"

	"github.com/gempir/go-twitch-irc/v3"
)

func main() {
	// or client := twitch.NewAnonymousClient() for an anonymous user (no write capabilities)
	client := twitch.NewClient("yourtwitchusername", "oauth:123123123")

	client.OnPrivateMessage(func(message twitch.PrivateMessage) {
		fmt.Println(message.Message)
	})

	client.Join("gempir")

	err := client.Connect()
	if err != nil {
		panic(err)
	}
}

Available Data

The twitch.User and MessageType structs reflect the data Twitch provides, minus any fields that have been marked as deprecated:

type User struct {
	ID          string
	Name        string
	DisplayName string
	Color       string
	Badges      map[string]int
}

type WhisperMessage struct {
	User User

	Raw       string
	Type      MessageType
	RawType   string
	Tags      map[string]string
	Message   string
	Target    string
	MessageID string
	ThreadID  string
	Emotes    []*Emote
	Action    bool
}

type PrivateMessage struct {
	User User

	Raw     string
	Type    MessageType
	RawType string
	Tags    map[string]string
	Message string
	Channel string
	RoomID  string
	ID      string
	Time    time.Time
	Emotes  []*Emote
	Bits    int
	Action  bool
}

type ClearChatMessage struct {
	Raw            string
	Type           MessageType
	RawType        string
	Tags           map[string]string
	Message        string
	Channel        string
	RoomID         string
	Time           time.Time
	BanDuration    int
	TargetUserID   string
	TargetUsername string
}

type ClearMessage struct {
	Raw         string
	Type        MessageType
	RawType     string
	Tags        map[string]string
	Message     string
	Channel     string
	Login       string
	TargetMsgID string
}

type RoomStateMessage struct {
	Raw     string
	Type    MessageType
	RawType string
	Tags    map[string]string
	Message string
	Channel string
	RoomID  string
	State   map[string]int
}

type UserNoticeMessage struct {
	User User

	Raw       string
	Type      MessageType
	RawType   string
	Tags      map[string]string
	Message   string
	Channel   string
	RoomID    string
	ID        string
	Time      time.Time
	Emotes    []*Emote
	MsgID     string
	MsgParams map[string]string
	SystemMsg string
}

type UserStateMessage struct {
	User User

	Raw       string
	Type      MessageType
	RawType   string
	Tags      map[string]string
	Message   string
	Channel   string
	EmoteSets []string
}

type GlobalUserStateMessage struct {
	User User

	Raw       string
	Type      MessageType
	RawType   string
	Tags      map[string]string
	EmoteSets []string
}

type NoticeMessage struct {
	Raw     string
	Type    MessageType
	RawType string
	Tags    map[string]string
	Message string
	Channel string
	MsgID   string
}

type UserJoinMessage struct {
	// Channel name
	Channel string

	// User name
	User string
}

type UserPartMessage struct {
	// Channel name
	Channel string

	// User name
	User string
}

For unsupported message types, we return RawMessage:

type RawMessage struct {
	Raw     string
	Type    MessageType
	RawType string
	Tags    map[string]string
	Message string
}

Available Methods

ParseMessage parses a raw Twitch IRC message into a User and a message object. User can be nil.

func ParseMessage(line string) (*User, interface{})

Client Methods

These are the available methods of the client so you can get your bot going:

func (c *Client) Say(channel, text string)
func (c *Client) Whisper(username, text string)
func (c *Client) Join(channel string)
func (c *Client) Depart(channel string)
func (c *Client) Userlist(channel string) ([]string, error)
func (c *Client) Connect() error
func (c *Client) Disconnect() error
func (c *Client) DeleteMessage(channel, msgID string)

Options

On your client you can configure multiple options:

client.IrcAddress = "127.0.0.1:3030" // for custom irc server
client.TLS = false // enabled by default, will connect to non TLS server of twitch when off or the given client.IrcAddress
client.SetupCmd = "LOGIN custom_command_here" // Send a custom command on successful IRC connection, before authentication.
client.Capabilities = []string{twitch.TagsCapability, twitch.CommandsCapability} // Customize which capabilities are sent
client.SetJoinRateLimiter(twitch.CreateVerifiedRateLimiter()) // If you have a verified bot or other needs use this to set a custom rate limiter

Option modifications must be done before calling Connect on the client.

Capabilities

By default, the client sends along these capabilities (Tags, Commands).

Callbacks

These callbacks are available to pass to the client:

client.OnConnect(func() {})
client.OnPrivateMessage(func(message PrivateMessage) {})
client.OnWhisperMessage(func(message WhisperMessage) {})
client.OnClearChatMessage(func(message ClearChatMessage) {})
client.OnClearMessage(func(message ClearMessage) {})
client.OnRoomStateMessage(func(message RoomStateMessage) {})
client.OnUserNoticeMessage(func(message UserNoticeMessage) {})
client.OnUserStateMessage(func(message UserStateMessage) {})
client.OnGlobalUserStateMessage(func(message GlobalUserStateMessage) {})
client.OnNoticeMessage(func(message NoticeMessage) {})
client.OnUserJoinMessage(func(message UserJoinMessage) {})
client.OnUserPartMessage(func(message UserPartMessage) {})
client.OnSelfJoinMessage(func(message UserJoinMessage) {})
client.OnSelfPartMessage(func(message UserPartMessage) {})

Message Types

If you ever need more than basic PRIVMSG, this might be for you. These are the message types currently supported:

WHISPER
PRIVMSG
CLEARCHAT
CLEARMSG
ROOMSTATE
USERNOTICE
USERSTATE
GLOBALUSERSTATE
NOTICE
JOIN
PART

# Packages

No description provided by the author

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
NewAnonymousClient to create a new client without login requirements (anonymous user) Do note that the Say and Whisper functions will be ineffectual when using this constructor.
NewClient to create a new client.
ParseMessage parse a raw Twitch IRC message.

# Constants

CLEARCHAT timeout messages.
CLEARMSG whenever a single message is deleted.
CommandsCapability for Twitch's Commands capabilities, see https://dev.twitch.tv/docs/irc/commands.
GLOBALUSERSTATE On successful login, provides data about the current logged-in user through IRC tags.
JOIN whenever a user joins a channel.
MembershipCapability for Twitch's Membership capabilities, see https://dev.twitch.tv/docs/irc/membership.
NAMES (or 353 https://www.alien.net.au/irc/irc2numerics.html#353) is the response sent from the server when the client requests a list of names for a channel.
NOTICE messages like sub mode, host on.
PART whenever a user parts from a channel.
PING is a message that can be sent from the IRC server.
PONG is a message that should be sent from the IRC server as a response to us sending a PING message.
PRIVMSG standard chat message.
RECONNECT is sent from Twitch when they request the client to reconnect (i.e.
ROOMSTATE changes like sub mode.
TagsCapability for Twitch's Tags capabilities, see https://dev.twitch.tv/docs/irc/tags.
No description provided by the author
No description provided by the author
UNSET is for message types we currently don't support.
USERNOTICE messages like subs, resubs, raids, etc.
USERSTATE messages.
WHISPER private messages.

# Variables

DefaultCapabilities is the default caps when creating a new Client.
ErrClientDisconnected returned from Connect() when a Disconnect() was called.
ErrConnectionIsNotOpen is returned by Disconnect in case you call it without being connected.
ErrLoginAuthenticationFailed returned from Connect() when either the wrong or a malformed oauth token is used.
ReadBufferSize can be modified to change the read channel buffer size.
WriteBufferSize can be modified to change the write channel buffer size.

# Structs

ClearChatMessage data you receive from CLEARCHAT message type.
ClearMessage data you receive from CLEARMSG message type.
Client client to control your connection and attach callbacks.
Emote twitch emotes.
EmotePosition is a single position of an emote to be used for text replacement.
GlobalUserStateMessage On successful login, provides data about the current logged-in user through IRC tags See https://dev.twitch.tv/docs/irc/tags/#globaluserstate-twitch-tags.
NamesMessage describes the data posted in response to a /names command See https://www.alien.net.au/irc/irc2numerics.html#353.
NoticeMessage data you receive from the NOTICE message type.
PingMessage describes an IRC PING message.
PongMessage describes an IRC PONG message.
PrivateMessage data you receive from PRIVMSG message type.
RawMessage data you receive from TMI.
ReconnectMessage describes the.
No description provided by the author
RoomStateMessage data you receive from ROOMSTATE message type.
User data you receive from TMI.
UserJoinMessage desJoines the message that is sent whenever a user joins a channel we're connected to See https://dev.twitch.tv/docs/irc/membership/#join-twitch-membership.
UserNoticeMessage data you receive from USERNOTICE message type.
UserPartMessage describes the message that is sent whenever a user leaves a channel we're connected to See https://dev.twitch.tv/docs/irc/membership/#part-twitch-membership.
UserStateMessage data you receive from the USERSTATE message type.
WhisperMessage data you receive from WHISPER message type.
No description provided by the author

# Interfaces

Message interface that all messages implement.
No description provided by the author

# Type aliases

MessageType different message types possible to receive via IRC.