Files
Sneedchat-Discord-Bridge-Go/config/config.go
Salastil f954771c0c
All checks were successful
Build & Release / build-latest (push) Successful in 9m53s
Build & Release / version-release (push) Has been skipped
Added a MediaUploadService option to the configuration loader and documented it in the README so operators can pick the attachment backend (defaulting to Litterbox) straight from .env.
Refactored the Discord bridge to build a media service during initialization, route attachment uploads through it, and dynamically label the status embeds and error diagnostics based on the selected provider while preserving the existing progress messaging flow.

Introduced a new media package that defines the uploader interface and ships a Litterbox implementation responsible for fetching Discord attachments and posting them to Catbox while reporting HTTP status codes back to the bridge.
2025-11-18 17:33:42 -05:00

56 lines
1.4 KiB
Go

package config
import (
"fmt"
"log"
"os"
"strconv"
"github.com/joho/godotenv"
)
type Config struct {
DiscordBotToken string
DiscordChannelID string
DiscordGuildID string
DiscordWebhookURL string
SneedchatRoomID int
MediaUploadService string
BridgeUsername string
BridgePassword string
BridgeUserID int
DiscordPingUserID string
Debug bool
}
func Load(envFile string) (*Config, error) {
if err := godotenv.Load(envFile); err != nil {
log.Printf("Warning: error loading %s: %v", envFile, err)
}
cfg := &Config{
DiscordBotToken: os.Getenv("DISCORD_BOT_TOKEN"),
DiscordChannelID: os.Getenv("DISCORD_CHANNEL_ID"),
DiscordGuildID: os.Getenv("DISCORD_GUILD_ID"),
DiscordWebhookURL: os.Getenv("DISCORD_WEBHOOK_URL"),
MediaUploadService: os.Getenv("MEDIA_UPLOAD_SERVICE"),
BridgeUsername: os.Getenv("BRIDGE_USERNAME"),
BridgePassword: os.Getenv("BRIDGE_PASSWORD"),
DiscordPingUserID: os.Getenv("DISCORD_PING_USER_ID"),
}
if cfg.MediaUploadService == "" {
cfg.MediaUploadService = "litterbox"
}
roomID, err := strconv.Atoi(os.Getenv("SNEEDCHAT_ROOM_ID"))
if err != nil {
return nil, fmt.Errorf("invalid SNEEDCHAT_ROOM_ID: %w", err)
}
cfg.SneedchatRoomID = roomID
if v := os.Getenv("BRIDGE_USER_ID"); v != "" {
cfg.BridgeUserID, _ = strconv.Atoi(v)
}
if os.Getenv("DEBUG") == "1" || os.Getenv("DEBUG") == "true" {
cfg.Debug = true
}
return cfg, nil
}