• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

cmd/pingpong/H15-Jan-2020-3324

test_resources/H03-May-2022-455448

.gitattributesH A D15-Jan-2020100 65

.gitignoreH A D15-Jan-202089 128

.travis.ymlH A D15-Jan-2020268 1311

LICENSEH A D15-Jan-20201 KiB2217

MakefileH A D15-Jan-2020169 107

README.MDH A D15-Jan-20205.2 KiB239199

client.goH A D15-Jan-202026.3 KiB1,090771

client_test.goH A D15-Jan-202043.4 KiB1,7801,362

go.modH A D15-Jan-202042 21

helpers_test.goH A D15-Jan-20202.9 KiB12399

irc.goH A D15-Jan-20202.8 KiB151112

irc_test.goH A D15-Jan-20203.1 KiB11190

message.goH A D15-Jan-202012.7 KiB495365

message_benchmark_test.goH A D15-Jan-20201.3 KiB6856

message_test.goH A D15-Jan-202022.5 KiB523402

run-test-tests.shH A D15-Jan-2020255 178

README.MD

1# go-twitch-irc [![Build Status](https://travis-ci.org/gempir/go-twitch-irc.svg?branch=master)](https://travis-ci.org/gempir/go-twitch-irc) [![Coverage Status](https://coveralls.io/repos/github/gempir/go-twitch-irc/badge.svg?branch=master)](https://coveralls.io/github/gempir/go-twitch-irc?branch=master)
2
3This is an irc client for connecting to twitch. It handles the annoying stuff like irc tag parsing.
4I highly recommend reading the godoc below, but this readme gives a basic overview of the functionality.
5
6godoc: https://godoc.org/github.com/gempir/go-twitch-irc
7
8## Getting Started
9```go
10package main
11
12import (
13	"fmt"
14
15	"github.com/gempir/go-twitch-irc"
16)
17
18func main() {
19	client := twitch.NewClient("justinfan123123", "oauth:123123123")
20
21	client.OnPrivateMessage(func(message twitch.PrivateMessage) {
22		fmt.Println(message.Message)
23	})
24
25	client.Join("gempir")
26
27	err := client.Connect()
28	if err != nil {
29		panic(err)
30	}
31}
32```
33### Available Data
34
35The twitch.User and MessageType structs reflect the data Twitch provides, minus any fields that have been marked as deprecated:
36```go
37type User struct {
38	ID          string
39	Name        string
40	DisplayName string
41	Color       string
42	Badges      map[string]int
43}
44
45type WhisperMessage struct {
46	User User
47
48	Raw       string
49	Type      MessageType
50	RawType   string
51	Tags      map[string]string
52	Message   string
53	Target    string
54	MessageID string
55	ThreadID  string
56	Emotes    []*Emote
57	Action    bool
58}
59
60type PrivateMessage struct {
61	User User
62
63	Raw     string
64	Type    MessageType
65	RawType string
66	Tags    map[string]string
67	Message string
68	Channel string
69	RoomID  string
70	ID      string
71	Time    time.Time
72	Emotes  []*Emote
73	Bits    int
74	Action  bool
75}
76
77type ClearChatMessage struct {
78	Raw            string
79	Type           MessageType
80	RawType        string
81	Tags           map[string]string
82	Message        string
83	Channel        string
84	RoomID         string
85	Time           time.Time
86	BanDuration    int
87	TargetUserID   string
88	TargetUsername string
89}
90
91type ClearMessage struct {
92	Raw         string
93	Type        MessageType
94	RawType     string
95	Tags        map[string]string
96	Message     string
97	Channel     string
98	Login       string
99	TargetMsgID string
100}
101
102type RoomStateMessage struct {
103	Raw     string
104	Type    MessageType
105	RawType string
106	Tags    map[string]string
107	Message string
108	Channel string
109	RoomID  string
110	State   map[string]int
111}
112
113type UserNoticeMessage struct {
114	User User
115
116	Raw       string
117	Type      MessageType
118	RawType   string
119	Tags      map[string]string
120	Message   string
121	Channel   string
122	RoomID    string
123	ID        string
124	Time      time.Time
125	Emotes    []*Emote
126	MsgID     string
127	MsgParams map[string]string
128	SystemMsg string
129}
130
131type UserStateMessage struct {
132	User User
133
134	Raw       string
135	Type      MessageType
136	RawType   string
137	Tags      map[string]string
138	Message   string
139	Channel   string
140	EmoteSets []string
141}
142
143type NoticeMessage struct {
144	Raw     string
145	Type    MessageType
146	RawType string
147	Tags    map[string]string
148	Message string
149	Channel string
150	MsgID   string
151}
152
153type UserJoinMessage struct {
154	// Channel name
155	Channel string
156
157	// User name
158	User string
159}
160
161type UserPartMessage struct {
162	// Channel name
163	Channel string
164
165	// User name
166	User string
167}
168```
169
170For unsupported message types, we return RawMessage:
171```go
172type RawMessage struct {
173	Raw     string
174	Type    MessageType
175	RawType string
176	Tags    map[string]string
177	Message string
178}
179```
180
181### Available Methods
182
183ParseMessage parses a raw Twitch IRC message into a User and a message object. User can be nil.
184
185	func ParseMessage(line string) (*User, interface{})
186
187### Client Methods
188
189These are the available methods of the client so you can get your bot going:
190
191	func (c *Client) Say(channel, text string)
192	func (c *Client) Whisper(username, text string)
193	func (c *Client) Join(channel string)
194	func (c *Client) Depart(channel string)
195	func (c *Client) Userlist(channel string) ([]string, error)
196	func (c *Client) Connect() error
197	func (c *Client) Disconnect() error
198
199### Options
200
201On your client you can configure multiple options:
202```go
203client.IrcAddress = "127.0.0.1:3030" // for custom irc server
204client.TLS = false // enabled by default, will connect to non TLS server of twitch when off or the given client.IrcAddress
205client.SetupCmd = "LOGIN custom_command_here" // Send a custom command on successful IRC connection, before authentication.
206```
207### Callbacks
208
209These callbacks are available to pass to the client:
210```go
211client.OnConnect(func() {})
212client.OnPrivateMessage(func(message PrivateMessage) {})
213client.OnWhisperMessage(func(message WhisperMessage) {})
214client.OnClearChatMessage(func(message ClearChatMessage) {})
215client.OnClearMessage(func message ClearMessage) {})
216client.OnRoomStateMessage(func(message RoomStateMessage) {})
217client.OnUsernoticeMessage(func(message UserNoticeMessage) {})
218client.OnUserstateMessage(func(message UserStateMessage) {})
219client.OnNoticeMessage(func(message NoticeMessage) {})
220client.OnUserJoinMessage(func(message UserJoinMessage) {})
221client.OnUserPartMessage(func(message UserPartMessage) {})
222```
223
224### Message Types
225
226If you ever need more than basic PRIVMSG, this might be for you.
227These are the 7 major message types currently supported:
228
229    WHISPER
230    PRIVMSG
231    CLEARCHAT
232    CLEARMSG
233    ROOMSTATE
234    USERNOTICE
235    USERSTATE
236    NOTICE
237    JOIN
238    PART
239