<commit_before>package media

import (
	"encoding/json"

	"github.com/gempir/gempbot/internal/helixclient"
	"github.com/gempir/gempbot/internal/log"
	"github.com/gempir/gempbot/internal/store"
	"github.com/google/uuid"
	"github.com/puzpuzpuz/xsync"
)

type PlayerState string

const (
	PLAYING PlayerState = "PLAYING"
	PAUSED  PlayerState = "PAUSED"
)

type MEDIA_TYPE string

const (
	MEDIA_TYPE_YOUTUBE MEDIA_TYPE = "youtube"
)

type DebugMessage struct {
	Action  string `json:"string"`
	Message string `json:"message"`
}

type MediaManager struct {
	db          store.Store
	helixClient helixclient.Client
	rooms       *xsync.MapOf[string, *Room]
	connections *xsync.MapOf[string, *Connection]
}

type Connection struct {
	id     string
	writer func(message []byte)
}

type Room struct {
	MediaType MEDIA_TYPE
	Url       string
	Time      float32
	State     PlayerState
	users     *xsync.MapOf[string, *Connection]
}

func NewMediaManager(db store.Store, helixClient helixclient.Client) *MediaManager {
	return &MediaManager{
		db:          db,
		helixClient: helixClient,
		rooms:       xsync.NewMapOf[*Room](),
		connections: xsync.NewMapOf[*Connection](),
	}
}

func (m *MediaManager) HandleJoin(connectionId string, userID string, channel string) {
	var joinChannelId string
	if channel == "" {
		joinChannelId = userID
	} else {
		res, err := m.helixClient.GetUserByUsername(channel)
		if err != nil {
			return
		}
		joinChannelId = res.ID
	}

	connection, ok := m.connections.Load(connectionId)
	if !ok {
		return
	}

	room, ok := m.rooms.Load(joinChannelId)
	if !ok {<commit_msg>interface<commit_after>package media

import (
	"encoding/json"

	"github.com/gempir/gempbot/internal/helixclient"
	"github.com/gempir/gempbot/internal/log"
	"github.com/google/uuid"
	"github.com/puzpuzpuz/xsync"
)

type PlayerState string

const (
	PLAYING PlayerState = "PLAYING"
	PAUSED  PlayerState = "PAUSED"
)

type MEDIA_TYPE string

const (
	MEDIA_TYPE_YOUTUBE MEDIA_TYPE = "youtube"
)

type DebugMessage struct {
	Action  string `json:"string"`
	Message string `json:"message"`
}

type MediaManager struct {
	storage     storage
	helixClient helixclient.Client
	rooms       *xsync.MapOf[string, *Room]
	connections *xsync.MapOf[string, *Connection]
}

type Connection struct {
	id     string
	writer func(message []byte)
}

type Room struct {
	MediaType MEDIA_TYPE
	Url       string
	Time      float32
	State     PlayerState
	users     *xsync.MapOf[string, *Connection]
}

type storage interface {
}

func NewMediaManager(storage storage, helixClient helixclient.Client) *MediaManager {
	return &MediaManager{
		storage:     storage,
		helixClient: helixClient,
		rooms:       xsync.NewMapOf[*Room](),
		connections: xsync.NewMapOf[*Connection](),
	}
}

func (m *MediaManager) HandleJoin(connectionId string, userID string, channel string) {
	var joinChannelId string
	if channel == "" {
		joinChannelId = userID
	} else {
		res, err := m.helixClient.GetUserByUsername(channel)
		if err != nil {
			return
		}
		joinChannelId = res.ID
	}

	connection, ok := m.connections.Load(connectionId)
	if !ok {
		return
	}

	room, ok := m.rooms.Load(joinChannelId)
	if !ok {
{'fraction_non_alphanumeric': 0.10777496839443743, 'fraction_numerical': 0.0012642225031605564, 'mean_word_length': 3.9921135646687698, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6927377', 'n_tokens_mistral': 1156, 'n_tokens_neox': 1094, 'n_words': 248}