feat: added web server with currently playing song

This commit is contained in:
Felipe M 2025-05-13 12:27:01 +02:00
parent 1a4986f294
commit 7f16452a99
Signed by: fmartingr
GPG key ID: CCFBC5637D4000A8
12 changed files with 847 additions and 9 deletions

View file

@ -2,6 +2,7 @@ package commands
import (
"fmt"
"sync"
"discord-jukebox-bot/pkg/config"
"discord-jukebox-bot/pkg/discord"
@ -10,6 +11,12 @@ import (
"github.com/bwmarrin/discordgo"
)
// Store a reference to the jukebox player for external access
var (
jukeboxPlayer *discord.JukeboxPlayer
jukeboxPlayerLock sync.RWMutex
)
// Setup sets up all commands for the Discord bot
func Setup(cfg *config.Config) (*discord.Bot, error) {
// Create the Subsonic client
@ -32,6 +39,11 @@ func Setup(cfg *config.Config) (*discord.Bot, error) {
if jukebox == nil {
return nil, fmt.Errorf("error creating jukebox player")
}
// Store the jukebox player reference
jukeboxPlayerLock.Lock()
jukeboxPlayer = jukebox
jukeboxPlayerLock.Unlock()
// Add any additional command initialization here
// This is where you can easily add new commands in the future
@ -51,4 +63,11 @@ func RegisterCustomCommand(
// Register the command handler
bot.RegisterCommand(name, handler)
return nil
}
// GetJukebox returns the current jukebox player instance
func GetJukebox() *discord.JukeboxPlayer {
jukeboxPlayerLock.RLock()
defer jukeboxPlayerLock.RUnlock()
return jukeboxPlayer
}