pubsub

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2021 License: BSD-3-Clause, GPL-3.0, ISC Imports: 9 Imported by: 1

Documentation

Overview

Package pubsub provides a client used to subscribe to updates from the Twitch PubSub endpoints.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BadgeEntitlementData added in v0.2.0

type BadgeEntitlementData struct {
	NewVersion      int `json:"new_version"`
	PreviousVersion int `json:"previous_version"`
}

BadgeEntitlementData represents entitlement information inside a Bits event.

type BitsBadgeData added in v0.2.0

type BitsBadgeData struct {
}

BitsBadgeData contains information about a bits badge event.

type BitsBadgeEvent added in v0.2.0

type BitsBadgeEvent struct {
	Type string        `json:"type"`
	Data BitsBadgeData `json:"data"`
}

BitsBadgeEvent contains the type and data payload for a bits badge event.

type BitsData added in v0.2.0

type BitsData struct {
	Username         string               `json:"user_name"`
	ChannelName      string               `json:"channel_name"`
	UserID           string               `json:"user_id"`
	ChannelID        string               `json:"channel_id"`
	Time             time.Time            `json:"time"`
	ChatMessage      string               `json:"chat_message"`
	BitsUsed         int                  `json:"bits_used"`
	TotalBitsUsed    int                  `json:"total_bits_used"`
	IsAnonymous      bool                 `json:"is_anonymous"`
	Context          string               `json:"context"`
	BadgeEntitlement BadgeEntitlementData `json:"badge_entitlement"`
}

BitsData contains information about a bits event.

type BitsEvent added in v0.2.0

type BitsEvent struct {
	Data        BitsData `json:"data"`
	Version     string   `json:"version"`
	MessageType string   `json:"message_type"`
	MessageID   string   `json:"message_id"`
}

BitsEvent contains the type and data payload for a bits event.

type ChannelPointsData

type ChannelPointsData struct {
	TimeStamp  time.Time      `json:"timestamp"`
	Redemption RedemptionData `json:"redemption"`
}

ChannelPointsData contains the time the reward was redeemed and the redemption data

type ChannelPointsEvent

type ChannelPointsEvent struct {
	Type string            `json:"type"`
	Data ChannelPointsData `json:"data"`
}

ChannelPointsEvent contains the type and data payload for a channel points event

type ChatModActionsData added in v0.2.0

type ChatModActionsData struct {
	Type             string   `json:"type"`
	ModerationAction string   `json:"moderation_action"`
	Args             []string `json:"args"`
	CreatedBy        string   `json:"created_by"`
	CreatedByUserID  string   `json:"created_by_user_id"`
	MsgID            string   `json:"msg_id"`
	TargetUserID     string   `json:"target_user_id"`
	TargetUserLogin  string   `json:"target_user_login"`
	FromAutomod      bool     `json:"from_automod"`
}

ChatModActionsData contains the data from a Chat Mod Action event

type ChatModActionsEvent

type ChatModActionsEvent struct {
	Data ChatModActionsData `json:"data"`
}

ChatModActionsEvent contains data payload for a mod action event

type Client

type Client struct {
	AuthToken *oauth2.Token
	ID        string
	// contains filtered or unexported fields
}

Client represents a connection and its state to the Twitch pubsub endpoint.

func NewClient

func NewClient(userID string, userToken *oauth2.Token) *Client

NewClient returns a new Client to communicate with the PubSub endpoints.

func (*Client) Close

func (c *Client) Close() error

Close disconnects the client from the Twitch PubSub endpoint. If the client is already connected, Close() will return an error.

func (*Client) Connect

func (c *Client) Connect() error

Connect to the Twitch PubSub endpoint and listen on all registered topics. Will automatically reconnect on failure. with exponential backoff. Returns an error if the client is already connected. Users of Client can call a Listen method for any topic at any time. If the Client is not connected, all topics listened on will be subscribed on connection. If the Client is connected, the topic will be subscribed on immediately.

func (*Client) IsConnected

func (c *Client) IsConnected() bool

IsConnected is a thread-safe check of whether or not the Client is connected.

func (*Client) ListenBits added in v0.2.0

func (c *Client) ListenBits(handler func(*BitsData))

ListenBits subscribes a handler function to the Bits event topic with the provided id. The handler will be called with a populated BitsData struct when the event is received.

func (*Client) ListenBitsBadge added in v0.2.0

func (c *Client) ListenBitsBadge(handler func(*BitsBadgeData))

ListenBitsBadge subscribes a handler function to the Bits badge event topic with the provided id. The handler will be called with a populated BitsBadgeData struct when the event is received.

func (*Client) ListenChannelPoints

func (c *Client) ListenChannelPoints(handler func(*ChannelPointsData))

ListenChannelPoints subscribes a handler function to the Channel Points topic with the provided id. The handler will be called with a populated ChannelPointsData struct when the event is received.

func (*Client) ListenChatModActions

func (c *Client) ListenChatModActions(handler func(*ChatModActionsData))

ListenChatModActions subscribes a handler function to the Chat Mod Actions topic with the provided id. The handler will be called with a populated ChatModActionsData struct when the event is received.

func (*Client) ListenSubs added in v0.2.0

func (c *Client) ListenSubs(handler func(*SubsData))

ListenSubs subscribes a handler function to the Subscriptions topic with the provided id. The handler will be called with a populated SubsData struct when the event is received.

func (*Client) ListenWhispers

func (c *Client) ListenWhispers(handler func(*WhispersData))

ListenWhispers subscribes a handler function to the Whispers topic with the provided id. The handler will be called with a populated WhispersData struct when the event is received.

func (*Client) UnlistenBits added in v0.2.0

func (c *Client) UnlistenBits()

UnlistenBits removes the current handler function from the Bits event topic and unlistens from the topic.

func (*Client) UnlistenBitsBadge added in v0.2.0

func (c *Client) UnlistenBitsBadge()

UnlistenBitsBadge removes the current handler function from the Bits badge event topic and unlistens from the topic.

func (*Client) UnlistenChannelPoints added in v0.2.0

func (c *Client) UnlistenChannelPoints()

UnlistenChannelPoints removes the current handler function from the channel points event topic and unlistens from the topic.

func (*Client) UnlistenChatModActions added in v0.2.0

func (c *Client) UnlistenChatModActions()

UnlistenChatModActions removes the current handler function from the Chat Mod Actions event topic and unlistens from the topic.

func (*Client) UnlistenSubs added in v0.2.0

func (c *Client) UnlistenSubs()

UnlistenSubs removes the current handler function from the Subscriptions event topic and unlistens from the topic.

func (*Client) UnlistenWhispers added in v0.2.0

func (c *Client) UnlistenWhispers()

UnlistenWhispers removes the current handler function from the Whispers event topic and unlistens from the topic.

type RedemptionData

type RedemptionData struct {
	ID         string           `json:"id"`
	User       RedemptionUser   `json:"user"`
	ChannelID  string           `json:"channel_id"`
	RedeemedAt time.Time        `json:"redeemed_at"`
	Reward     RedemptionReward `json:"reward"`
	UserInput  string           `json:"user_input"`
	Status     string           `json:"status"`
}

RedemptionData contains metadata about the redeemed reward

type RedemptionImage

type RedemptionImage struct {
	URL1x string `json:"url_1x"`
	URL2x string `json:"url_2x"`
	URL4x string `json:"url_4x"`
}

RedemptionImage represents the cute image used on the redemption button

type RedemptionMaxPerStream

type RedemptionMaxPerStream struct {
	IsEnabled    bool `json:"is_enabled"`
	MaxPerStream int  `json:"max_per_stream"`
}

RedemptionMaxPerStream represents information about redemption limits per stream

type RedemptionReward

type RedemptionReward struct {
	ID                    string                 `json:"id"`
	ChannelID             string                 `json:"channel_id"`
	Title                 string                 `json:"title"`
	Prompt                string                 `json:"prompt"`
	Cost                  int                    `json:"cost"`
	IsUserInputRequired   bool                   `json:"is_user_input_required"`
	IsSubOnly             bool                   `json:"is_sub_only"`
	Image                 RedemptionImage        `json:"image"`
	DefaultImage          RedemptionImage        `json:"default_image"`
	BackgroundColor       string                 `json:"background_color"`
	IsEnabled             bool                   `json:"is_enabled"`
	IsPaused              bool                   `json:"is_paused"`
	IsInStock             bool                   `json:"is_in_stock"`
	MaxPerStream          RedemptionMaxPerStream `json:"max_per_stream"`
	ShouldRedemptionsSkip bool                   `json:"should_redemptions_skip_request_queue"`
	TemplateID            string                 `json:"template_id"`
	UpdatedForIndicatorAt time.Time              `json:"updated_for_indicator_at"`
}

RedemptionReward represents information about the reward redeemed

type RedemptionUser

type RedemptionUser struct {
	ID          string `json:"id"`
	Login       string `json:"login"`
	DisplayName string `json:"display_name"`
}

RedemptionUser represents the user who redeemed the reward

type SubMessageData added in v0.2.0

type SubMessageData struct {
	Message string  `json:"message"`
	Emotes  *string `json:"emotes"`
}

SubMessageData represents data in a sub message.

type SubsData added in v0.2.0

type SubsData 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"`
	RecipientID          string         `json:"recipient_id"`
	RecipientUsername    string         `json:"recipient_user_name"`
	RecipientDisplayName string         `json:"recipient_display_name"`
	Time                 time.Time      `json:"time"`
	SubMessage           SubMessageData `json:"sub_message"`
	SubPlan              string         `json:"sub_plan"`
	SubPlanName          string         `json:"sub_plan_name"`
	Months               int            `json:"months"`
	Context              string         `json:"context"`
	IsGift               bool           `json:"is_gift"`
	MultiMonthDuration   int            `json:"multi_month_duration"`
}

SubsData contains the type and data payload for a subscription event.

type WhispersBadges

type WhispersBadges struct {
	ID      string `json:"id"`
	Version string `json:"version"`
}

WhispersBadges represents the badges shown by the sender of the whisper

type WhispersData

type WhispersData struct {
	ID        int               `json:"id"`
	MessageID string            `json:"message_id"`
	ThreadID  string            `json:"thread_id"`
	Body      string            `json:"body"`
	SentTs    int               `json:"sent_ts"`
	FromID    int               `json:"from_id"`
	Tags      WhispersTags      `json:"tags"`
	Recipient WhispersRecipient `json:"recipient"`
	Nonce     string            `json:"nonce"`
}

WhispersData contains information about a whisper

type WhispersEvent

type WhispersEvent struct {
	Type string       `json:"type"`
	Data WhispersData `json:"data"`
}

WhispersEvent contains the type and data payload for a mod action event

type WhispersRecipient

type WhispersRecipient struct {
	ID           int     `json:"id"`
	Username     string  `json:"username"`
	DisplayName  string  `json:"display_name"`
	Color        string  `json:"color"`
	ProfileImage *string `json:"profile_image"`
}

WhispersRecipient represents the recipient of the whisper

type WhispersTags

type WhispersTags struct {
	Login       string           `json:"login"`
	DisplayName string           `json:"display_name"`
	Color       string           `json:"color"`
	Emotes      []string         `json:"emotes"`
	Badges      []WhispersBadges `json:"badges"`
}

WhispersTags represents information about the sender of the whisper

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL