Add forex plugin, stability fixes, and async HTTP dispatch

- Add forex plugin (Frankfurter v2 API) with rate lookups, analysis,
  DM-based alerts, and daily cron poll. Backfills 1 year of history
  on startup for moving averages and buy signal scoring.

- Fix bot hang caused by SQLite lock contention in reminder polling:
  rows cursor was held open while writing to the same DB. Collect
  results first, close cursor, then process. Same fix in milkcarton.

- Add sync retry loop so the bot reconnects after network drops
  instead of silently exiting. StopSync() for clean Ctrl+C shutdown.

- Add panic recovery to all dispatch, syncer, and cron paths.

- Make all HTTP-calling plugin commands async (goroutines) so a slow
  or dead external API cannot block the message dispatch pipeline.
  Affects: lookup, stocks, forex, anime, movies, concerts, gaming,
  retro, wotd, urls, howami.

- Extract DisplayName to Base, add db.Exec helper, convert silent
  error discards across the codebase.

- Fix UNO mercy-kill bug (eliminated bot continues playing), adventure
  DM nag spam, stats column mismatch, per-call regex/replacer allocs.

- Update README: forex commands, Finance section, 47 plugins.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
prosolis
2026-03-26 09:22:02 -07:00
parent c7c1b76589
commit 9c6ded13fa
68 changed files with 5784 additions and 724 deletions

View File

@@ -111,12 +111,8 @@ func (p *AnimePlugin) OnMessage(ctx MessageContext) error {
parts := strings.SplitN(args, " ", 2)
sub := strings.ToLower(parts[0])
// Subcommands that only touch the DB don't need async
switch sub {
case "watch":
if len(parts) < 2 || strings.TrimSpace(parts[1]) == "" {
return p.SendReply(ctx.RoomID, ctx.EventID, "Usage: !anime watch <title>")
}
return p.handleWatch(ctx, strings.TrimSpace(parts[1]))
case "watching":
return p.handleWatching(ctx)
case "unwatch":
@@ -124,13 +120,30 @@ func (p *AnimePlugin) OnMessage(ctx MessageContext) error {
return p.SendReply(ctx.RoomID, ctx.EventID, "Usage: !anime unwatch <id>")
}
return p.handleUnwatch(ctx, strings.TrimSpace(parts[1]))
case "season":
return p.handleSeason(ctx)
case "upcoming":
return p.handleUpcoming(ctx)
default:
return p.handleSearch(ctx, args)
}
// Subcommands that hit the Jikan API run async to avoid blocking dispatch
go func() {
var err error
switch sub {
case "watch":
if len(parts) < 2 || strings.TrimSpace(parts[1]) == "" {
err = p.SendReply(ctx.RoomID, ctx.EventID, "Usage: !anime watch <title>")
} else {
err = p.handleWatch(ctx, strings.TrimSpace(parts[1]))
}
case "season":
err = p.handleSeason(ctx)
case "upcoming":
err = p.handleUpcoming(ctx)
default:
err = p.handleSearch(ctx, args)
}
if err != nil {
slog.Error("anime: handler error", "err", err)
}
}()
return nil
}
// rateLimit enforces the 400ms delay between Jikan API calls.
@@ -166,8 +179,6 @@ func (p *AnimePlugin) jikanGet(apiURL string, target interface{}) error {
}
func (p *AnimePlugin) handleSearch(ctx MessageContext, query string) error {
d := db.Get()
// Search via API
encoded := url.QueryEscape(query)
apiURL := fmt.Sprintf("https://api.jikan.moe/v4/anime?q=%s&limit=3&sfw=true", encoded)
@@ -186,13 +197,11 @@ func (p *AnimePlugin) handleSearch(ctx MessageContext, query string) error {
// Cache the result
data, _ := json.Marshal(anime)
if _, err := d.Exec(
db.Exec("anime: cache write",
`INSERT INTO anime_cache (mal_id, data, cached_at) VALUES (?, ?, ?)
ON CONFLICT(mal_id) DO UPDATE SET data = ?, cached_at = ?`,
anime.MalID, string(data), time.Now().Unix(), string(data), time.Now().Unix(),
); err != nil {
slog.Error("anime: cache write", "err", err)
}
)
return p.SendReply(ctx.RoomID, ctx.EventID, p.formatAnime(anime))
}
@@ -293,7 +302,7 @@ func (p *AnimePlugin) handleWatch(ctx MessageContext, title string) error {
// Also cache the anime data
data, _ := json.Marshal(anime)
_, _ = d.Exec(
db.Exec("anime: cache watchlist entry",
`INSERT INTO anime_cache (mal_id, data, cached_at) VALUES (?, ?, ?)
ON CONFLICT(mal_id) DO UPDATE SET data = ?, cached_at = ?`,
anime.MalID, string(data), time.Now().Unix(), string(data), time.Now().Unix(),
@@ -514,7 +523,7 @@ func (p *AnimePlugin) PostDailyReleases(roomID id.RoomID) {
// Update cache
data, _ := json.Marshal(animeData)
_, _ = d.Exec(
db.Exec("anime: update daily cache",
`INSERT INTO anime_cache (mal_id, data, cached_at) VALUES (?, ?, ?)
ON CONFLICT(mal_id) DO UPDATE SET data = ?, cached_at = ?`,
entry.malID, string(data), time.Now().Unix(), string(data), time.Now().Unix(),