#!/usr/bin/env python import os import logging from dotenv import load_dotenv import simplematrixbotlib as botlib # Load environment variables from .env file load_dotenv() # Bot configuration settings MATRIX_URL = os.getenv("MATRIX_URL") MATRIX_USER = os.getenv("MATRIX_USER") MATRIX_PASS = os.getenv("MATRIX_PASS") ADMIN_USER = "@hashborgir:mozilla.org" PREFIX = '!' creds = botlib.Creds(MATRIX_URL, MATRIX_USER, MATRIX_PASS) bot = botlib.Bot(creds) # Setup logging logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s', level=logging.INFO) # Load plugins PLUGINS_DIR = "plugins" def load_plugins(): plugins = [] for plugin_file in os.listdir(PLUGINS_DIR): if plugin_file.endswith(".py"): plugin_name = os.path.splitext(plugin_file)[0] try: plugin_module = __import__(f"{PLUGINS_DIR}.{plugin_name}", fromlist=[""]) plugins.append(plugin_module) logging.info(f"Loaded plugin: {plugin_name}") except Exception as e: logging.error(f"Error loading plugin {plugin_name}: {e}") return plugins plugins = load_plugins() @bot.listener.on_message_event async def handle_commands(room, message): """ Function to handle incoming command messages. Args: room (Room): The Matrix room where the command was invoked. message (RoomMessage): The message object containing the command. Returns: None """ for plugin in plugins: await plugin.handle_command(room, message, bot, PREFIX) bot.run()