twitch

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoAuthProvided     = errors.New("one of app secret or user access token needs to be provided")
	ErrNoUserAccess       = errors.New("user endpoint called when no token was provided")
	ErrUserRefreshToken   = errors.New("the provided user refresh token is empty")
	ErrNoRefresher        = errors.New("refresher was not provided")
	ErrNoClientSecret     = errors.New("no app access token was provided")
	ErrAppTokenStatusCode = errors.New("invalid status code response while creating app access token")
)
View Source
var (
	// ErrZeroLengthMessage is returned when parsing if the input is
	// zero-length.
	ErrZeroLengthMessage = errors.New("irc: cannot parse zero-length message")

	// ErrMissingDataAfterPrefix is returned when parsing if there is
	// no message data after the prefix.
	ErrMissingDataAfterPrefix = errors.New("irc: no message data after prefix")

	// ErrMissingDataAfterTags is returned when parsing if there is no
	// message data after the tags.
	ErrMissingDataAfterTags = errors.New("irc: no message data after tags")

	// ErrMissingCommand is returned when parsing if there is no
	// command in the parsed message.
	ErrMissingCommand = errors.New("irc: missing message command")

	ErrUnhandledCommand = errors.New("irc: message command not handled by parser")
)

Functions

This section is empty.

Types

type API

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

func NewAPI

func NewAPI(clientID string, opts ...APIOptionFunc) (*API, error)

func (*API) BanUser added in v0.0.2

func (a *API) BanUser(ctx context.Context, broadcasterID string, moderatorID string, data BanUserData) error

func (*API) CreateEventSubSubscription added in v0.3.0

func (a *API) CreateEventSubSubscription(ctx context.Context, reqData CreateEventSubSubscriptionRequest) (CreateEventSubSubscriptionResponse, error)

func (*API) DeleteSubSubscriptions added in v0.3.0

func (a *API) DeleteSubSubscriptions(ctx context.Context, id string) error

func (*API) FetchEventSubSubscriptions added in v0.3.0

func (a *API) FetchEventSubSubscriptions(ctx context.Context, status, subType, userID string) ([]EventSubData, error)

https://dev.twitch.tv/docs/api/reference/#get-eventsub-subscriptions

func (*API) FetchUnbanRequests added in v0.0.4

func (a *API) FetchUnbanRequests(ctx context.Context, broadcasterID, moderatorID string) ([]UnbanRequest, error)

func (*API) FetchUserFollowedChannels added in v0.2.0

func (a *API) FetchUserFollowedChannels(ctx context.Context, userID string, broadcasterID string) ([]FollowedChannel, error)

func (*API) GetChannelEmotes

func (a *API) GetChannelEmotes(ctx context.Context, broadcaster string) (EmoteResponse, error)

func (*API) GetChatSettings

func (a *API) GetChatSettings(ctx context.Context, broadcasterID string, moderatorID string) (GetChatSettingsResponse, error)

moderatorID needs to match ID of the user the token was generated for

func (*API) GetGlobalEmotes

func (a *API) GetGlobalEmotes(ctx context.Context) (EmoteResponse, error)

func (*API) GetStreamInfo

func (a *API) GetStreamInfo(ctx context.Context, broadcastID []string) (GetStreamsResponse, error)

func (*API) GetUsers

func (a *API) GetUsers(ctx context.Context, logins []string, ids []string) (UserResponse, error)

func (*API) ResolveBanRequest added in v0.0.4

func (a *API) ResolveBanRequest(ctx context.Context, broadcasterID, moderatorID, requestID, status string) (UnbanRequest, error)

func (*API) UnbanUser added in v0.0.4

func (a *API) UnbanUser(ctx context.Context, broadcasterID string, moderatorID string, userID string) error

type APIError

type APIError struct {
	ErrorText string `json:"error"`
	Status    int    `json:"status"`
	Message   string `json:"message"`
}

error response

func (APIError) Error

func (a APIError) Error() string

type APIOptionFunc

type APIOptionFunc func(api *API) error

func WithClientSecret

func WithClientSecret(secret string) APIOptionFunc

func WithHTTPClient

func WithHTTPClient(client *http.Client) APIOptionFunc

func WithUserAuthentication

func WithUserAuthentication(provider AccountProvider, refresher TokenRefresher, accountID string) APIOptionFunc

type AccountProvider

type AccountProvider interface {
	GetAccountBy(id string) (save.Account, error)
	UpdateTokensFor(id, accessToken, refreshToken string) error
}

type BanUserData added in v0.0.2

type BanUserData struct {
	UserID            string `json:"user_id"`
	DurationInSeconds int    `json:"duration,omitempty"`
	Reason            string `json:"reason"`
}

https://dev.twitch.tv/docs/api/reference/#ban-user

type BanUserRequest added in v0.0.2

type BanUserRequest struct {
	Data BanUserData `json:"data"`
}

https://dev.twitch.tv/docs/api/reference/#ban-user

type Chat

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

func NewChat

func NewChat(logger zerolog.Logger, accountProvider AccountProvider, accountID string) *Chat

func (*Chat) ConnectWithRetry

func (c *Chat) ConnectWithRetry(ctx context.Context, messages <-chan IRCer) (<-chan IRCer, <-chan error)

type ChatSettingData

type ChatSettingData struct {
	BroadcasterID                 string `json:"broadcaster_id"`
	SlowMode                      bool   `json:"slow_mode"`
	SlowModeWaitTime              int    `json:"slow_mode_wait_time"` // in seconds
	FollowerMode                  bool   `json:"follower_mode"`
	FollowerModeDuration          int    `json:"follower_mode_duration"` // in minutes
	SubscriberMode                bool   `json:"subscriber_mode"`
	EmoteMode                     bool   `json:"emote_mode"`
	UniqueChatMode                bool   `json:"unique_chat_mode"`
	NonModeratorChatDelay         bool   `json:"non_moderator_chat_delay"`
	NonModeratorChatDelayDuration int    `json:"non_moderator_chat_delay_duration"` // in seconds
}

https://dev.twitch.tv/docs/api/reference/#get-chat-settings

type CreateEventSubSubscriptionRequest added in v0.3.0

type CreateEventSubSubscriptionRequest struct {
	Type      string                   `json:"type"`
	Version   string                   `json:"version"`
	Condition map[string]string        `json:"condition"`
	Transport EventSubTransportRequest `json:"transport"`
}

https://dev.twitch.tv/docs/api/reference/#create-eventsub-subscription

type CreateEventSubSubscriptionResponse added in v0.3.0

type CreateEventSubSubscriptionResponse struct {
	Data         []EventSubData `json:"data"`
	Total        int            `json:"total"`
	TotalCost    int            `json:"total_cost"`
	MaxTotalCost int            `json:"max_total_cost"`
}

https://dev.twitch.tv/docs/api/reference/#create-eventsub-subscription

type EmoteData

type EmoteData struct {
	ID        string     `json:"id"`
	Name      string     `json:"name"`
	Images    EmoteImage `json:"images"`
	Format    []string   `json:"format"`
	Scale     []string   `json:"scale"`
	ThemeMode []string   `json:"theme_mode"`
}

https://api.twitch.tv/helix/chat/emotes/global

type EmoteImage

type EmoteImage struct {
	URL1X string `json:"url_1x"`
	URL2X string `json:"url_2x"`
	URL4X string `json:"url_4x"`
}

https://api.twitch.tv/helix/chat/emotes/global

type EmoteResponse

type EmoteResponse struct {
	Data     []EmoteData `json:"data"`
	Template string      `json:"template"`
}

https://api.twitch.tv/helix/chat/emotes/global

type EventSubData added in v0.3.0

type EventSubData struct {
	ID        string            `json:"id"`
	Status    string            `json:"status"`
	Type      string            `json:"type"`
	Version   string            `json:"version"`
	Condition map[string]string `json:"condition"`
	CreatedAt time.Time         `json:"created_at"`
	Transport EventSubTransport `json:"transport"`
	Cost      int               `json:"cost"`
}

https://dev.twitch.tv/docs/api/reference/#create-eventsub-subscription

type EventSubTransport added in v0.3.0

type EventSubTransport struct {
	Method    string `json:"method"`
	ConduitID string `json:"conduit_id"`
}

https://dev.twitch.tv/docs/api/reference/#create-eventsub-subscription

type EventSubTransportRequest added in v0.3.0

type EventSubTransportRequest struct {
	Method    string `json:"method"`
	Callback  string `json:"callback"`
	ConduitID string `json:"conduit_id"`
	Secret    string `json:"secret"`
	SessionID string `json:"session_id"`
}

https://dev.twitch.tv/docs/api/reference/#create-eventsub-subscription

type FollowedChannel added in v0.2.0

type FollowedChannel struct {
	BroadcasterID    string    `json:"broadcaster_id"`
	BroadcasterLogin string    `json:"broadcaster_login"`
	BroadcasterName  string    `json:"broadcaster_name"`
	FollowedAt       time.Time `json:"followed_at"`
}

https://dev.twitch.tv/docs/api/reference/#get-followed-channels

type GetChatSettingsResponse

type GetChatSettingsResponse struct {
	Data []ChatSettingData `json:"data"`
}

https://dev.twitch.tv/docs/api/reference/#get-chat-settings

type GetEventSubSubscriptionsResponse added in v0.3.0

type GetEventSubSubscriptionsResponse struct {
	Total        int            `json:"total"`
	TotalCost    int            `json:"total_cost"`
	MaxTotalCost int            `json:"max_total_cost"`
	Pagination   Pagination     `json:"pagination"`
	Data         []EventSubData `json:"data"`
}

https://dev.twitch.tv/docs/api/reference/#get-eventsub-subscriptions

type GetFollowedChannelsResponse added in v0.2.0

type GetFollowedChannelsResponse struct {
	Total      int               `json:"total"`
	Data       []FollowedChannel `json:"data"`
	Pagination Pagination        `json:"pagination"`
}

https://dev.twitch.tv/docs/api/reference/#get-followed-channels

type GetStreamsResponse

type GetStreamsResponse struct {
	Data       []StreamData `json:"data"`
	Pagination Pagination   `json:"pagination"`
}

https://api.twitch.tv/helix/streams

type GetUnbanRequestsResponse added in v0.0.4

type GetUnbanRequestsResponse struct {
	Data       []UnbanRequest `json:"data"`
	Pagination Pagination     `json:"pagination"`
}

https://dev.twitch.tv/docs/api/reference/#get-unban-requests

type IRCer

type IRCer interface {
	IRC() string
}

IRCer are types that can be turned into an IRC command

func ParseIRC added in v0.3.0

func ParseIRC(message string) (IRCer, error)

type Pagination

type Pagination struct {
	Cursor string `json:"cursor"`
}

https://api.twitch.tv/helix/streams

type RetryReachedError

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

func (RetryReachedError) Error

func (e RetryReachedError) Error() string

func (RetryReachedError) Unwrap

func (e RetryReachedError) Unwrap() error

type StreamData

type StreamData 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"`
	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       []any     `json:"tag_ids"`
	IsMature     bool      `json:"is_mature"`
}

https://api.twitch.tv/helix/streams

type TokenRefresher

type TokenRefresher interface {
	RefreshToken(ctx context.Context, refreshToken string) (string, string, error)
}

type UnbanRequest added in v0.0.4

type UnbanRequest struct {
	ID               string    `json:"id"`
	BroadcasterName  string    `json:"broadcaster_name"`
	BroadcasterLogin string    `json:"broadcaster_login"`
	BroadcasterID    string    `json:"broadcaster_id"`
	ModeratorID      string    `json:"moderator_id"`
	ModeratorLogin   string    `json:"moderator_login"`
	ModeratorName    string    `json:"moderator_name"`
	UserID           string    `json:"user_id"`
	UserLogin        string    `json:"user_login"`
	UserName         string    `json:"user_name"`
	Text             string    `json:"text"`
	Status           string    `json:"status"`
	CreatedAt        time.Time `json:"created_at"`
	ResolvedAt       time.Time `json:"resolved_at"`
	ResolutionText   string    `json:"resolution_text"`
}

https://dev.twitch.tv/docs/api/reference/#get-unban-requests

type UserData

type UserData 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"`
	OfflineImageURL string    `json:"offline_image_url"`
	ViewCount       int       `json:"view_count"`
	Email           string    `json:"email"`
	CreatedAt       time.Time `json:"created_at"`
}

https://dev.twitch.tv/docs/api/reference/#get-users

type UserResponse

type UserResponse struct {
	Data []UserData `json:"data"`
}

https://dev.twitch.tv/docs/api/reference/#get-users

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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