Documentation
¶
Index ¶
- Constants
- Variables
- type ChannelUserState
- type ChatBan
- type ChatMessage
- type ChatMessageDelete
- type ChatSender
- type Client
- func (client *Client) Close()
- func (client *Client) GetChannel(channel string) (RoomState, bool)
- func (client *Client) GetNextShard() (*Conn, error)
- func (client *Client) GetShard(id int) (*Conn, error)
- func (client *Client) Join(channels ...string) error
- func (client *Client) Leave(channels ...string) error
- func (client *Client) OnShardChannelBan(f func(int, ChatBan))
- func (client *Client) OnShardChannelJoin(f func(int, string, string))
- func (client *Client) OnShardChannelLeave(f func(int, string, string))
- func (client *Client) OnShardChannelMessageDelete(f func(int, ChatMessageDelete))
- func (client *Client) OnShardChannelUpdate(f func(int, RoomState))
- func (client *Client) OnShardChannelUserNotice(f func(int, UserNotice))
- func (client *Client) OnShardDisconnect(f func(int))
- func (client *Client) OnShardLatencyUpdate(f func(int, time.Duration))
- func (client *Client) OnShardMessage(f func(int, ChatMessage))
- func (client *Client) OnShardRawMessage(f func(int, Message))
- func (client *Client) OnShardReconnect(f func(int))
- func (client *Client) OnShardServerNotice(f func(int, ServerNotice))
- func (client *Client) SetMaxChannelsPerShard(max int)
- type Command
- type Conn
- func (conn *Conn) Close()
- func (conn *Conn) Connect() error
- func (conn *Conn) GetChannel(channel string) (RoomState, bool)
- func (conn *Conn) IsConnected() bool
- func (conn *Conn) IsShard() bool
- func (conn *Conn) Join(channels ...string) error
- func (conn *Conn) Leave(channels ...string) error
- func (conn *Conn) OnChannelBan(f func(ChatBan))
- func (conn *Conn) OnChannelJoin(f func(string, string))
- func (conn *Conn) OnChannelLeave(f func(string, string))
- func (conn *Conn) OnChannelMessageDelete(f func(ChatMessageDelete))
- func (conn *Conn) OnChannelUpdate(f func(RoomState))
- func (conn *Conn) OnChannelUserNotice(f func(UserNotice))
- func (conn *Conn) OnDisconnect(f func())
- func (conn *Conn) OnLatencyUpdate(f func(time.Duration))
- func (conn *Conn) OnMessage(f func(ChatMessage))
- func (conn *Conn) OnRawMessage(f func(Message))
- func (conn *Conn) OnReconnect(f func())
- func (conn *Conn) OnServerNotice(f func(ServerNotice))
- func (conn *Conn) Ping() (time.Duration, error)
- func (conn *Conn) Reconnect() error
- func (conn *Conn) Say(channel string, message string) error
- func (conn *Conn) Sayf(channel string, format string, a ...interface{}) error
- func (conn *Conn) SendRaw(raw ...string) error
- func (conn *Conn) SetLogin(username, token string) error
- type GlobalUserState
- type IClient
- type IConn
- type IMessageParser
- type Message
- type RoomState
- func (state RoomState) IsEmoteOnly() bool
- func (state RoomState) IsFollowersOnly() (enabled bool, duration time.Duration)
- func (state RoomState) IsR9KModeEnabled() bool
- func (state RoomState) IsRitualsEnabled() bool
- func (state RoomState) IsSlowModeEnabled() (enabled bool, duration time.Duration)
- func (state RoomState) IsSubscribersOnly() bool
- type ServerNotice
- type Source
- type UserNotice
- type UserState
Constants ¶
const IP = "irc.chat.twitch.tv"
IP for the IRC server
Variables ¶
var ( // ErrShardIDOutOfBounds returned when an invalid shard id is provided ErrShardIDOutOfBounds = errors.New("shard id out of bounds") // ErrShardedMessageSend returned when a sharded connection tries to send a message ErrShardedMessageSend = errors.New("messages can not be sent on a sharded connection") // ErrNotConnected returned when the connection is closed ErrNotConnected = errors.New("connection is closed") // ErrNotAuthenticated returned when authentication is required but not set ErrNotAuthenticated = errors.New("not authenticated") // ErrAlreadyConnected returned when a connection tries to connect but is already running ErrAlreadyConnected = errors.New("client is already connected") // ErrPingTimeout returned when the server takes too long to respond to a ping message ErrPingTimeout = errors.New("server took too long to respond to ping") // ErrPartialMessage returned when a raw message is not complete ErrPartialMessage = errors.New("parseError: partial message") // ErrNoCommand returned when a raw message has no command ErrNoCommand = errors.New("parseError: no command") )
Functions ¶
This section is empty.
Types ¶
type ChannelUserState ¶
type ChannelUserState struct { UserState IsBroadcaster bool IsModerator bool IsVIP bool IsSubscriber bool }
ChannelUserState is the state of the authenticated user in a channels chatroom
func NewChannelUserState ¶
func NewChannelUserState(msg Message) (state ChannelUserState)
NewChannelUserState parses the state of an authenticated user in a channels chatroom
type ChatBan ¶
type ChatBan struct { IRCMessage Message ChannelName string ChannelID int64 TargetName string TargetID int64 CreatedAt time.Time // contains filtered or unexported fields }
ChatBan is a timeout or permanent ban that was issued on a user in a chatroom
func NewChatBan ¶
NewChatBan parses a ban or timeout in a channels chatroom
func (ChatBan) Expiration ¶
Expiration returns the time that a temporary ban will expire
func (ChatBan) IsTemporary ¶
IsTemporary returns true if a ban is set to expire after a set amount of time
type ChatMessage ¶
type ChatMessage struct { IRCMessage Message Sender ChatSender ID string Channel string ChannelID int64 Text string IsCheer bool IsAction bool CreatedAt time.Time }
ChatMessage is a message sent in a channels chatroom
func NewChatMessage ¶
func NewChatMessage(msg Message) ChatMessage
NewChatMessage parses a message sent in a channels chatroom
type ChatMessageDelete ¶
type ChatMessageDelete struct { IRCMessage Message ChannelName string TargetID string TargetSenderName string Text string CreatedAt time.Time }
ChatMessageDelete is a message that was deleted from the chatroom
func NewChatMessageDelete ¶
func NewChatMessageDelete(msg Message) ChatMessageDelete
NewChatMessageDelete parses a notice that a message was deleted
type ChatSender ¶
type ChatSender struct { ID int64 Username string DisplayName string Color string Badges map[string]string BadgeInfo map[string]string IsBroadcaster bool IsModerator bool IsVIP bool IsSubscriber bool Type string }
ChatSender is a user that sent a message in a channels chatroom
func NewChatSender ¶
func NewChatSender(msg Message) ChatSender
NewChatSender parses the sender for a message in a channels chatroom
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a sharded connection to the Twitch IRC service
func New ¶
func New() *Client
New IRC Client
The client uses a sharding system to allow applications to listen to large numbers of Twitch chatrooms with minimized backlogs of message handling. The client will separate channels into groups of 100 by default.
func (*Client) GetChannel ¶
GetChannel returns true if any shard is listening to the provided channel along with its RoomState
func (*Client) GetNextShard ¶
GetNextShard returns the first shard that can join channels
func (*Client) OnShardChannelBan ¶
OnShardChannelBan event called after a user was banned or timed out in a channels chatoom
func (*Client) OnShardChannelJoin ¶
OnShardChannelJoin event called after a user joins a chatroom
func (*Client) OnShardChannelLeave ¶
OnShardChannelLeave event called after a user leaves a chatroom
func (*Client) OnShardChannelMessageDelete ¶
func (client *Client) OnShardChannelMessageDelete(f func(int, ChatMessageDelete))
OnShardChannelMessageDelete event called after a message was deleted in a channels chatroom
func (*Client) OnShardChannelUpdate ¶
OnShardChannelUpdate event called after a chatrooms state has been modified
func (*Client) OnShardChannelUserNotice ¶
func (client *Client) OnShardChannelUserNotice(f func(int, UserNotice))
OnShardChannelUserNotice event called after a generic user event occurrs in a channels chatroom
func (*Client) OnShardDisconnect ¶
OnShardDisconnect event called after a shards connection is closed
func (*Client) OnShardLatencyUpdate ¶
OnShardLatencyUpdate event called after a shards latency is updated
func (*Client) OnShardMessage ¶
func (client *Client) OnShardMessage(f func(int, ChatMessage))
OnShardMessage event called after a shard receives a chat message
func (*Client) OnShardRawMessage ¶
OnShardRawMessage event called after a shard receives an IRC message
func (*Client) OnShardReconnect ¶
OnShardReconnect event called after a shards connection is reopened
func (*Client) OnShardServerNotice ¶
func (client *Client) OnShardServerNotice(f func(int, ServerNotice))
OnShardServerNotice event called when the IRC server sends a notice message
func (*Client) SetMaxChannelsPerShard ¶
SetMaxChannelsPerShard sets the maximum number of channels a shard can listen to at a time
Default: 100
type Command ¶
type Command string
Command is the command sent in an IRCMessage
const ( // CMDPrivMessage is a PRIVMSG command CMDPrivMessage Command = "PRIVMSG" // CMDClearChat is a CLEARCHAT command CMDClearChat Command = "CLEARCHAT" // CMDClearMessage is a CLEARMSG command CMDClearMessage Command = "CLEARMSG" // CMDHostTarget is a HOSTTARGET command CMDHostTarget Command = "HOSTTARGET" // CMDNotice is a NOTICE command CMDNotice Command = "NOTICE" // CMDReconnect is a RECONNECT command CMDReconnect Command = "RECONNECT" // CMDRoomState is a ROOMSTATE command CMDRoomState Command = "ROOMSTATE" // CMDUserNotice is a USERNOTICE command CMDUserNotice Command = "USERNOTICE" // CMDUserState is a USERSTATE command CMDUserState Command = "USERSTATE" // CMDGlobalUserState is a GLOBALUSERSTATE command CMDGlobalUserState Command = "GLOBALUSERSTATE" // CMDJoin is a JOIN command CMDJoin Command = "JOIN" // CMDPart is a PART command CMDPart Command = "PART" // CMDPing is a PING command CMDPing Command = "PING" // CMDPong is a PONG command CMDPong Command = "PONG" // CMDReady is a 376 command CMDReady Command = "376" )
type Conn ¶
type Conn struct { UserState GlobalUserState Username string // contains filtered or unexported fields }
Conn is a single connection to the Twitch IRC service
func (*Conn) GetChannel ¶
GetChannel returns true if this connection is listening to the provided channel along with its RoomState
func (*Conn) IsConnected ¶
IsConnected returns true if the connection is active
func (*Conn) OnChannelBan ¶
OnChannelBan event called after a user was banned or timed out in a channels chatoom
func (*Conn) OnChannelJoin ¶
OnChannelJoin event called after a user joins a chatroom
func (*Conn) OnChannelLeave ¶
OnChannelLeave event called after a user leeaves a chatroom
func (*Conn) OnChannelMessageDelete ¶
func (conn *Conn) OnChannelMessageDelete(f func(ChatMessageDelete))
OnChannelMessageDelete event called after a message was deleted in a channels chatroom
func (*Conn) OnChannelUpdate ¶
OnChannelUpdate event called after a chatrooms state has been modified
func (*Conn) OnChannelUserNotice ¶
func (conn *Conn) OnChannelUserNotice(f func(UserNotice))
OnChannelUserNotice event called after a generic user event occurrs in a channels chatroom
func (*Conn) OnDisconnect ¶
func (conn *Conn) OnDisconnect(f func())
OnDisconnect event called when the connection was closed
func (*Conn) OnLatencyUpdate ¶
OnLatencyUpdate event called after the latency to server has been updated
func (*Conn) OnMessage ¶
func (conn *Conn) OnMessage(f func(ChatMessage))
OnMessage event called after a message is received
func (*Conn) OnRawMessage ¶
OnRawMessage event called after a raw IRC message has been handled
func (*Conn) OnReconnect ¶
func (conn *Conn) OnReconnect(f func())
OnReconnect event called when the connection is reopened
func (*Conn) OnServerNotice ¶
func (conn *Conn) OnServerNotice(f func(ServerNotice))
OnServerNotice event called when the IRC server sends a notice message
func (*Conn) Ping ¶
Ping sends a ping message to the IRC server
This operation will block, giving the server up to 5 seconds to respond after correcting for latency before failing
func (*Conn) Reconnect ¶
Reconnect closes and reopens the IRC connection
Equivalent to Connect if the connection is not already open
func (*Conn) Say ¶
Say sends a message in the provided channel if authenticated
If using a shards, you must create a single connection and use it as a writer
func (*Conn) Sayf ¶
Sayf sends a formatted message in the provided channel if authenticated
If using a shards, you must create a single connection and use it as a writer
type GlobalUserState ¶
type GlobalUserState struct {
UserState
}
GlobalUserState is the state of the authenticated user that does not change across channels
func NewGlobalUserState ¶
func NewGlobalUserState(msg Message) (state GlobalUserState)
NewGlobalUserState parses the global state of an authenticated user
type IClient ¶
type IClient interface { SetMaxChannelsPerShard(int) GetNextShard() (*Conn, error) GetShard(int) (*Conn, error) GetChannel(string) (RoomState, bool) Join(...string) error Leave(...string) error Close() OnShardMessage(func(int, ChatMessage)) OnShardServerNotice(func(int, ServerNotice)) OnShardLatencyUpdate(func(int, time.Duration)) OnShardChannelJoin(func(int, string, string)) OnShardChannelLeave(func(int, string, string)) OnShardChannelUpdate(func(int, RoomState)) OnShardChannelUserNotice(func(int, UserNotice)) OnShardChannelMessageDelete(func(int, ChatMessageDelete)) OnShardChannelBan(func(int, ChatBan)) OnShardRawMessage(func(int, Message)) OnShardReconnect(func(int)) OnShardDisconnect(func(int)) }
IClient is a generic IRC shard provider
type IConn ¶
type IConn interface { SetLogin(string, string) error IsShard() bool IsConnected() bool GetChannel(string) (RoomState, bool) Connect() error SendRaw(...string) error Ping() (time.Duration, error) Join(...string) error Say(string, string) error Sayf(string, string, ...interface{}) error Leave(...string) error Reconnect() error Close() OnServerNotice(func(ServerNotice)) OnLatencyUpdate(func(time.Duration)) OnChannelJoin(func(string, string)) OnChannelLeave(func(string, string)) OnChannelUpdate(func(RoomState)) OnChannelUserNotice(func(UserNotice)) OnChannelMessageDelete(func(ChatMessageDelete)) OnChannelBan(func(ChatBan)) OnMessage(func(ChatMessage)) OnRawMessage(func(Message)) OnReconnect(func()) OnDisconnect(func()) }
IConn is a generic IRC connection
type IMessageParser ¶
type IMessageParser interface { Parse() error // contains filtered or unexported methods }
IMessageParser is a generic parser for an IRC message
type Message ¶
type Message struct { Raw string Command Command Sender Source Tags map[string]string Params []string Text string }
Message is an IRC message received by the socket
func NewParsedMessage ¶
NewParsedMessage parses raw data from the IRC server and returns an IRCMessage
type RoomState ¶
type RoomState struct { UserState ChannelUserState ID int64 Name string // contains filtered or unexported fields }
RoomState is the current state of a channels chatroom
func NewRoomState ¶
NewRoomState parses the state of a channels chatroom and stores it to the provided pointer
func (RoomState) IsEmoteOnly ¶
IsEmoteOnly returns true if users without VIP or moderator privileges are only permitted to send emotes
func (RoomState) IsFollowersOnly ¶
IsFollowersOnly returns true if users must be following for a set duration before sending messages
func (RoomState) IsR9KModeEnabled ¶
IsR9KModeEnabled returns true if messages must contain more than 9 unique characters to be sent successfully
func (RoomState) IsRitualsEnabled ¶
IsRitualsEnabled returns true if users are able to signal to the chatroom that they are new to the community
func (RoomState) IsSlowModeEnabled ¶
IsSlowModeEnabled returns true if non-moderators must wait a set duration between sending messages
func (RoomState) IsSubscribersOnly ¶
IsSubscribersOnly returns true if users without VIP or moderator privileges must be subscribed to send messages
type ServerNotice ¶
ServerNotice is a message sent from the IRC server with general notices
func NewServerNotice ¶
func NewServerNotice(msg Message) ServerNotice
NewServerNotice parses a notice message sent from the IRC server
type UserNotice ¶
type UserNotice struct { IRCMessage Message Sender ChatSender ID string Message string Type string CreatedAt time.Time }
UserNotice is a generic user based event in a channels chatroom
func NewUserNotice ¶
func NewUserNotice(msg Message) UserNotice
NewUserNotice parses a generic user based event in a channels chatroom
type UserState ¶
type UserState struct { ID int64 DisplayName string Color string Badges map[string]string BadgeInfo map[string]string EmoteSets []int64 Type string }
UserState is a generic state of an authenticated user
func NewUserState ¶
NewUserState parses a generic state of an authenticated user