mirror of
https://github.com/prosolis/gogobee.git
synced 2026-07-16 08:52:42 +00:00
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:
@@ -31,9 +31,11 @@ func (r *Registry) Init() error {
|
||||
r.mu.RLock()
|
||||
defer r.mu.RUnlock()
|
||||
for _, p := range r.plugins {
|
||||
slog.Info("initializing plugin", "name", p.Name())
|
||||
if err := p.Init(); err != nil {
|
||||
return err
|
||||
}
|
||||
slog.Info("initialized plugin", "name", p.Name())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -43,12 +45,27 @@ func (r *Registry) DispatchMessage(ctx plugin.MessageContext) {
|
||||
r.mu.RLock()
|
||||
defer r.mu.RUnlock()
|
||||
for _, p := range r.plugins {
|
||||
if err := p.OnMessage(ctx); err != nil {
|
||||
slog.Error("plugin message handler error",
|
||||
r.safeOnMessage(p, ctx)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Registry) safeOnMessage(p plugin.Plugin, ctx plugin.MessageContext) {
|
||||
defer func() {
|
||||
if rec := recover(); rec != nil {
|
||||
slog.Error("plugin message handler panic",
|
||||
"plugin", p.Name(),
|
||||
"err", err,
|
||||
"panic", rec,
|
||||
"sender", ctx.Sender,
|
||||
"room", ctx.RoomID,
|
||||
"body", truncate(ctx.Body, 100),
|
||||
)
|
||||
}
|
||||
}()
|
||||
if err := p.OnMessage(ctx); err != nil {
|
||||
slog.Error("plugin message handler error",
|
||||
"plugin", p.Name(),
|
||||
"err", err,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,12 +74,27 @@ func (r *Registry) DispatchReaction(ctx plugin.ReactionContext) {
|
||||
r.mu.RLock()
|
||||
defer r.mu.RUnlock()
|
||||
for _, p := range r.plugins {
|
||||
if err := p.OnReaction(ctx); err != nil {
|
||||
slog.Error("plugin reaction handler error",
|
||||
r.safeOnReaction(p, ctx)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Registry) safeOnReaction(p plugin.Plugin, ctx plugin.ReactionContext) {
|
||||
defer func() {
|
||||
if rec := recover(); rec != nil {
|
||||
slog.Error("plugin reaction handler panic",
|
||||
"plugin", p.Name(),
|
||||
"err", err,
|
||||
"panic", rec,
|
||||
"sender", ctx.Sender,
|
||||
"room", ctx.RoomID,
|
||||
"emoji", ctx.Emoji,
|
||||
)
|
||||
}
|
||||
}()
|
||||
if err := p.OnReaction(ctx); err != nil {
|
||||
slog.Error("plugin reaction handler error",
|
||||
"plugin", p.Name(),
|
||||
"err", err,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,6 +109,13 @@ func (r *Registry) GetCommands() []plugin.CommandDef {
|
||||
return cmds
|
||||
}
|
||||
|
||||
func truncate(s string, n int) string {
|
||||
if len(s) <= n {
|
||||
return s
|
||||
}
|
||||
return s[:n] + "…"
|
||||
}
|
||||
|
||||
// GetPlugin returns a plugin by name.
|
||||
func (r *Registry) GetPlugin(name string) plugin.Plugin {
|
||||
r.mu.RLock()
|
||||
|
||||
Reference in New Issue
Block a user