twitchnotify

package
v0.0.0-...-eb18d79 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package twitchnotify provides functionalities to watch the state of twitch streams and notifying changes by polling the twitch REST API.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserNotFound        = errors.New("user not found")
	ErrGameNotFound        = errors.New("game not found")
	ErrInvalidResponseType = errors.New("invalid response type")
	ErrMaxUsersReached     = errors.New("max registered users reached")
)

Functions

func GetEmbed

func GetEmbed(d *Stream, u *User) *discordgo.MessageEmbed

GetEmbed assembles and returns an embed reference from the given Stream and User objects.

Types

type Config

type Config struct {
	TimerDelay time.Duration `json:"timderdelay"`
}

type Credentials

type Credentials struct {
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
}

Credentials hold the client ID and client secret of a twitch API application.

type DBEntry

type DBEntry struct {
	GuildID      string
	ChannelID    string
	TwitchUserID string
}

DBEntry specifies a database entry for tracking twitch users.

type Game

type Game struct {
	ID      string `json:"id"`
	Name    string `json:"name"`
	IconURL string `json:"box_art_url"`
}

Game wraps information about a twitch game type.

type NotifyHandler

type NotifyHandler func(*Stream, *User)

NotifyHandler describes a callback handler when a stream either goes online or offline passing the stream data as well as the user data of the streamer.

type NotifyWorker

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

NotifyWorker provides general utilities to fetch watched online streamers and call notify handler callbacks when a stream goes online or offline.

func New

func New(
	creds Credentials,
	wentOnlineHandler NotifyHandler,
	wentOfflineHandler NotifyHandler,
	config ...Config,
) (worker *NotifyWorker, err error)

New initializes a new NotifyWorker instance and starts the worker timer loop.

func (*NotifyWorker) AddUser

func (w *NotifyWorker) AddUser(u *User) error

AddUser adds the specified twitch User to the watch list. If maxUserCap is reached, an ErrMaxUsersreached error is returned.

func (*NotifyWorker) GetUser

func (w *NotifyWorker) GetUser(identifyer string, typ UserIdent) (*User, error)

GetUser tries to fetch a user either by login or by ID, specified by typ which one of these methods is used. Returns the fetched user object and occured errors during fetch.

func (*NotifyWorker) Handle

func (w *NotifyWorker) Handle() error

Handle is the callback function executed on ech timer tick.

type Stream

type Stream struct {
	ID           string   `json:"id"`
	UserID       string   `json:"user_id"`
	UserName     string   `json:"user_name"`
	GameID       string   `json:"game_id"`
	CommunityIDs []string `json:"community_ids"`
	Type         string   `json:"type"`
	Title        string   `json:"title"`
	ViewerCount  int      `json:"viewer_count"`
	StartedAt    string   `json:"started_at"`
	Language     string   `json:"language"`
	ThumbnailURL string   `json:"thumbnail_url"`

	Game *Game
}

Stream wraps information about a twitch stream.

type User

type User struct {
	ID          string `json:"id"`
	DisplayName string `json:"display_name"`
	LoginName   string `json:"login"`
	Description string `json:"description"`
	AviURL      string `json:"profile_image_url"`
}

User wraps information about a twitch streamer.

type UserIdent

type UserIdent string

UserIdent is the type of identificator for getting users via the Twitch API.

const (
	IdentID    UserIdent = "id"
	IdentLogin UserIdent = "login"
)

Jump to

Keyboard shortcuts

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