fix: Wormhole v3.4.2 — empty-prefix command filter bug

The v3.4.1 command filter used bot.get_context() to detect commands,
but an empty-string prefix ('') matched EVERY message, causing
ctx.valid to return True for any message whose first word happened
to be a registered command.  With enough built-in commands (help,
ping, info, set, etc.) this silently dropped most or all relay
traffic (total_messages stayed at 0).

Fix: require ctx.prefix to be truthy (non-empty) before skipping
a message as a command.  Empty-prefix matches are now ignored,
so only messages with a real prefix (!, @bot, etc.) are filtered.

Also re-added the empty-prefix warning to 'wh debug' output so
users know to clean up their bot prefix configuration.
This commit is contained in:
Viktor AI 2026-05-12 12:53:18 +00:00
parent 5ece19dae7
commit 9598f752c1
2 changed files with 15 additions and 5 deletions

View file

@ -1,6 +1,6 @@
{ {
"author": ["everestmcarthur"], "author": ["everestmcarthur"],
"install_msg": "Thanks for installing **Wormhole v3.4.1** — the ultimate cross-server relay!\n\nGet started: `[p]wh create <network-name>` then `[p]wh open <network-name>` in channels you want to link.\n\nNew in v3.4.1: Relay engine hardening — command filter uses Red's internal command resolution (no more dropped messages), top-level error handling, safer background loops.\n\nFull help: `[p]wh help` or `/wh help`", "install_msg": "Thanks for installing **Wormhole v3.4.2** — the ultimate cross-server relay!\n\nGet started: `[p]wh create <network-name>` then `[p]wh open <network-name>` in channels you want to link.\n\nNew in v3.4.2: Fixed empty-prefix bug that silently blocked all relay traffic. Command filter now correctly ignores empty-string prefixes. v3.4.1: Relay engine hardening — command filter uses Red's internal command resolution (no more dropped messages), top-level error handling, safer background loops.\n\nFull help: `[p]wh help` or `/wh help`",
"name": "Wormhole", "name": "Wormhole",
"disabled": false, "disabled": false,
"short": "The ultimate cross-server relay — hybrid commands, context menus, ToS, reports, mentions policy, 85+ commands.", "short": "The ultimate cross-server relay — hybrid commands, context menus, ToS, reports, mentions policy, 85+ commands.",

View file

@ -25,6 +25,10 @@ Phase 5.1: Relay engine hardening — replaced heuristic command filter with
Red's internal bot.get_context() (only real commands filtered), Red's internal bot.get_context() (only real commands filtered),
top-level try/except around entire relay chain, safe AFK/auto-response top-level try/except around entire relay chain, safe AFK/auto-response
calls, blackout loop no longer overrides manual freeze calls, blackout loop no longer overrides manual freeze
Phase 5.2: Fix empty-prefix bug — get_context() with an empty-string prefix
matched every message, silently blocking all relay traffic. Now
requires ctx.prefix to be non-empty before filtering. Re-added
empty-prefix warning to wh debug.
""" """
from __future__ import annotations from __future__ import annotations
@ -373,7 +377,7 @@ class _ReportModal(discord.ui.Modal, title="Report Message"):
class Wormhole(commands.Cog): class Wormhole(commands.Cog):
"""The ultimate cross-server relay: networks, DMs, starboard, auto-mod, invites, portals & more.""" """The ultimate cross-server relay: networks, DMs, starboard, auto-mod, invites, portals & more."""
__version__ = "3.4.1" __version__ = "3.4.2"
def __init__(self, bot: Red): def __init__(self, bot: Red):
self.bot = bot self.bot = bot
@ -3650,7 +3654,11 @@ class Wormhole(commands.Cog):
if isinstance(pfx, str): pfx = [pfx] if isinstance(pfx, str): pfx = [pfx]
pfx_display = [f"`{p}`" if p.strip() else f"`(empty)`" for p in pfx[:5]] pfx_display = [f"`{p}`" if p.strip() else f"`(empty)`" for p in pfx[:5]]
lines.append(f"\n**Prefixes:** {', '.join(pfx_display)}") lines.append(f"\n**Prefixes:** {', '.join(pfx_display)}")
lines.append("**Command filter:** `bot.get_context()` — only registered commands are skipped") empty_pfx = any(p == "" for p in pfx)
if empty_pfx:
lines.append("⚠️ **Empty prefix detected!** Messages matching commands via the empty prefix "
"may be incorrectly filtered. Use `[p]set prefix` to remove it.")
lines.append("**Command filter:** `bot.get_context()` — only prefixed commands are skipped")
await ctx.send(embed=info_embed("\n".join(lines), title="🔧 Wormhole Debug")) await ctx.send(embed=info_embed("\n".join(lines), title="🔧 Wormhole Debug"))
@ -3685,11 +3693,13 @@ class Wormhole(commands.Cog):
# ── COMMAND FILTERING ─────────────────────────────────────────────── # ── COMMAND FILTERING ───────────────────────────────────────────────
# Use Red's internal command resolution — only skip messages that are # Use Red's internal command resolution — only skip messages that are
# actual registered bot commands. No prefix guessing or heuristics. # actual registered bot commands with a real (non-empty) prefix.
# An empty-string prefix matches every message, so we must ignore it
# to avoid silently dropping all relay traffic.
if message.content: if message.content:
try: try:
ctx = await self.bot.get_context(message) ctx = await self.bot.get_context(message)
if ctx.valid: if ctx.valid and ctx.prefix:
return return
except Exception: except Exception:
pass pass