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.
56 lines
1.4 KiB
Go
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
|
|
}
|