Files
FunguyBot/plugins/plugins.py
T

61 lines
2.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
This plugin lists all loaded plugins (from bot.plugins) inside a collapsible block,
and sends a separate alwaysvisible 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"<strong>[{plugin_name}.py]</strong>: {desc}")
active_count = len(plugin_items)
# 1) Alwaysvisible 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 = "<br>".join(plugin_items)
detail_msg = (
f"<details>"
f"<summary><strong>🔌 Plugin List 🔌<br>⤵︎ Click to expand</strong></summary>"
f"<br>{list_html}"
f"</details>"
)
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__ = """
<details>
<summary><strong>!plugins</strong> List active plugins</summary>
<p>Shows the total number of loaded plugins and a collapsible list with descriptions.</p>
</details>
"""