gotau

package module
Version: v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2021 License: MIT Imports: 8 Imported by: 0

README

Go Tau

pipeline status coverage report Go Reference Go Report Card discord

This library is designed to make integrating with TAU in go, taking care of parsing out the messages and calling the registered receivers, leaving you to handle the logic.

Callbacks

You can implement any/all of these callbacks in your own code to take advantage of this library allowing you to take care of the business logic, while this library takes care of parsing messages into usable structs.

  • RawCallback(msg []byte) - All websocket messages received will be forwarded to this callback untouched. Note this will not stop processing via more specific callbacks.
  • ErrorCallback(err error) - Used to handle websocket type errors like when the websocket is closed by the remote source, if this is not handled then errors here will cause a panic.
  • StreamOnlineCallback(msg *StreamOnlineMsg) - Called when a streamer goes online
  • StreamOfflineCallback(msg *StreamOnlineMsg) - Called when a streamer goes offline
  • FollowCallback(msg *FollowMsg) - Called when a new follow event is received.
  • StreamUpdateCallback(msg *StreamUpdateMsg) - Called when a stream update event is received.
  • CheerCallback(msg *CheerMsg) - Called when a cheer event is received.
  • RaidCallback(msg *RaidMsg) - Called when a raid event is received.
  • SubscriptionCallback(msg *SubscriptionMsg) - Called when a subscription event is received.
  • PointsRedemptionCallback(msg *PointsRedemptionMsg) - Called when a points redemption event is received. Breaking change coming in a future version based on an upcoming TAU change
  • HypeTrainBeginCallback(msg *HypeTrainBeginMsg) - Called when a hype train beginning event is received.
  • HypeTrainProgressCallback(msg *HypeTrainProgressMsg) - Called when a hype train progress event is received.
  • HypeTrainEndCallback(msg *HypeTrainEndedMsg) - Called when a hype train end event is received.

Utility Functions

  • GetAuthToken - Allows for getting your auth token via username and password. Ideally you would keep your auth token in your config, but this just gives you another option of how to get the data.
  • SetParallelProcessing - Allows you to process messages in parallel, defaults to false.
  • Reconnect - Can be used to reconnect to the websocket on a connection error via the ErrorCallback.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAuthToken added in v0.0.2

func GetAuthToken(username, password, hostname string, port int, hasSSL bool) (string, error)

GetAuthToken is used to get the auth token for a user to interact with TAU given a username and password. Ideally this would be gathered from the UI and potentially stored in a config of some sort, but this option exists in case that is not an option.

Types

type CheerCallback

type CheerCallback func(msg *CheerMsg)

CheerCallback is a callback to handle cheer events

type CheerMsg

type CheerMsg struct {
	*Event
	EventData struct {
		IsAnonymous      bool   `json:"is_anonymous"`
		UserID           string `json:"user_id"`
		UserName         string `json:"user_name"`
		UserLogin        string `json:"user_login"`
		BroadcasterID    string `json:"broadcaster_user_id"`
		BroadcasterName  string `json:"broadcaster_user_name"`
		BroadcasterLogin string `json:"broadcaster_user_login"`
		Bits             int    `json:"bits"`
		Message          string `json:"message"`
	} `json:"event_data"`
}

CheerMsg is a message that represents a cheer event that TAU sends

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents a client connected to TAU

func NewClient

func NewClient(hostname string, port int, token string, hasSSL bool) (*Client, error)

NewClient allows you to get a new client that is connected to TAU

func (*Client) Reconnect added in v0.0.3

func (c *Client) Reconnect() error

Reconnect can be used to reconnect if a connection error comes in via the ErrorCallback.

func (*Client) SendMessage

func (c *Client) SendMessage(msg interface{}) error

SendMessage Allows you to send json message to the server.

func (*Client) SetCheerCallback

func (c *Client) SetCheerCallback(callback CheerCallback)

SetCheerCallback sets a callback to be called when a cheer event is received.

func (*Client) SetErrorCallback

func (c *Client) SetErrorCallback(callback ErrorCallback)

SetErrorCallback sets a callback for the user to handle errors that might arise (like connection closed)

func (*Client) SetFollowCallback

func (c *Client) SetFollowCallback(callback FollowCallback)

SetFollowCallback sets a callback to be called on a follow event received.

func (*Client) SetHypeTrainBeginCallback

func (c *Client) SetHypeTrainBeginCallback(callback HypeTrainBeginCallback)

SetHypeTrainBeginCallback sets a callback to be called when a hype train begin event is received.

func (*Client) SetHypeTrainEndedCallback

func (c *Client) SetHypeTrainEndedCallback(callback HypeTrainEndCallback)

SetHypeTrainEndedCallback sets a callback to be called when a hype train ended event is received.

func (*Client) SetHypeTrainProgressCallback

func (c *Client) SetHypeTrainProgressCallback(callback HypeTrainProgressCallback)

SetHypeTrainProgressCallback sets a callback to be called when a hype train progress event is received.

func (*Client) SetParallelProcessing added in v0.0.3

func (c *Client) SetParallelProcessing(parallel bool)

SetParallelProcessing Allows you to enable processing events in parallel. By default this is false, and most people probably would want it to be false, but there could be cases where processing in parallel would be useful/desirable.

func (*Client) SetPointsRedemptionCallback

func (c *Client) SetPointsRedemptionCallback(callback PointsRedemptionCallback)

SetPointsRedemptionCallback sets a callback to be called when a points redemption event is received.

func (*Client) SetRaidCallback

func (c *Client) SetRaidCallback(callback RaidCallback)

SetRaidCallback sets a callback to be called when a raid event is received.

func (*Client) SetRawCallback

func (c *Client) SetRawCallback(callback RawCallback)

SetRawCallback sets a callback to be called on all received messages.

func (*Client) SetStreamOfflineCallback

func (c *Client) SetStreamOfflineCallback(callback StreamOfflineCallback)

SetStreamOfflineCallback sets a callback to be called when a stream offline event is received.

func (*Client) SetStreamOnlineCallback

func (c *Client) SetStreamOnlineCallback(callback StreamOnlineCallback)

SetStreamOnlineCallback sets a callback to be called when a stream online event is received.

func (*Client) SetStreamUpdateCallback

func (c *Client) SetStreamUpdateCallback(callback StreamUpdateCallback)

SetStreamUpdateCallback sets a callback to be called on stream update events received

func (*Client) SetSubscriptionCallback

func (c *Client) SetSubscriptionCallback(callback SubscriptionCallback)

SetSubscriptionCallback sets a callback to be called when a subscription event is received.

type ErrorCallback

type ErrorCallback func(err error)

ErrorCallback is a callback to handle websocket specific errors where the websocket likely needs to be re-established and a new client is needed.

type Event

type Event struct {
	ID          string `json:"id"`
	EventID     string `json:"event_id"`
	EventType   string `json:"event_type"`
	EventSource string `json:"event_source"`
	Created     Time   `json:"created"`
	Origin      string `json:"origin"`
}

Event is the common parts of every event coming from TAU

type FollowCallback

type FollowCallback func(msg *FollowMsg)

FollowCallback is a callback to handle follow events

type FollowMsg

type FollowMsg struct {
	*Event
	EventData struct {
		UserName         string `json:"user_name"`
		UserID           string `json:"user_id"`
		UserLogin        string `json:"user_login"`
		BroadcasterID    string `json:"broadcaster_user_id"`
		BroadcasterName  string `json:"broadcaster_user_name"`
		BroadcasterLogin string `json:"broadcaster_user_login"`
	} `json:"event_data"`
}

FollowMsg is a message representing a follow event that TAU sends

type HypeTrainBeginCallback

type HypeTrainBeginCallback func(msg *HypeTrainBeginMsg)

HypeTrainBeginCallback is a callback to handle hype train begin events

type HypeTrainBeginMsg

type HypeTrainBeginMsg struct {
	*Event
	EventData struct {
		BroadcasterID    string    `json:"broadcaster_user_id"`
		BroadcasterName  string    `json:"broadcaster_user_name"`
		BroadcasterLogin string    `json:"broadcaster_user_login"`
		Total            int       `json:"total"`
		Progress         int       `json:"progress"`
		Goal             int       `json:"goal"`
		StartedAt        time.Time `json:"started_at"`
		ExpiresAt        time.Time `json:"expires_at"`
		TopContributions []struct {
			UserID    string `json:"user_id"`
			UserLogin string `json:"user_login"`
			UserName  string `json:"user_name"`
			Type      string `json:"type"`
			Total     int    `json:"total"`
		} `json:"top_contributions"`
		LastContribution struct {
			UserID    string `json:"user_id"`
			UserLogin string `json:"user_login"`
			UserName  string `json:"user_name"`
			Type      string `json:"type"`
			Total     int    `json:"total"`
		} `json:"last_contribution"`
	} `json:"event_data"`
}

HypeTrainBeginMsg is a message that represents a hype train begin event that TAU sends

type HypeTrainEndCallback

type HypeTrainEndCallback func(msg *HypeTrainEndedMsg)

HypeTrainEndCallback is a callback to handle hype train end events

type HypeTrainEndedMsg

type HypeTrainEndedMsg struct {
	*Event
	EventData struct {
		BroadcasterID    string    `json:"broadcaster_user_id"`
		BroadcasterName  string    `json:"broadcaster_user_name"`
		BroadcasterLogin string    `json:"broadcaster_user_login"`
		Level            int       `json:"level"`
		Total            int       `json:"total"`
		Progress         int       `json:"progress"`
		StartedAt        time.Time `json:"started_at"`
		EndedAt          time.Time `json:"ended_at"`
		CooldownEndsAt   time.Time `json:"cooldown_ends_at"`
		TopContributions []struct {
			UserID    string `json:"user_id"`
			UserLogin string `json:"user_login"`
			UserName  string `json:"user_name"`
			Type      string `json:"type"`
			Total     int    `json:"total"`
		} `json:"top_contributions"`
	} `json:"event_data"`
}

HypeTrainEndedMsg is a message that represents a hype train end event that TAU sends

type HypeTrainProgressCallback

type HypeTrainProgressCallback func(msg *HypeTrainProgressMsg)

HypeTrainProgressCallback is a callback to handle hype train progress events

type HypeTrainProgressMsg

type HypeTrainProgressMsg struct {
	*Event
	EventData struct {
		BroadcasterID    string    `json:"broadcaster_user_id"`
		BroadcasterName  string    `json:"broadcaster_user_name"`
		BroadcasterLogin string    `json:"broadcaster_user_login"`
		Level            int       `json:"level"`
		Total            int       `json:"total"`
		Progress         int       `json:"progress"`
		Goal             int       `json:"goal"`
		StartedAt        time.Time `json:"started_at"`
		ExpiresAt        time.Time `json:"expires_at"`
		TopContributions []struct {
			UserID    string `json:"user_id"`
			UserLogin string `json:"user_login"`
			UserName  string `json:"user_name"`
			Type      string `json:"type"`
			Total     int    `json:"total"`
		} `json:"top_contributions"`
		LastContribution struct {
			UserID    string `json:"user_id"`
			UserLogin string `json:"user_login"`
			UserName  string `json:"user_name"`
			Type      string `json:"type"`
			Total     int    `json:"total"`
		} `json:"last_contribution"`
	} `json:"event_data"`
}

HypeTrainProgressMsg is a message that represents a hype train progress event that TAU sends

type PointsRedemptionCallback

type PointsRedemptionCallback func(msg *PointsRedemptionMsg)

PointsRedemptionCallback is a callback to handle points redemption events

type PointsRedemptionMsg

type PointsRedemptionMsg struct {
	*Event
	EventData struct {
		BroadcasterID    string    `json:"broadcaster_user_id"`
		BroadcasterName  string    `json:"broadcaster_user_name"`
		BroadcasterLogin string    `json:"broadcaster_user_login"`
		ID               string    `json:"id"`
		UserID           string    `json:"user_id"`
		UserLogin        string    `json:"user_login"`
		UserName         string    `json:"user_name"`
		UserInput        string    `json:"user_input"`
		Status           string    `json:"status"`
		RedeemedAt       time.Time `json:"redeemed_at"`
		Reward           struct {
			ID     string `json:"id"`
			Title  string `json:"title"`
			Prompt string `json:"prompt"`
			Cost   int    `json:"cost"`
		} `json:"reward"`
	} `json:"event_data"`
}

PointsRedemptionMsg is a message that represents a points redemption event that TAU sends

type RaidCallback

type RaidCallback func(msg *RaidMsg)

RaidCallback is a callback to handle raid events

type RaidMsg

type RaidMsg struct {
	*Event
	EventData struct {
		FromBroadcasterName  string `json:"from_broadcaster_user_name"`
		FromBroadcasterID    string `json:"from_broadcaster_user_id"`
		FromBroadcasterLogin string `json:"from_broadcaster_user_login"`
		ToBroadcasterName    string `json:"to_broadcaster_user_name"`
		ToBroadcasterID      string `json:"to_broadcaster_user_id"`
		ToBroadcasterLogin   string `json:"to_broadcaster_user_login"`
		Viewers              int    `json:"viewers"`
	} `json:"event_data"`
}

RaidMsg is a message that represents a raid event that TAU sends

type RawCallback

type RawCallback func(msg []byte)

RawCallback is a callback that will be called for every message that is received. Setting this callback does not prevent other callbacks from being called, though this one will be called first.

type StreamOfflineCallback

type StreamOfflineCallback func(msg *StreamOfflineMsg)

StreamOfflineCallback is a callback to handle the stream going offline event

type StreamOfflineMsg

type StreamOfflineMsg struct {
	*Event
	EventData struct {
		BroadcasterID    string `json:"broadcaster_user_id"`
		BroadcasterName  string `json:"broadcaster_user_name"`
		BroadcasterLogin string `json:"broadcaster_user_login"`
	} `json:"event_data"`
}

StreamOfflineMsg is a message that represents a stream offline event that TAU sends

type StreamOnlineCallback

type StreamOnlineCallback func(msg *StreamOnlineMsg)

StreamOnlineCallback is a callback to handle the stream coming online event

type StreamOnlineMsg

type StreamOnlineMsg struct {
	*Event
	EventData struct {
		ID               string    `json:"id"`
		BroadcasterID    string    `json:"broadcaster_user_id"`
		BroadcasterName  string    `json:"broadcaster_user_name"`
		BroadcasterLogin string    `json:"broadcaster_user_login"`
		Type             string    `json:"type"`
		StartedAt        time.Time `json:"started_at"`
	} `json:"event_data"`
}

StreamOnlineMsg is a message that represents a stream online event that TAU sends

type StreamUpdateCallback

type StreamUpdateCallback func(msg *StreamUpdateMsg)

StreamUpdateCallback is a callback to handle updates to the stream information (like title)

type StreamUpdateMsg

type StreamUpdateMsg struct {
	*Event
	EventData struct {
		Title            string `json:"title"`
		Language         string `json:"language"`
		IsMature         bool   `json:"is_mature"`
		CategoryID       int    `json:"category_id"`
		CategoryName     string `json:"category_name"`
		BroadcasterID    string `json:"broadcaster_user_id"`
		BroadcasterName  string `json:"broadcaster_user_name"`
		BroadcasterLogin string `json:"broadcaster_user_login"`
	} `json:"event_data"`
}

StreamUpdateMsg is a message that represents a stream update event that TAU sends

type SubscriptionCallback

type SubscriptionCallback func(msg *SubscriptionMsg)

SubscriptionCallback is a callback to handle subscription events

type SubscriptionMsg

type SubscriptionMsg struct {
	*Event
	EventData struct {
		Type string `json:"type"`
		Data struct {
			Topic   string `json:"topic"`
			Message struct {
				BenefitEndMonth    int       `json:"benefit_end_month"`
				UserName           string    `json:"user_name"`
				DisplayName        string    `json:"display_name"`
				ChannelName        string    `json:"channel_name"`
				UserID             string    `json:"user_id"`
				ChannelID          string    `json:"channel_id"`
				Time               time.Time `json:"time"`
				SubPlan            string    `json:"sub_plan"`
				SubPlanName        string    `json:"sub_plan_name"`
				Months             int       `json:"months"`
				CumulativeMonths   int       `json:"cumulative_months"`
				Context            string    `json:"context"`
				IsGift             bool      `json:"is_gift"`
				MultiMonthDuration int       `json:"multi_month_duration"`
				StreakMonths       int       `json:"streak_months"`
				SubMessage         struct {
					Message string `json:"message"`
					Emotes  []struct {
						Start int `json:"start"`
						End   int `json:"end"`
						ID    int `json:"id"`
					} `json:"emotes"`
				} `json:"sub_message"`
			} `json:"message"`
		} `json:"data"`
	} `json:"event_data"`
}

SubscriptionMsg is a message that represents a subscription event that TAU sends

type Time

type Time struct {
	time.Time
}

Time wraps the standard time.Time to allow for custom parsing from json

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(b []byte) error

UnmarshalJSON implemented to allow for parsing this time object from TAU

Directories

Path Synopsis
examples
Package helix handles interactions with twitch via the TAU pass through.
Package helix handles interactions with twitch via the TAU pass through.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL