package config import ( "fmt" "log" "os" "strconv" "github.com/joho/godotenv" ) // Config holds all configuration for the pure Matrix Appservice ↔ Sneedchat bridge. type Config struct { // --- Sneedchat --- SneedchatRoomID int // numeric Siropu/Sneedchat room ID BridgeUsername string // XenForo username used to authenticate BridgePassword string // XenForo password BridgeUserID int // numeric XenForo user_id (optional, used for echo-suppression) Debug bool // verbose logging // --- Matrix Appservice --- MatrixAppserviceToken string // token used to authenticate HS → AS MatrixGhostUserDomain string // domain for generated ghost MXIDs MatrixGhostUserPrefix string // prefix for ghost MXIDs ("" = none) AppserviceListenAddr string // HTTP listen address, e.g. ":29333" } // Load loads all settings from .env into a Config struct. func Load(envFile string) (*Config, error) { if err := godotenv.Load(envFile); err != nil { log.Printf("⚠️ Warning: could not load %s: %v", envFile, err) } cfg := &Config{ // Sneedchat credentials BridgeUsername: getenv("BRIDGE_USERNAME", ""), BridgePassword: getenv("BRIDGE_PASSWORD", ""), // Matrix Appservice fields MatrixAppserviceToken: getenv("MATRIX_APPSERVICE_TOKEN", ""), MatrixGhostUserDomain: getenv("MATRIX_GHOST_USER_DOMAIN", "sneedchat.kiwifarms.net"), MatrixGhostUserPrefix: getenv("MATRIX_GHOST_USER_PREFIX", ""), // Appservice listen address AppserviceListenAddr: getenv("APPSERVICE_LISTEN_ADDR", ":29333"), } // Debug flag switch v := getenv("DEBUG", ""); v { case "1", "true", "TRUE", "True": cfg.Debug = true } // Required Sneedchat room ID roomRaw := getenv("SNEEDCHAT_ROOM_ID", "") roomID, err := strconv.Atoi(roomRaw) if err != nil { return nil, fmt.Errorf("invalid SNEEDCHAT_ROOM_ID: %s", roomRaw) } cfg.SneedchatRoomID = roomID // Optional: user ID for echo suppression if v := getenv("BRIDGE_USER_ID", ""); v != "" { id, _ := strconv.Atoi(v) cfg.BridgeUserID = id } return cfg, nil } // getenv returns environment variable k or default def. func getenv(k, def string) string { if v := os.Getenv(k); v != "" { return v } return def }