Files
Bellhop/main.go
prosolis 8f38d3d9f4 Switch config format from YAML to TOML
Replaces gopkg.in/yaml.v3 with github.com/BurntSushi/toml. Updates
struct tags, default config path, Dockerfile CMD, README, and ships
config.example.toml in place of the YAML example. ${ENV_VAR}
expansion still runs on the raw file before parsing, so the behavior
is unchanged.
2026-05-24 21:05:41 -07:00

67 lines
1.4 KiB
Go

package main
import (
"context"
"flag"
"log/slog"
"os"
"os/signal"
"syscall"
"bellhop/internal/arr"
"bellhop/internal/bot"
"bellhop/internal/config"
"bellhop/internal/matrix"
)
func main() {
configPath := flag.String("config", "config.toml", "path to config file")
flag.Parse()
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelInfo})))
cfg, err := config.Load(*configPath)
if err != nil {
slog.Error("config load failed", "err", err)
os.Exit(1)
}
services := bot.Services{}
if cfg.Services.Radarr != nil {
services.Radarr = arr.NewRadarr(cfg.Services.Radarr)
}
if cfg.Services.Sonarr != nil {
services.Sonarr = arr.NewSonarr(cfg.Services.Sonarr)
}
if cfg.Services.Lidarr != nil {
services.Lidarr = arr.NewLidarr(cfg.Services.Lidarr)
}
mx, err := matrix.New(cfg.Matrix)
if err != nil {
slog.Error("matrix init failed", "err", err)
os.Exit(1)
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
dispatcher := bot.New(ctx, cfg.Matrix.CommandPrefix, services, mx)
mx.SetMessageHandler(dispatcher.Handle)
if err := mx.Start(ctx); err != nil {
slog.Error("matrix start failed", "err", err)
mx.Stop()
os.Exit(1)
}
slog.Info("bellhop started", "allowed_rooms", len(cfg.Matrix.AllowedRooms))
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
<-sig
slog.Info("shutting down")
cancel()
mx.Stop()
}