chatstate

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package chatstate keeps the chat-room settings: slow mode, follower mode, emote-only and the rest of the state a tab renders in its status bar.

The settings have two sources. IRC ROOMSTATE messages are free but partial: Twitch only sends the tags it wants to report, so an absent tag means "no news", not "off". The Twitch Get Chat Settings endpoint returns the full state but costs one request per broadcaster and cannot be batched. The cache merges both and deduplicates requests, so a channel is fetched at most once and every tab showing that channel renders the same state.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoSettings = errors.New("no chat settings returned for channel")

ErrNoSettings reports that Get Chat Settings answered without an entry for the broadcaster, which means the response cannot be used as settings.

Functions

func SettingsFromResponse

func SettingsFromResponse(resp twitchapi.GetChatSettingsResponse) (twitchapi.ChatSettingData, error)

SettingsFromResponse unwraps the single entry Get Chat Settings returns. Both the startup prefetch and the tab fallback read settings this way, so the "empty answer" rule lives here instead of in each caller.

func SettingsFromUpdate

func SettingsFromUpdate(event eventsub.Event) twitchapi.ChatSettingData

SettingsFromUpdate converts a channel.chat_settings.update event into the settings shape the cache and the status bar use. The event always carries the complete state, so no merge with older settings is needed.

Types

type Cache

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

Cache holds the known chat settings per broadcaster ID. Settings belong to the channel, not to the account reading them, so tabs of different accounts share an entry.

func NewCache

func NewCache() *Cache

func (*Cache) ApplyRoomState

func (c *Cache) ApplyRoomState(broadcasterID string, state *twitchirc.RoomState) twitchapi.ChatSettingData

ApplyRoomState merges a ROOMSTATE message into the settings known for the channel and returns the result. Because the message is partial, a full state fetched earlier survives an update that only mentions one setting.

func (*Cache) Fetch

func (c *Cache) Fetch(ctx context.Context, broadcasterID string, fetch Fetcher) (twitchapi.ChatSettingData, error)

Fetch returns the settings of a channel and only calls fetch when nothing is cached. Concurrent callers for the same channel share one request. Failures are not cached, so a later call can retry.

func (*Cache) Get

func (c *Cache) Get(broadcasterID string) (twitchapi.ChatSettingData, bool)

Get returns the settings known for a channel without making a request.

func (*Cache) Put

func (c *Cache) Put(broadcasterID string, settings twitchapi.ChatSettingData)

Put records settings for a channel. Empty IDs are ignored: they carry no channel identity and would share one map entry across unrelated tabs.

type Fetcher

type Fetcher func(ctx context.Context) (twitchapi.ChatSettingData, error)

Fetcher loads the complete chat settings of one broadcaster.

Jump to

Keyboard shortcuts

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