A matterbridge bot that detects music links (Spotify, YouTube, Apple Music, etc.) in chat messages and responds with equivalent links on other platforms. Features: - Connects to matterbridge via WebSocket API - Detects links from 7 music services (Spotify, YouTube, Apple, Deezer, etc.) - Uses idonthavespotify API for conversion (no API credentials required) - Automatic reconnection with exponential backoff - Platform setup guide for NixOS deployment Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
// Package config handles configuration loading and validation.
|
|
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/BurntSushi/toml"
|
|
)
|
|
|
|
// Config holds the complete application configuration.
|
|
type Config struct {
|
|
Matterbridge MatterbridgeConfig `toml:"matterbridge"`
|
|
}
|
|
|
|
// MatterbridgeConfig holds matterbridge connection settings.
|
|
type MatterbridgeConfig struct {
|
|
URL string `toml:"url"` // WebSocket URL, e.g., "ws://localhost:4242/api/websocket"
|
|
Token string `toml:"token"` // API token for authentication
|
|
Gateway string `toml:"gateway"` // Gateway name to send messages to
|
|
Username string `toml:"username"` // Bot username shown in messages
|
|
Avatar string `toml:"avatar"` // Avatar URL for the bot
|
|
}
|
|
|
|
// Load reads and parses a TOML configuration file.
|
|
func Load(path string) (*Config, error) {
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("reading config file: %w", err)
|
|
}
|
|
|
|
var cfg Config
|
|
if err := toml.Unmarshal(data, &cfg); err != nil {
|
|
return nil, fmt.Errorf("parsing config file: %w", err)
|
|
}
|
|
|
|
if err := cfg.Validate(); err != nil {
|
|
return nil, fmt.Errorf("validating config: %w", err)
|
|
}
|
|
|
|
return &cfg, nil
|
|
}
|
|
|
|
// Validate checks that required configuration fields are set.
|
|
func (c *Config) Validate() error {
|
|
if c.Matterbridge.URL == "" {
|
|
return fmt.Errorf("matterbridge.url is required")
|
|
}
|
|
if c.Matterbridge.Gateway == "" {
|
|
return fmt.Errorf("matterbridge.gateway is required")
|
|
}
|
|
if c.Matterbridge.Username == "" {
|
|
c.Matterbridge.Username = "MusicLink"
|
|
}
|
|
return nil
|
|
}
|