59 lines
2.0 KiB
Python
59 lines
2.0 KiB
Python
"""
|
||
This plugin provides a command to list all loaded plugins along with their descriptions.
|
||
"""
|
||
|
||
# plugins/plugins.py
|
||
|
||
import os
|
||
import sys
|
||
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")
|
||
plugin_descriptions = get_plugin_descriptions()
|
||
|
||
plugin_descriptions.insert(0, "<details><summary><strong>🔌Plugins List🔌<br>⤵︎Click Here to Expand⤵︎</strong></summary>")
|
||
plugins_message = "<br>".join(plugin_descriptions)
|
||
plugins_message += "</details>"
|
||
|
||
await bot.api.send_markdown_message(room.room_id, plugins_message)
|
||
logging.info("Sent plugin list to the room")
|
||
|
||
|
||
def get_plugin_descriptions():
|
||
plugin_descriptions = []
|
||
for module_name, module in sys.modules.items():
|
||
if module_name.startswith("plugins.") and hasattr(module, "__file__"):
|
||
plugin_path = module.__file__
|
||
plugin_name = os.path.basename(plugin_path).split(".")[0]
|
||
|
||
if hasattr(module, "__description__"):
|
||
description = module.__description__
|
||
elif module.__doc__:
|
||
description = module.__doc__.strip().split("\n")[0]
|
||
else:
|
||
description = "No description available"
|
||
|
||
plugin_descriptions.append(f"<strong>[{plugin_name}.py]:</strong> {description}")
|
||
|
||
plugin_descriptions.sort()
|
||
return plugin_descriptions
|
||
|
||
|
||
# ---------------------------------------------------------------------------
|
||
# Plugin Metadata
|
||
# ---------------------------------------------------------------------------
|
||
|
||
__version__ = "1.0.0"
|
||
__author__ = "Funguy Bot"
|
||
__description__ = "List all loaded plugins"
|
||
__help__ = """
|
||
<details>
|
||
<summary><strong>!plugins</strong> – List loaded plugins</summary>
|
||
<p>Displays all currently loaded plugins and their descriptions.</p>
|
||
</details>
|
||
"""
|