""" Plugin for dynamically aggregating help from all loaded plugins. """ import logging import simplematrixbotlib as botlib async def handle_command(room, message, bot, prefix, config): match = botlib.MessageMatch(room, message, bot, prefix) if not (match.is_not_from_this_bot() and match.prefix() and match.command("help")): return args = match.args() plugins = getattr(bot, "plugins", {}) if not plugins: await bot.api.send_text_message(room.room_id, "No plugins are currently loaded.") return # If a specific plugin is requested if args: plugin_name = args[0].strip() if plugin_name in plugins: plugin = plugins[plugin_name] help_html = getattr(plugin, "__help__", None) if help_html: await bot.api.send_markdown_message(room.room_id, help_html) else: # Fallback: docstring first line doc = getattr(plugin, "__doc__", "No description available.") first_line = doc.strip().split("\n")[0] if doc else "No description available." await bot.api.send_text_message( room.room_id, f"No detailed help for '{plugin_name}'. {first_line}" ) return else: await bot.api.send_text_message( room.room_id, f"Plugin '{plugin_name}' not found. Available: {', '.join(sorted(plugins.keys()))}" ) return # Aggregate help from all plugins help_parts = [] for pname in sorted(plugins.keys()): plugin = plugins[pname] help_html = getattr(plugin, "__help__", None) if help_html: help_parts.append(help_html) else: # Minimal fallback using docstring doc = getattr(plugin, "__doc__", "No description.") first_line = doc.strip().split("\n")[0] if doc else "No description." help_parts.append( f"
!{pname}

{first_line}

" ) # Append bot credits credits = """
🌟 Funguy Bot Credits

🧙‍♂️ Creator & Developer: HB is the author of 🍄Funguy Bot🍄. (@hashborgir:mozilla.org)
🚀 Development Context: Created during recovery from two-level cervical spinal surgery (CDA Cervical Discectomy and Disc Arthroplasty)

Join our Matrix Room: Self‑hosting | Security | Sysadmin | Homelab | Programming

""" help_parts.append(credits) master = "
🍄 Funguy Bot Commands (click to expand)
" master += "\n".join(help_parts) master += "
" await bot.api.send_markdown_message(room.room_id, master) logging.info("Sent dynamic help from %d plugins", len(plugins))