"""
This plugin lists all loaded plugins (from bot.plugins) inside a collapsible block,
and sends a separate always‑visible line showing the total active count.
"""
import logging
import simplematrixbotlib as botlib
async def handle_command(room, message, bot, prefix, config):
match = botlib.MessageMatch(room, message, bot, prefix)
if match.is_not_from_this_bot() and match.prefix() and match.command("plugins"):
logging.info("Received !plugins command")
# Fetch the real, currently loaded plugins from the bot instance
plugins_dict = getattr(bot, "plugins", {})
if not plugins_dict:
await bot.api.send_markdown_message(room.room_id, "📊 **Total Active Plugins:** 0")
return
# Build sorted list of descriptions
plugin_items = []
for plugin_name, module in sorted(plugins_dict.items()):
desc = getattr(module, "__description__", None)
if not desc and module.__doc__:
desc = module.__doc__.strip().split("\n")[0]
desc = desc or "No description available"
plugin_items.append(f"[{plugin_name}.py]: {desc}")
active_count = len(plugin_items)
# 1) Always‑visible count
count_msg = f"📊 **Total Active Plugins:** {active_count}"
await bot.api.send_markdown_message(room.room_id, count_msg)
# 2) Collapsible list
list_html = " ".join(plugin_items)
detail_msg = (
f""
f"🔌 Plugin List 🔌 ⤵︎ Click to expand"
f" {list_html}"
f""
)
await bot.api.send_markdown_message(room.room_id, detail_msg)
logging.info(f"Sent plugin list ({active_count} active) to room {room.room_id}")
# ---------------------------------------------------------------------------
# Plugin Metadata
# ---------------------------------------------------------------------------
__version__ = "1.0.4"
__author__ = "Funguy Bot"
__description__ = "List all loaded plugins with count, collapsible"
__help__ = """
!plugins – List active plugins
Shows the total number of loaded plugins and a collapsible list with descriptions.