Documentation ¶
Index ¶
- Constants
- Variables
- func BitsEventTopic(channelID string) string
- func ModerationActionTopic(userID, channelID string) string
- func PointsActionTopic(channelID string) string
- func PointsEventTopic(channelID string) string
- type Base
- type BaseData
- type BitsEvent
- type Client
- func (c *Client) Disconnect()
- func (c *Client) Listen(topicName string, authToken string)
- func (c *Client) OnBitsEvent(callback func(channelID string, data *BitsEvent))
- func (c *Client) OnModerationAction(callback func(channelID string, data *ModerationAction))
- func (c *Client) OnPointsAction(callback func(channelID string, data *PointsAction))
- func (c *Client) OnPointsEvent(callback func(channelID string, data *PointsEvent))
- func (c *Client) SetConnectionLimit(connectionLimit int)
- func (c *Client) SetTopicLimit(topicLimit int)
- func (c *Client) Start() error
- type InnerData
- type Listen
- type ListenData
- type Message
- type ModerationAction
- type PointsAction
- type PointsEvent
- type ResponseMessage
Constants ¶
const (
TypeListen = "LISTEN"
)
Variables ¶
var ( // ErrNotConnected is returned if an action is attempted to be performed on a Client when it is not connected ErrNotConnected = errors.New("go-twitch-pubsub: Not connected") // ErrDisconnectedByUser is returned from Connect after the user calls Disconnect() ErrDisconnectedByUser = errors.New("go-twitch-pubsub: Disconnected by user") // DefaultHost is the default host to connect to Twitch's pubsub servers DefaultHost = "wss://pubsub-edge.twitch.tv" )
Functions ¶
func BitsEventTopic ¶
BitsEventTopic returns a properly formatted bits event topic string with the given channel ID argument
func ModerationActionTopic ¶
ModerationActionTopic returns a properly formatted moderation action topic string with the given user and channel ID arguments
func PointsActionTopic ¶
ModerationActionTopic returns a properly formatted moderation action topic string with the given user and channel ID arguments
func PointsEventTopic ¶
BitsEventTopic returns a properly formatted bits event topic string with the given channel ID argument
Types ¶
type BaseData ¶
type BaseData struct { Topic string `json:"topic"` // Message is an escaped json string Message string `json:"message"` }
BaseData TODO: Refactor
type BitsEvent ¶
type BitsEvent 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"` Context string `json:"context"` BadgeEntitlement struct { NewVersion int `json:"new_version"` PreviousVersion int `json:"previous_version"` } `json:"badge_entitlement"` }
BitsEvent describes an incoming "Bit" action coming from Twitch's PubSub servers
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the client that connects to Twitch's pubsub servers
func (*Client) Disconnect ¶
func (c *Client) Disconnect()
Disconnect disconnects from Twitch's pubsub servers and leave the client in an idle state
func (*Client) Listen ¶
Listen sends a message to Twitch's pubsub servers telling them we're interested in a specific topic Some topics require authentication, and for those you will need to pass a valid authentication token
func (*Client) OnBitsEvent ¶
OnBitsEvent attaches the given callback to the bits event
func (*Client) OnModerationAction ¶
func (c *Client) OnModerationAction(callback func(channelID string, data *ModerationAction))
OnModerationAction attaches the given callback to the moderation action event
func (*Client) OnPointsAction ¶
func (c *Client) OnPointsAction(callback func(channelID string, data *PointsAction))
func (*Client) OnPointsEvent ¶
func (c *Client) OnPointsEvent(callback func(channelID string, data *PointsEvent))
func (*Client) SetConnectionLimit ¶
func (*Client) SetTopicLimit ¶
type InnerData ¶
type InnerData struct { Data json.RawMessage `json:"data"` Version string `json:"version"` MessageType string `json:"message_type"` MessageID string `json:"message_id"` }
InnerData TODO: Refactor
type Listen ¶
type Listen struct { Base Nonce string `json:"nonce,omitempty"` Data ListenData `json:"data"` }
type ListenData ¶
type ModerationAction ¶
type ModerationAction struct { Type string `json:"type"` ModerationAction string `json:"moderation_action"` Arguments []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"` }
ModerationAction describes an incoming "Moderation" action coming from Twitch's PubSub servers
type PointsAction ¶
type PointsAction struct { Timestamp time.Time `json:"timestamp"` Redemption string `json:"redemption"` User_input string `json:"user_input"` Status string `json:"status"` Channel_id string `json:"channel_id"` Redeemed_at string `json:"redeemed_at"` Reward string `json"reward"` }
ModerationAction describes an incoming "Moderation" action coming from Twitch's PubSub servers
type PointsEvent ¶
type PointsEvent struct { Channel_id string `json:"channel_id"` Redeemed_at string `json:"redeemed_at"` Reward string `json"reward"` Id string `json:"id"` User string `json:"user"` }
BitsEvent describes an incoming "Bit" action coming from Twitch's PubSub servers
type ResponseMessage ¶
ResponseMessage TODO: Refactor