twitch

package
v3.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BadgeBroadcaster = "broadcaster"
	BadgeFounder     = "founder"
	BadgeModerator   = "moderator"
	BadgeSubscriber  = "subscriber"
	BadgeVIP         = "vip"
)
View Source
const (
	EventSubEventTypeChannelFollow = "channel.follow"
	EventSubEventTypeChannelRaid   = "channel.raid"
	EventSubEventTypeChannelUpdate = "channel.update"
	EventSubEventTypeStreamOffline = "stream.offline"
	EventSubEventTypeStreamOnline  = "stream.online"

	EventSubEventTypeChannelPointCustomRewardRedemptionAdd = "channel.channel_points_custom_reward_redemption.add"

	EventSubEventTypeUserAuthorizationRevoke = "user.authorization.revoke"
)
View Source
const (
	// API Scopes
	ScopeChannelEditCommercial       = "channel:edit:commercial"
	ScopeChannelManageBroadcast      = "channel:manage:broadcast"
	ScopeChannelManageModerators     = "channel:manage:moderators"
	ScopeChannelManagePolls          = "channel:manage:polls"
	ScopeChannelManagePredictions    = "channel:manage:predictions"
	ScopeChannelManageRaids          = "channel:manage:raids"
	ScopeChannelManageRedemptions    = "channel:manage:redemptions"
	ScopeChannelManageVIPS           = "channel:manage:vips"
	ScopeChannelManageWhispers       = "user:manage:whispers"
	ScopeChannelReadRedemptions      = "channel:read:redemptions"
	ScopeModeratorManageAnnoucements = "moderator:manage:announcements"
	ScopeModeratorManageBannedUsers  = "moderator:manage:banned_users"
	ScopeModeratorManageChatMessages = "moderator:manage:chat_messages"
	ScopeModeratorManageChatSettings = "moderator:manage:chat_settings"
	ScopeUserManageChatColor         = "user:manage:chat_color"

	// Deprecated v5 scope but used in chat
	ScopeV5ChannelEditor = "channel_editor"

	// Chat Scopes
	ScopeChatEdit    = "chat:edit"     // Send live stream chat and rooms messages.
	ScopeChatRead    = "chat:read"     // View live stream chat and rooms messages.
	ScopeWhisperRead = "whispers:read" // View your whisper messages.
)

Variables

Functions

This section is empty.

Types

type APICache

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

func (*APICache) Get

func (t *APICache) Get(key []string) interface{}

func (*APICache) Set

func (t *APICache) Set(key []string, valid time.Duration, data interface{})

type BadgeCollection

type BadgeCollection map[string]*int

func ParseBadgeLevels

func ParseBadgeLevels(m *irc.Message) BadgeCollection

func (BadgeCollection) Add

func (b BadgeCollection) Add(badge string, level int)

func (BadgeCollection) Get

func (b BadgeCollection) Get(badge string) int

func (BadgeCollection) Has

func (b BadgeCollection) Has(badge string) bool

type Category

type Category struct {
	BoxArtURL string `json:"box_art_url"`
	ID        string `json:"id"`
	Name      string `json:"name"`
}

type Client

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

func New

func New(clientID, clientSecret, accessToken, refreshToken string) *Client

func (*Client) APICache

func (c *Client) APICache() *APICache

func (*Client) AddChannelVIP added in v3.2.0

func (c *Client) AddChannelVIP(ctx context.Context, broadcasterName, userName string) error

func (*Client) BanUser

func (c *Client) BanUser(channel, username string, duration time.Duration, reason string) error

BanUser bans or timeouts a user in the given channel. Setting the duration to 0 will result in a ban, setting if greater than 0 will result in a timeout. The timeout is automatically converted to full seconds. The timeout duration must be less than 1209600s.

func (*Client) DeleteMessage

func (c *Client) DeleteMessage(channel, messageID string) error

DeleteMessage deletes one or all messages from the specified chat. If no messageID is given all messages are deleted. If a message ID is given the message must be no older than 6 hours and it must not be posted by broadcaster or moderator.

func (*Client) GetAuthorizedUser

func (c *Client) GetAuthorizedUser() (userID string, userName string, err error)

func (*Client) GetCurrentStreamInfo

func (c *Client) GetCurrentStreamInfo(username string) (*StreamInfo, error)

func (*Client) GetDisplayNameForUser

func (c *Client) GetDisplayNameForUser(username string) (string, error)

func (*Client) GetFollowDate

func (c *Client) GetFollowDate(from, to string) (time.Time, error)

func (*Client) GetIDForUsername

func (c *Client) GetIDForUsername(username string) (string, error)

func (*Client) GetRecentStreamInfo

func (c *Client) GetRecentStreamInfo(username string) (string, string, error)

func (*Client) GetToken

func (c *Client) GetToken() (string, error)

func (*Client) GetUserInformation

func (c *Client) GetUserInformation(user string) (*User, error)

func (*Client) HasLiveStream

func (c *Client) HasLiveStream(username string) (bool, error)

func (*Client) ModifyChannelInformation

func (c *Client) ModifyChannelInformation(ctx context.Context, broadcasterName string, game, title *string) error

func (*Client) RefreshToken

func (c *Client) RefreshToken() error

func (*Client) RemoveChannelVIP added in v3.2.0

func (c *Client) RemoveChannelVIP(ctx context.Context, broadcasterName, userName string) error

func (*Client) SearchCategories

func (c *Client) SearchCategories(ctx context.Context, name string) ([]Category, error)

func (*Client) SendChatAnnouncement

func (c *Client) SendChatAnnouncement(channel, color, message string) error

SendChatAnnouncement sends an announcement in the specified channel with the given message. Colors must be blue, green, orange, purple or primary (empty color = primary)

func (*Client) SendWhisper

func (c *Client) SendWhisper(toUser, message string) error

SendWhisper sends a whisper from the bot to the specified user.

For details about message limits see the official documentation: https://dev.twitch.tv/docs/api/reference#send-whisper

func (*Client) SetTokenUpdateHook

func (c *Client) SetTokenUpdateHook(f func(string, string) error)

func (*Client) UnbanUser

func (c *Client) UnbanUser(channel, username string) error

UnbanUser removes a timeout or ban given to the user in the channel

func (*Client) UpdateToken

func (c *Client) UpdateToken(accessToken, refreshToken string)

func (*Client) ValidateToken

func (c *Client) ValidateToken(ctx context.Context, force bool) error

type EventSubClient

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

func NewEventSubClient

func NewEventSubClient(twitchClient *Client, apiURL, secret, secretHandle string) (*EventSubClient, error)

func (*EventSubClient) HandleEventsubPush

func (e *EventSubClient) HandleEventsubPush(w http.ResponseWriter, r *http.Request)

func (*EventSubClient) PreFetchSubscriptions

func (e *EventSubClient) PreFetchSubscriptions(ctx context.Context) error

func (*EventSubClient) RegisterEventSubHooks

func (e *EventSubClient) RegisterEventSubHooks(event string, condition EventSubCondition, callback func(json.RawMessage) error) (func(), error)

type EventSubCondition

type EventSubCondition struct {
	BroadcasterUserID     string `json:"broadcaster_user_id,omitempty"`
	CampaignID            string `json:"campaign_id,omitempty"`
	CategoryID            string `json:"category_id,omitempty"`
	ClientID              string `json:"client_id,omitempty"`
	ExtensionClientID     string `json:"extension_client_id,omitempty"`
	FromBroadcasterUserID string `json:"from_broadcaster_user_id,omitempty"`
	OrganizationID        string `json:"organization_id,omitempty"`
	RewardID              string `json:"reward_id,omitempty"`
	ToBroadcasterUserID   string `json:"to_broadcaster_user_id,omitempty"`
	UserID                string `json:"user_id,omitempty"`
}

func (EventSubCondition) Hash

func (e EventSubCondition) Hash() (string, error)

type EventSubEventChannelPointCustomRewardRedemptionAdd

type EventSubEventChannelPointCustomRewardRedemptionAdd struct {
	ID                   string `json:"id"`
	BroadcasterUserID    string `json:"broadcaster_user_id"`
	BroadcasterUserLogin string `json:"broadcaster_user_login"`
	BroadcasterUserName  string `json:"broadcaster_user_name"`
	UserID               string `json:"user_id"`
	UserLogin            string `json:"user_login"`
	UserName             string `json:"user_name"`
	UserInput            string `json:"user_input"`
	Status               string `json:"status"`
	Reward               struct {
		ID     string `json:"id"`
		Title  string `json:"title"`
		Cost   int64  `json:"cost"`
		Prompt string `json:"prompt"`
	} `json:"reward"`
	RedeemedAt time.Time `json:"redeemed_at"`
}

type EventSubEventChannelUpdate

type EventSubEventChannelUpdate struct {
	BroadcasterUserID    string `json:"broadcaster_user_id"`
	BroadcasterUserLogin string `json:"broadcaster_user_login"`
	BroadcasterUserName  string `json:"broadcaster_user_name"`
	Title                string `json:"title"`
	Language             string `json:"language"`
	CategoryID           string `json:"category_id"`
	CategoryName         string `json:"category_name"`
	IsMature             bool   `json:"is_mature"`
}

type EventSubEventFollow

type EventSubEventFollow struct {
	UserID               string    `json:"user_id"`
	UserLogin            string    `json:"user_login"`
	UserName             string    `json:"user_name"`
	BroadcasterUserID    string    `json:"broadcaster_user_id"`
	BroadcasterUserLogin string    `json:"broadcaster_user_login"`
	BroadcasterUserName  string    `json:"broadcaster_user_name"`
	FollowedAt           time.Time `json:"followed_at"`
}

type EventSubEventRaid

type EventSubEventRaid struct {
	FromBroadcasterUserID    string `json:"from_broadcaster_user_id"`
	FromBroadcasterUserLogin string `json:"from_broadcaster_user_login"`
	FromBroadcasterUserName  string `json:"from_broadcaster_user_name"`
	ToBroadcasterUserID      string `json:"to_broadcaster_user_id"`
	ToBroadcasterUserLogin   string `json:"to_broadcaster_user_login"`
	ToBroadcasterUserName    string `json:"to_broadcaster_user_name"`
	Viewers                  int64  `json:"viewers"`
}

type EventSubEventStreamOffline

type EventSubEventStreamOffline struct {
	BroadcasterUserID    string `json:"broadcaster_user_id"`
	BroadcasterUserLogin string `json:"broadcaster_user_login"`
	BroadcasterUserName  string `json:"broadcaster_user_name"`
}

type EventSubEventStreamOnline

type EventSubEventStreamOnline struct {
	ID                   string    `json:"id"`
	BroadcasterUserID    string    `json:"broadcaster_user_id"`
	BroadcasterUserLogin string    `json:"broadcaster_user_login"`
	BroadcasterUserName  string    `json:"broadcaster_user_name"`
	Type                 string    `json:"type"`
	StartedAt            time.Time `json:"started_at"`
}

type EventSubEventUserAuthorizationRevoke

type EventSubEventUserAuthorizationRevoke struct {
	ClientID  string `json:"client_id"`
	UserID    string `json:"user_id"`
	UserLogin string `json:"user_login"`
	UserName  string `json:"user_name"`
}

type OAuthTokenResponse

type OAuthTokenResponse struct {
	AccessToken  string   `json:"access_token"`
	RefreshToken string   `json:"refresh_token"`
	ExpiresIn    int      `json:"expires_in"`
	Scope        []string `json:"scope"`
	TokenType    string   `json:"token_type"`
}

type OAuthTokenValidationResponse

type OAuthTokenValidationResponse struct {
	ClientID  string   `json:"client_id"`
	Login     string   `json:"login"`
	Scopes    []string `json:"scopes"`
	UserID    string   `json:"user_id"`
	ExpiresIn int      `json:"expires_in"`
}

type StreamInfo

type StreamInfo 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"`
	Title        string    `json:"title"`
	ViewerCount  int64     `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"`
}

type User

type User struct {
	DisplayName     string `json:"display_name"`
	ID              string `json:"id"`
	Login           string `json:"login"`
	ProfileImageURL string `json:"profile_image_url"`
}

Jump to

Keyboard shortcuts

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