Rename bot.py to funguy.py
This commit is contained in:
parent
2518357745
commit
0c00cea070
64
funguy.py
Executable file
64
funguy.py
Executable file
@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env python
|
||||
# bot.py
|
||||
|
||||
import os
|
||||
import logging
|
||||
import importlib
|
||||
import simplematrixbotlib as botlib
|
||||
from dotenv import load_dotenv
|
||||
import time
|
||||
|
||||
# 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"
|
||||
PLUGINS = {}
|
||||
|
||||
def load_plugins():
|
||||
for plugin_file in os.listdir(PLUGINS_DIR):
|
||||
if plugin_file.endswith(".py"):
|
||||
plugin_name = os.path.splitext(plugin_file)[0]
|
||||
try:
|
||||
module = importlib.import_module(f"{PLUGINS_DIR}.{plugin_name}")
|
||||
PLUGINS[plugin_name] = module
|
||||
logging.info(f"Loaded plugin: {plugin_name}")
|
||||
except Exception as e:
|
||||
logging.error(f"Error loading plugin {plugin_name}: {e}")
|
||||
|
||||
def reload_plugins():
|
||||
global PLUGINS
|
||||
PLUGINS = {}
|
||||
load_plugins()
|
||||
|
||||
load_plugins()
|
||||
|
||||
@bot.listener.on_message_event
|
||||
async def handle_commands(room, message):
|
||||
match = botlib.MessageMatch(room, message, bot, PREFIX)
|
||||
if match.is_not_from_this_bot() and match.prefix() and match.command("reload"):
|
||||
if str(message.sender) == ADMIN_USER:
|
||||
reload_plugins()
|
||||
await bot.api.send_text_message(room.room_id, "Plugins reloaded successfully")
|
||||
else:
|
||||
await bot.api.send_text_message(room.room_id, "You are not authorized to reload plugins.")
|
||||
|
||||
for plugin_name, plugin_module in PLUGINS.items():
|
||||
await plugin_module.handle_command(room, message, bot, PREFIX)
|
||||
|
||||
bot.run()
|
Loading…
Reference in New Issue
Block a user