Testing configuration changes/updates
This commit is contained in:
58
funguy.py
58
funguy.py
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
# bot.py
|
||||
# funguy.py
|
||||
|
||||
import os
|
||||
import logging
|
||||
@@ -8,26 +8,12 @@ import simplematrixbotlib as botlib
|
||||
from dotenv import load_dotenv
|
||||
import time
|
||||
import sys
|
||||
|
||||
# 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)
|
||||
from plugins.config import FunguyConfig
|
||||
|
||||
# Setup logging
|
||||
logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s', level=logging.INFO)
|
||||
|
||||
# Load plugins
|
||||
# Load plugins (defined before plugin load/reload functions)
|
||||
PLUGINS_DIR = "plugins"
|
||||
PLUGINS = {}
|
||||
|
||||
@@ -51,19 +37,53 @@ def reload_plugins():
|
||||
del sys.modules[plugin_name]
|
||||
load_plugins()
|
||||
|
||||
def rehash_config(config):
|
||||
del config
|
||||
config = FunguyConfig()
|
||||
|
||||
|
||||
# Load environment variables from .env file
|
||||
load_dotenv()
|
||||
|
||||
# Load plugins
|
||||
load_plugins()
|
||||
|
||||
# Bot configuration settings
|
||||
MATRIX_URL = os.getenv("MATRIX_URL")
|
||||
MATRIX_USER = os.getenv("MATRIX_USER")
|
||||
MATRIX_PASS = os.getenv("MATRIX_PASS")
|
||||
|
||||
# Get credentials from env
|
||||
creds = botlib.Creds(MATRIX_URL, MATRIX_USER, MATRIX_PASS)
|
||||
|
||||
# Bot configuration
|
||||
config = FunguyConfig()
|
||||
bot = botlib.Bot(creds, config)
|
||||
|
||||
PREFIX = config.prefix
|
||||
|
||||
@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:
|
||||
if str(message.sender) == config.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)
|
||||
await plugin_module.handle_command(room, message, bot, PREFIX, config)
|
||||
|
||||
|
||||
if match.is_not_from_this_bot() and match.prefix() and match.command("rehash"):
|
||||
if str(message.sender) == config.admin_user:
|
||||
rehash_config(config)
|
||||
await bot.api.send_text_message(room.room_id, "Config rehashed")
|
||||
else:
|
||||
await bot.api.send_text_message(room.room_id, "You are not authorized to reload plugins.")
|
||||
|
||||
|
||||
|
||||
|
||||
bot.run()
|
||||
|
Reference in New Issue
Block a user