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 ¶
- Variables
- func SettingsFromResponse(resp twitchapi.GetChatSettingsResponse) (twitchapi.ChatSettingData, error)
- func SettingsFromUpdate(event eventsub.Event) twitchapi.ChatSettingData
- type Cache
- func (c *Cache) ApplyRoomState(broadcasterID string, state *twitchirc.RoomState) twitchapi.ChatSettingData
- func (c *Cache) Fetch(ctx context.Context, broadcasterID string, fetch Fetcher) (twitchapi.ChatSettingData, error)
- func (c *Cache) Get(broadcasterID string) (twitchapi.ChatSettingData, bool)
- func (c *Cache) Put(broadcasterID string, settings twitchapi.ChatSettingData)
- type Fetcher
Constants ¶
This section is empty.
Variables ¶
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 (*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.