Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

go irc client for twitch.tv

License

NotificationsYou must be signed in to change notification settings

gempir/go-twitch-irc

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

Getting Started

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)}}

Available Data

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}

Available Methods

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

funcParseMessage(linestring) (*User,interface{})

Client Methods

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)

Options

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.

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(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) {})

Message Types

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

WHISPERPRIVMSGCLEARCHATCLEARMSGROOMSTATEUSERNOTICEUSERSTATEGLOBALUSERSTATENOTICEJOINPART

About

go irc client for twitch.tv

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp