- Notifications
You must be signed in to change notification settings - Fork59
go irc client for twitch.tv
License
gempir/go-twitch-irc
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
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 mainimport ("fmt""github.com/gempir/go-twitch-irc/v4")funcmain() {// 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()iferr!=nil {panic(err)}}
The twitch.User and MessageType structs reflect the data Twitch provides, minus any fields that have been marked as deprecated:
typeUserstruct {IDstringNamestringDisplayNamestringColorstringBadgesmap[string]intIsBroadcasterboolIsModboolIsVipbool}typeWhisperMessagestruct {UserUserRawstringTypeMessageTypeRawTypestringTagsmap[string]stringMessagestringTargetstringMessageIDstringThreadIDstringEmotes []*EmoteActionbool}typePrivateMessagestruct {UserUserRawstringTypeMessageTypeRawTypestringTagsmap[string]stringMessagestringChannelstringRoomIDstringIDstringTime time.TimeEmotes []*EmoteBitsintActionbool}typeClearChatMessagestruct {RawstringTypeMessageTypeRawTypestringTagsmap[string]stringMessagestringChannelstringRoomIDstringTime time.TimeBanDurationintTargetUserIDstringTargetUsernamestring}typeClearMessagestruct {RawstringTypeMessageTypeRawTypestringTagsmap[string]stringMessagestringChannelstringLoginstringTargetMsgIDstring}typeRoomStateMessagestruct {RawstringTypeMessageTypeRawTypestringTagsmap[string]stringMessagestringChannelstringRoomIDstringStatemap[string]int}typeUserNoticeMessagestruct {UserUserRawstringTypeMessageTypeRawTypestringTagsmap[string]stringMessagestringChannelstringRoomIDstringIDstringTime time.TimeEmotes []*EmoteMsgIDstringMsgParamsmap[string]stringSystemMsgstring}typeUserStateMessagestruct {UserUserRawstringTypeMessageTypeRawTypestringTagsmap[string]stringMessagestringChannelstringEmoteSets []string}typeGlobalUserStateMessagestruct {UserUserRawstringTypeMessageTypeRawTypestringTagsmap[string]stringEmoteSets []string}typeNoticeMessagestruct {RawstringTypeMessageTypeRawTypestringTagsmap[string]stringMessagestringChannelstringMsgIDstring}typeUserJoinMessagestruct {// Channel nameChannelstring// User nameUserstring}typeUserPartMessagestruct {// Channel nameChannelstring// User nameUserstring}
For unsupported message types, we return RawMessage:
typeRawMessagestruct {RawstringTypeMessageTypeRawTypestringTagsmap[string]stringMessagestring}
ParseMessage parses a raw Twitch IRC message into a User and a message object. User can be nil.
funcParseMessage(linestring) (*User,interface{})
These are the available methods of the client so you can get your bot going:
func (c*Client)Say(channel,textstring)func (c*Client)Join(channelstring)func (c*Client)Depart(channelstring)func (c*Client)Userlist(channelstring) ([]string,error)func (c*Client)Connect()errorfunc (c*Client)Disconnect()errorfunc (c*Client)Latency() (latency time.Duration,errerror)
On your client you can configure multiple options:
client.IrcAddress="127.0.0.1:3030"// for custom irc serverclient.TLS=false// enabled by default, will connect to non TLS server of twitch when off or the given client.IrcAddressclient.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 sentclient.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.
By default, the client sends along these capabilities (Tags,Commands).
These callbacks are available to pass to the client:
client.OnConnect(func() {})client.OnPrivateMessage(func(messagePrivateMessage) {})client.OnWhisperMessage(func(messageWhisperMessage) {})client.OnClearChatMessage(func(messageClearChatMessage) {})client.OnClearMessage(func(messageClearMessage) {})client.OnRoomStateMessage(func(messageRoomStateMessage) {})client.OnUserNoticeMessage(func(messageUserNoticeMessage) {})client.OnUserStateMessage(func(messageUserStateMessage) {})client.OnGlobalUserStateMessage(func(messageGlobalUserStateMessage) {})client.OnNoticeMessage(func(messageNoticeMessage) {})client.OnUserJoinMessage(func(messageUserJoinMessage) {})client.OnUserPartMessage(func(messageUserPartMessage) {})client.OnSelfJoinMessage(func(messageUserJoinMessage) {})client.OnSelfPartMessage(func(messageUserPartMessage) {})
If you ever need more than basic PRIVMSG, this might be for you.These are the message types currently supported:
WHISPERPRIVMSGCLEARCHATCLEARMSGROOMSTATEUSERNOTICEUSERSTATEGLOBALUSERSTATENOTICEJOINPARTAbout
go irc client for twitch.tv
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.