chat

package
v0.0.0-...-23da873 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UnknownType of message
	UnknownType = iota
	// PrivateMessage is a standard chat
	PrivateMessage
	// JoinMessage is something related to who is in the channel?
	JoinMessage
	// PingMessage is the Ping request from the server
	PingMessage
	// PartMessage is something related to Join?
	PartMessage
	// UserStateMessage is something we get at our join?
	UserStateMessage
	// RoomStateMessage tells us about the rules of the room
	RoomStateMessage
	// GlobalUserState ???
	GlobalUserState
	// Capacity ??
	Capacity
	// Authentication response
	Authentication
	// AuthenticationFail response
	AuthenticationFail
)

Variables

View Source
var (
	// ErrAuthFailed is returned if the twitch authetication process returns an error
	ErrAuthFailed = fmt.Errorf("failed to authenticate")
	// ErrNoChannel must provide a channel to join
	ErrNoChannel = fmt.Errorf("no channel provided")
	// ErrNoConnection connection was not established
	ErrNoConnection = fmt.Errorf("no connection")

	// TwitchCharacterLimit is the maximum message size
	TwitchCharacterLimit = 500
)
View Source
var ErrInvalidMsg = fmt.Errorf("invalid message, did not parse")

ErrInvalidMsg the message didn't parse

Functions

func AlternateUsers

func AlternateUsers() map[string]string

AlternateUsers for a given twitch user (eg a watching account separate from the broadcasting one)

func Bots

func Bots() map[string]struct{}

Bots we know about

func IsBot

func IsBot(user string) bool

IsBot is it probably a bot?

func TrimBots

func TrimBots(users *sync.Map)

TrimBots from a user list

Types

type ListenMessage

type ListenMessage struct {
	Type  string      `json:"type"`
	Nonce string      `json:"nonce,omitempty"`
	Data  ListenTopic `json:"data"`
}

ListenMessage subscribes to a pubsub topic

type ListenTopic

type ListenTopic struct {
	Topics    []string `json:"topics"`
	AuthToken string   `json:"auth_token"`
}

ListenTopic describes a pubsub listen topic

type Twitch

type Twitch struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Twitch talks to twitch

func NewTwitch

func NewTwitch(cfg *config.Configuration) (*Twitch, error)

NewTwitch chat interface

func (*Twitch) Clip

func (t *Twitch) Clip() (string, error)

Clip the latest few seconds nightbot : $(urlfetch https://m7tthg2fz8.execute-api.us-east-1.amazonaws.com/?cmd=clip)

func (*Twitch) Close

func (t *Twitch) Close() error

Close will idempotently close the underlying websocket

func (*Twitch) Farewell

func (t *Twitch) Farewell(channelName string, user string)

Farewell to a user

func (*Twitch) GetAllStreamInfoForUsers

func (t *Twitch) GetAllStreamInfoForUsers(usernames ...string) (map[string]TwitchStreamInfo, int, error)

GetAllStreamInfoForUsers will give the stream info for the given channel names curl -X GET 'https://api.twitch.tv/helix/streams' https://dev.twitch.tv/docs/api/reference/#get-streams

func (*Twitch) GetAuthTokens

func (t *Twitch) GetAuthTokens(ctx context.Context, channelID, channelName string) (err error)

GetAuthTokens will try very hard to get the authentication tokens

func (*Twitch) GetChannelInfo

func (t *Twitch) GetChannelInfo(userInfo *TwitchUserInfo) (*TwitchChannelInfo, error)

GetChannelInfo gets channel information

func (*Twitch) GetClips

func (t *Twitch) GetClips(userInfo *TwitchUserInfo) ([]*TwithcClipInfo, error)

GetClips gets the channel clips

func (*Twitch) GetUserInfo

func (t *Twitch) GetUserInfo(login string) (*TwitchUserInfo, error)

GetUserInfo gets the information on a user by login

func (*Twitch) IFollowThem

func (t *Twitch) IFollowThem(theirID string) (bool, error)

IFollowThem checks if a channel is followed by the channel running the bot, used by auto-shoutout https://dev.twitch.tv/docs/api/reference/#get-followed-channels

func (*Twitch) Open

func (t *Twitch) Open(ctx context.Context) error

Open the connection again

func (*Twitch) Pong

func (t *Twitch) Pong(msg TwitchMessage) error

Pong is keep alive

func (*Twitch) ReceiveOneMessage

func (t *Twitch) ReceiveOneMessage() (msg TwitchMessage, err error)

ReceiveOneMessage waits for a message to be posted to chat

func (*Twitch) Reconnect

func (t *Twitch) Reconnect(ctx context.Context, channelID, channelName string) error

Reconnect when the token expires

func (*Twitch) SendMessage

func (t *Twitch) SendMessage(channelName, msg string) (err error)

SendMessage to a channel TODO: elipsis/fmt args pls

func (*Twitch) Shoutout

func (t *Twitch) Shoutout(channelName string, user string, manual bool)

Shoutout a user

func (*Twitch) StartPubSubEventHandler

func (t *Twitch) StartPubSubEventHandler(ctx context.Context, wg *sync.WaitGroup,
	redemptionHandlers map[string]func(context.Context, TwitchPointRedemption),
)

StartPubSubEventHandler is the event loop for twitch pub-sub

func (*Twitch) SuperShoutOut

func (t *Twitch) SuperShoutOut(channelName string, user string, manual bool) []*TwithcClipInfo

SuperShoutOut grabs clips

type TwitchChannelInfo

type TwitchChannelInfo struct {
	BroadcasterID              string   `json:"broadcaster_id"`
	BroadcasterLogin           string   `json:"broadcaster_login"`
	BroadcasterName            string   `json:"broadcaster_name"`
	BroadcasterLanguage        string   `json:"broadcaster_language"`
	GameID                     string   `json:"game_id"`
	GameName                   string   `json:"game_name"`
	IsLive                     bool     `json:"is_live"`
	Title                      string   `json:"title"`
	Delay                      int      `json:"delay"`
	Taghs                      []string `json:"tags"`
	ContentClassificatinLables []string `json:"content_classification_labels"`
	ISBrandedContent           bool     `json:"is_branded_content"`
}

TwitchChannelInfo contains the information about a channel

type TwitchEventMessage

type TwitchEventMessage struct {
	Type string                 `json:"type"`
	Data map[string]interface{} `json:"data"`
}

TwitchEventMessage from the pubsub

type TwitchMessage

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

TwitchMessage wrapper for parsing and providing info on individual chat messages

func FakeTwitchMessage

func FakeTwitchMessage(body string) TwitchMessage

FakeTwitchMessage for timers/etc

func (TwitchMessage) AtUser

func (c TwitchMessage) AtUser() string

AtUser is the user in a format that twitch likes with an @ sign

func (TwitchMessage) Body

func (c TwitchMessage) Body() string

Body of the message

func (TwitchMessage) CleanUserFromArgs

func (c TwitchMessage) CleanUserFromArgs() string

CleanUserFromArgs or just the user who sent it

func (TwitchMessage) DisplayName

func (c TwitchMessage) DisplayName() string

DisplayName of the user who sent the message

func (TwitchMessage) GetBotCommand

func (c TwitchMessage) GetBotCommand() string

GetBotCommand gets the command passed if IsBotCommand

func (TwitchMessage) GetBotCommandArgs

func (c TwitchMessage) GetBotCommandArgs() string

GetBotCommandArgs returns any arguments passed to the command as a single string

func (TwitchMessage) GoString

func (c TwitchMessage) GoString() string

GoString is verbose

func (TwitchMessage) IsBotCommand

func (c TwitchMessage) IsBotCommand() bool

IsBotCommand will say if a chat message should be interpreted as a bot command

func (TwitchMessage) IsMod

func (c TwitchMessage) IsMod() bool

IsMod for restricted bot commands

func (TwitchMessage) IsOwner

func (c TwitchMessage) IsOwner() bool

IsOwner is the channel owner/broadcaster

func (TwitchMessage) IsSub

func (c TwitchMessage) IsSub() bool

IsSub is a subscriber

func (TwitchMessage) IsVIP

func (c TwitchMessage) IsVIP() bool

IsVIP are VIPs

func (*TwitchMessage) Parse

func (c *TwitchMessage) Parse(b []byte) error

Parse message from the websocket read

func (TwitchMessage) Raw

func (c TwitchMessage) Raw() string

Raw message contents with headers/etc

func (TwitchMessage) String

func (c TwitchMessage) String() string

String is readable

func (TwitchMessage) Type

func (c TwitchMessage) Type() int

Type of chat message

func (TwitchMessage) User

func (c TwitchMessage) User() string

User that sent the message

func (TwitchMessage) Users

func (c TwitchMessage) Users() map[string]string

Users found in Join/Part messages

type TwitchPointRedemption

type TwitchPointRedemption struct {
	Timestamp  time.Time `json:"timestamp"`
	Redemption struct {
		ID   string `json:"id"`
		User struct {
			ID          string `json:"id"`
			Login       string `json:"login"`
			DisplayName string `json:"display_name"`
		} `json:"user"`
		ChannelID  string    `json:"channel_id"`
		RedeemedAt time.Time `json:"redeemed_at"`
		Reward     struct {
			ID        string `json:"id"`
			ChannelID string `json:"channel_id"`
			Title     string `json:"title"`
		} `json:"reward"`
		UserInput string `json:"user_input"`
		Status    string `json:"status"`
	} `json:"redemption"`
}

TwitchPointRedemption from the pubsub

type TwitchPubSubMessage

type TwitchPubSubMessage struct {
	Type string                 `json:"type"`
	Data map[string]interface{} `json:"data,omitempty"`
}

TwitchPubSubMessage is a parsed message from twitch event pub/sub

type TwitchStreamInfo

type TwitchStreamInfo 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"` // "live"
	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       []string  `json:"tag_ids"`
	IsMature     bool      `json:"is_mature"`
}

TwitchStreamInfo contains info that twitch api provides on live streams

type TwitchUserInfo

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

TwitchUserInfo response from GetUser https://dev.twitch.tv/docs/api/reference/#get-users

type TwithcClipInfo

type TwithcClipInfo struct {
	ID        string `json:"id"`        // : "AwkwardHelplessSalamanderSwiftRage",
	URL       string `json:"url"`       // : "https://clips.twitch.tv/AwkwardHelplessSalamanderSwiftRage",
	EmbeddURL string `json:"embed_url"` // : "https://clips.twitch.tv/embed?clip=AwkwardHelplessSalamanderSwiftRage",
	//	"broadcaster_id": "67955580",
	//	"broadcaster_name": "ChewieMelodies",
	//	"creator_id": "53834192",
	//	"creator_name": "BlackNova03",
	//	"video_id": "205586603",
	//	"game_id": "488191",
	//	"language": "en",
	Title        string    `json:"title"`         //	"title": "babymetal",
	ViewCount    int       `json:"view_count"`    // : 10,
	CreatedAt    time.Time `json:"created_at"`    // : "2017-11-30T22:34:18Z",
	ThumbnailURL string    `json:"thumbnail_url"` //: "https://clips-media-assets.twitch.tv/157589949-preview-480x272.jpg",
	Duration     float64   `json:"duration"`      //: 28.3

}

TwithcClipInfo get clip response

Jump to

Keyboard shortcuts

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