Fix correctness bugs found by code review

- 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"
This commit is contained in:
prosolis
2026-05-24 20:50:51 -07:00
parent 8c295d183b
commit 035089c159
5 changed files with 137 additions and 52 deletions

12
main.go
View File

@@ -43,13 +43,17 @@ func main() {
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)
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)