Documentation
¶
Index ¶
- Constants
- Variables
- func AlternateUsers() map[string]string
- func Bots() map[string]struct{}
- func IsBot(user string) bool
- func TrimBots(users *sync.Map)
- type ListenMessage
- type ListenTopic
- type Twitch
- func (t *Twitch) Clip() (string, error)
- func (t *Twitch) Close() error
- func (t *Twitch) Farewell(channelName string, user string)
- func (t *Twitch) GetAllStreamInfoForUsers(usernames ...string) (map[string]TwitchStreamInfo, int, error)
- func (t *Twitch) GetAuthTokens(ctx context.Context, channelID, channelName string) (err error)
- func (t *Twitch) GetChannelInfo(userInfo *TwitchUserInfo) (*TwitchChannelInfo, error)
- func (t *Twitch) GetClips(userInfo *TwitchUserInfo) ([]*TwithcClipInfo, error)
- func (t *Twitch) GetUserInfo(login string) (*TwitchUserInfo, error)
- func (t *Twitch) IFollowThem(theirID string) (bool, error)
- func (t *Twitch) Open(ctx context.Context) error
- func (t *Twitch) Pong(msg TwitchMessage) error
- func (t *Twitch) ReceiveOneMessage() (msg TwitchMessage, err error)
- func (t *Twitch) Reconnect(ctx context.Context, channelID, channelName string) error
- func (t *Twitch) SendMessage(channelName, msg string) (err error)
- func (t *Twitch) Shoutout(channelName string, user string, manual bool)
- func (t *Twitch) StartPubSubEventHandler(ctx context.Context, wg *sync.WaitGroup, ...)
- func (t *Twitch) SuperShoutOut(channelName string, user string, manual bool) []*TwithcClipInfo
- type TwitchChannelInfo
- type TwitchEventMessage
- type TwitchMessage
- func (c TwitchMessage) AtUser() string
- func (c TwitchMessage) Body() string
- func (c TwitchMessage) CleanUserFromArgs() string
- func (c TwitchMessage) DisplayName() string
- func (c TwitchMessage) GetBotCommand() string
- func (c TwitchMessage) GetBotCommandArgs() string
- func (c TwitchMessage) GoString() string
- func (c TwitchMessage) IsBotCommand() bool
- func (c TwitchMessage) IsMod() bool
- func (c TwitchMessage) IsOwner() bool
- func (c TwitchMessage) IsSub() bool
- func (c TwitchMessage) IsVIP() bool
- func (c *TwitchMessage) Parse(b []byte) error
- func (c TwitchMessage) Raw() string
- func (c TwitchMessage) String() string
- func (c TwitchMessage) Type() int
- func (c TwitchMessage) User() string
- func (c TwitchMessage) Users() map[string]string
- type TwitchPointRedemption
- type TwitchPubSubMessage
- type TwitchStreamInfo
- type TwitchUserInfo
- type TwithcClipInfo
Constants ¶
const ( // UnknownType of message UnknownType = iota // PrivateMessage is a standard chat PrivateMessage // JoinMessage is something related to who is in the channel? JoinMessage // PingMessage is the Ping request from the server PingMessage // PartMessage is something related to Join? PartMessage // UserStateMessage is something we get at our join? UserStateMessage // RoomStateMessage tells us about the rules of the room RoomStateMessage // GlobalUserState ??? GlobalUserState // Capacity ?? Capacity // Authentication response Authentication // AuthenticationFail response AuthenticationFail )
Variables ¶
var ( // ErrAuthFailed is returned if the twitch authetication process returns an error ErrAuthFailed = fmt.Errorf("failed to authenticate") // ErrNoChannel must provide a channel to join ErrNoChannel = fmt.Errorf("no channel provided") // ErrNoConnection connection was not established ErrNoConnection = fmt.Errorf("no connection") // TwitchCharacterLimit is the maximum message size TwitchCharacterLimit = 500 )
var ErrInvalidMsg = fmt.Errorf("invalid message, did not parse")
ErrInvalidMsg the message didn't parse
Functions ¶
func AlternateUsers ¶
AlternateUsers for a given twitch user (eg a watching account separate from the broadcasting one)
Types ¶
type ListenMessage ¶
type ListenMessage struct { Type string `json:"type"` Nonce string `json:"nonce,omitempty"` Data ListenTopic `json:"data"` }
ListenMessage subscribes to a pubsub topic
type ListenTopic ¶
ListenTopic describes a pubsub listen topic
type Twitch ¶
Twitch talks to twitch
func NewTwitch ¶
func NewTwitch(cfg *config.Configuration) (*Twitch, error)
NewTwitch chat interface
func (*Twitch) Clip ¶
Clip the latest few seconds nightbot : $(urlfetch https://m7tthg2fz8.execute-api.us-east-1.amazonaws.com/?cmd=clip)
func (*Twitch) GetAllStreamInfoForUsers ¶
func (t *Twitch) GetAllStreamInfoForUsers(usernames ...string) (map[string]TwitchStreamInfo, int, error)
GetAllStreamInfoForUsers will give the stream info for the given channel names curl -X GET 'https://api.twitch.tv/helix/streams' https://dev.twitch.tv/docs/api/reference/#get-streams
func (*Twitch) GetAuthTokens ¶
GetAuthTokens will try very hard to get the authentication tokens
func (*Twitch) GetChannelInfo ¶
func (t *Twitch) GetChannelInfo(userInfo *TwitchUserInfo) (*TwitchChannelInfo, error)
GetChannelInfo gets channel information
func (*Twitch) GetClips ¶
func (t *Twitch) GetClips(userInfo *TwitchUserInfo) ([]*TwithcClipInfo, error)
GetClips gets the channel clips
func (*Twitch) GetUserInfo ¶
func (t *Twitch) GetUserInfo(login string) (*TwitchUserInfo, error)
GetUserInfo gets the information on a user by login
func (*Twitch) IFollowThem ¶
IFollowThem checks if a channel is followed by the channel running the bot, used by auto-shoutout https://dev.twitch.tv/docs/api/reference/#get-followed-channels
func (*Twitch) ReceiveOneMessage ¶
func (t *Twitch) ReceiveOneMessage() (msg TwitchMessage, err error)
ReceiveOneMessage waits for a message to be posted to chat
func (*Twitch) SendMessage ¶
SendMessage to a channel TODO: elipsis/fmt args pls
func (*Twitch) StartPubSubEventHandler ¶
func (t *Twitch) StartPubSubEventHandler(ctx context.Context, wg *sync.WaitGroup, redemptionHandlers map[string]func(context.Context, TwitchPointRedemption), )
StartPubSubEventHandler is the event loop for twitch pub-sub
func (*Twitch) SuperShoutOut ¶
func (t *Twitch) SuperShoutOut(channelName string, user string, manual bool) []*TwithcClipInfo
SuperShoutOut grabs clips
type TwitchChannelInfo ¶
type TwitchChannelInfo struct { BroadcasterID string `json:"broadcaster_id"` BroadcasterLogin string `json:"broadcaster_login"` BroadcasterName string `json:"broadcaster_name"` BroadcasterLanguage string `json:"broadcaster_language"` GameID string `json:"game_id"` GameName string `json:"game_name"` IsLive bool `json:"is_live"` Title string `json:"title"` Delay int `json:"delay"` Taghs []string `json:"tags"` ContentClassificatinLables []string `json:"content_classification_labels"` ISBrandedContent bool `json:"is_branded_content"` }
TwitchChannelInfo contains the information about a channel
type TwitchEventMessage ¶
type TwitchEventMessage struct { Type string `json:"type"` Data map[string]interface{} `json:"data"` }
TwitchEventMessage from the pubsub
type TwitchMessage ¶
type TwitchMessage struct {
// contains filtered or unexported fields
}
TwitchMessage wrapper for parsing and providing info on individual chat messages
func FakeTwitchMessage ¶
func FakeTwitchMessage(body string) TwitchMessage
FakeTwitchMessage for timers/etc
func (TwitchMessage) AtUser ¶
func (c TwitchMessage) AtUser() string
AtUser is the user in a format that twitch likes with an @ sign
func (TwitchMessage) CleanUserFromArgs ¶
func (c TwitchMessage) CleanUserFromArgs() string
CleanUserFromArgs or just the user who sent it
func (TwitchMessage) DisplayName ¶
func (c TwitchMessage) DisplayName() string
DisplayName of the user who sent the message
func (TwitchMessage) GetBotCommand ¶
func (c TwitchMessage) GetBotCommand() string
GetBotCommand gets the command passed if IsBotCommand
func (TwitchMessage) GetBotCommandArgs ¶
func (c TwitchMessage) GetBotCommandArgs() string
GetBotCommandArgs returns any arguments passed to the command as a single string
func (TwitchMessage) IsBotCommand ¶
func (c TwitchMessage) IsBotCommand() bool
IsBotCommand will say if a chat message should be interpreted as a bot command
func (TwitchMessage) IsOwner ¶
func (c TwitchMessage) IsOwner() bool
IsOwner is the channel owner/broadcaster
func (*TwitchMessage) Parse ¶
func (c *TwitchMessage) Parse(b []byte) error
Parse message from the websocket read
func (TwitchMessage) Raw ¶
func (c TwitchMessage) Raw() string
Raw message contents with headers/etc
func (TwitchMessage) Users ¶
func (c TwitchMessage) Users() map[string]string
Users found in Join/Part messages
type TwitchPointRedemption ¶
type TwitchPointRedemption struct { Timestamp time.Time `json:"timestamp"` Redemption struct { ID string `json:"id"` User struct { ID string `json:"id"` Login string `json:"login"` DisplayName string `json:"display_name"` } `json:"user"` ChannelID string `json:"channel_id"` RedeemedAt time.Time `json:"redeemed_at"` Reward struct { ID string `json:"id"` ChannelID string `json:"channel_id"` Title string `json:"title"` } `json:"reward"` UserInput string `json:"user_input"` Status string `json:"status"` } `json:"redemption"` }
TwitchPointRedemption from the pubsub
type TwitchPubSubMessage ¶
type TwitchPubSubMessage struct { Type string `json:"type"` Data map[string]interface{} `json:"data,omitempty"` }
TwitchPubSubMessage is a parsed message from twitch event pub/sub
type TwitchStreamInfo ¶
type TwitchStreamInfo struct { ID string `json:"id"` UserID string `json:"user_id"` UserLogin string `json:"user_login"` UserName string `json:"user_name"` GameID string `json:"game_id"` GameName string `json:"game_name"` Type string `json:"type"` // "live" Title string `json:"title"` Tags []string `json:"tags"` ViewerCount int `json:"viewer_count"` StartedAt time.Time `json:"started_at"` Language string `json:"language"` ThumbnailURL string `json:"thumbnail_url"` TagIDs []string `json:"tag_ids"` IsMature bool `json:"is_mature"` }
TwitchStreamInfo contains info that twitch api provides on live streams
type TwitchUserInfo ¶
type TwitchUserInfo struct { ID string `json:"id"` Login string `json:"login"` DisplayName string `json:"display_name"` Type string `json:"type"` BroadcasterType string `json:"broadcaster_type"` Description string `json:"description"` ProfileImageURL string `json:"profile_image_url"` OffilneImageURL string `json:"offline_image_url"` ViewCount int `json:"view_count"` Email string `json:"email"` CreatedAt time.Time `json:"created_at"` }
TwitchUserInfo response from GetUser https://dev.twitch.tv/docs/api/reference/#get-users
type TwithcClipInfo ¶
type TwithcClipInfo struct { ID string `json:"id"` // : "AwkwardHelplessSalamanderSwiftRage", URL string `json:"url"` // : "https://clips.twitch.tv/AwkwardHelplessSalamanderSwiftRage", EmbeddURL string `json:"embed_url"` // : "https://clips.twitch.tv/embed?clip=AwkwardHelplessSalamanderSwiftRage", // "broadcaster_id": "67955580", // "broadcaster_name": "ChewieMelodies", // "creator_id": "53834192", // "creator_name": "BlackNova03", // "video_id": "205586603", // "game_id": "488191", // "language": "en", Title string `json:"title"` // "title": "babymetal", ViewCount int `json:"view_count"` // : 10, CreatedAt time.Time `json:"created_at"` // : "2017-11-30T22:34:18Z", ThumbnailURL string `json:"thumbnail_url"` //: "https://clips-media-assets.twitch.tv/157589949-preview-480x272.jpg", Duration float64 `json:"duration"` //: 28.3 }
TwithcClipInfo get clip response