- matrix: drop cryptohelper LoginAs so device.json creds aren't invalidated on every restart by Init's re-login - matrix: thread ctx through PostThreadedReply; bot dispatcher derives per-command ctx from app lifecycle so SIGTERM cancels in-flight work - matrix: isTokenValid verifies /whoami user_id matches configured one - matrix: loadDevice distinguishes missing file from corrupt parse; refuse to silently overwrite a corrupt device.json - matrix: Start checks Syncer type assertion and returns error - arr: parseLookup skips empty-title items and extracts existing id - bot: skip Add when Result.Exists; reply "already in library"
67 lines
1.4 KiB
Go
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.yaml", "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()
|
|
}
|