Wire Matrix messages to the *arr clients. Dispatcher parses "<prefix><cmd> <query>", routes movie/tv/music to Radarr/Sonarr/Lidarr, adds the top hit, and replies in a thread. Unconfigured services reply with a clear message instead of failing.
63 lines
1.3 KiB
Go
63 lines
1.3 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)
|
|
}
|
|
|
|
dispatcher := bot.New(cfg.Matrix.CommandPrefix, services, mx)
|
|
mx.SetMessageHandler(dispatcher.Handle)
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
mx.Start(ctx)
|
|
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()
|
|
}
|