twitch-bot/botUserState.go
Knut Ahlers 688c665356
[core] Fix: Emote sets are not int but uuid
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2021-09-29 19:05:12 +02:00

63 lines
1.2 KiB
Go

package main
import (
"strings"
"sync"
"github.com/Luzifer/twitch-bot/twitch"
"github.com/go-irc/irc"
)
type (
twitchUserState struct {
Badges twitch.BadgeCollection
Color string
DisplayName string
EmoteSets []string
}
twitchUserStateStore struct {
states map[string]*twitchUserState
lock sync.RWMutex
}
)
func newTwitchUserStateStore() *twitchUserStateStore {
return &twitchUserStateStore{
states: make(map[string]*twitchUserState),
}
}
func parseTwitchUserState(m *irc.Message) (*twitchUserState, error) {
var (
color, _ = m.GetTag("color")
displayName, _ = m.GetTag("display-name")
emoteSets []string
rawSets, _ = m.GetTag("emote-sets")
)
if rawSets != "" {
emoteSets = strings.Split(rawSets, ",")
}
return &twitchUserState{
Badges: twitch.ParseBadgeLevels(m),
Color: color,
DisplayName: displayName,
EmoteSets: emoteSets,
}, nil
}
func (t *twitchUserStateStore) Get(channel string) *twitchUserState {
t.lock.RLock()
defer t.lock.RUnlock()
return t.states[channel]
}
func (t *twitchUserStateStore) Set(channel string, state *twitchUserState) {
t.lock.Lock()
defer t.lock.Unlock()
t.states[channel] = state
}