适用于 twitch.tv 的 go irc 客户端
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/v4?tab=doc
package main
import (
"fmt"
"github.com/gempir/go-twitch-irc/v4"
)
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)
}
}The twitch.User and MessageType structs reflect the data Twitch provides, minus any fields that have been marked as deprecated:
…For unsupported message types, we return RawMessage:
type RawMessage struct {
Raw string
Type MessageType
RawType string
Tags map[string]string
Message string
}ParseMessage parses a raw Twitch IRC message into a User and a message object. User can be nil.
func ParseMessage(line string) (*User, interface{})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) 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) Latency() (latency time.Duration, err error)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 limiterOption modifications must be done before calling Connect on the client.
By default, the client sends along these capabilities (Tags, Commands).
These callbacks are available to pass to the client:
…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暂无开放 Issues,或尚未同步最近议题。