# plugins/load_plugin.py import os import logging import importlib import simplematrixbotlib as botlib PLUGINS = {} async def load_plugin(plugin_name): try: module = importlib.import_module(f"plugins.{plugin_name}") PLUGINS[plugin_name] = module logging.info(f"Loaded plugin: {plugin_name}") return True except Exception as e: logging.error(f"Error loading plugin {plugin_name}: {e}") return False 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("load"): if str(message.sender) == config.admin_user: args = match.args() if len(args) != 1: await bot.api.send_text_message(room.room_id, "Usage: !load ") else: plugin_name = args[0] if plugin_name not in PLUGINS: success = await load_plugin(plugin_name) if success: await bot.api.send_text_message(room.room_id, f"Plugin '{plugin_name}' loaded successfully") else: await bot.api.send_text_message(room.room_id, f"Error loading plugin '{plugin_name}'") else: await bot.api.send_text_message(room.room_id, f"Plugin '{plugin_name}' is already loaded") else: await bot.api.send_text_message(room.room_id, "You are not authorized to load plugins.")