From 6a47be34bce7127af632180c025646403796619d Mon Sep 17 00:00:00 2001 From: prosolis <5590409+prosolis@users.noreply.github.com> Date: Fri, 5 Jun 2026 19:26:49 -0700 Subject: [PATCH] Honor IGNORED_BOTS env var: global sender ignore at dispatch IGNORED_BOTS was set in .env but never read by any code; only the URL-preview plugin filtered, and via a different unset var (URL_PREVIEW_IGNORE_USERS). Parse IGNORED_BOTS in NewRegistry and short-circuit DispatchMessage/DispatchReaction so ignored senders (e.g. @pete:parodia.dev) are dropped before any plugin runs. --- internal/bot/dispatch.go | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/internal/bot/dispatch.go b/internal/bot/dispatch.go index e1e4925..a2d2351 100644 --- a/internal/bot/dispatch.go +++ b/internal/bot/dispatch.go @@ -2,6 +2,8 @@ package bot import ( "log/slog" + "os" + "strings" "sync" "gogobee/internal/plugin" @@ -9,13 +11,24 @@ import ( // Registry manages plugin registration and event dispatch. type Registry struct { - mu sync.RWMutex - plugins []plugin.Plugin + mu sync.RWMutex + plugins []plugin.Plugin + ignoredBots map[string]struct{} } -// NewRegistry creates an empty plugin registry. +// NewRegistry creates an empty plugin registry. Senders listed in the +// IGNORED_BOTS env var (comma-separated full Matrix user IDs, e.g. +// "@pete:parodia.dev") are dropped before any plugin sees them. func NewRegistry() *Registry { - return &Registry{} + ignored := make(map[string]struct{}) + if raw := os.Getenv("IGNORED_BOTS"); raw != "" { + for _, u := range strings.Split(raw, ",") { + if u = strings.TrimSpace(u); u != "" { + ignored[u] = struct{}{} + } + } + } + return &Registry{ignoredBots: ignored} } // Register adds a plugin to the registry. @@ -42,6 +55,9 @@ func (r *Registry) Init() error { // DispatchMessage sends a message context to all plugins in order. func (r *Registry) DispatchMessage(ctx plugin.MessageContext) { + if _, ok := r.ignoredBots[string(ctx.Sender)]; ok { + return + } r.mu.RLock() defer r.mu.RUnlock() for _, p := range r.plugins { @@ -71,6 +87,9 @@ func (r *Registry) safeOnMessage(p plugin.Plugin, ctx plugin.MessageContext) { // DispatchReaction sends a reaction context to all plugins in order. func (r *Registry) DispatchReaction(ctx plugin.ReactionContext) { + if _, ok := r.ignoredBots[string(ctx.Sender)]; ok { + return + } r.mu.RLock() defer r.mu.RUnlock() for _, p := range r.plugins {