Config refactor. Plugins now using config

This commit is contained in:
Hash Borgir
2024-02-14 00:12:40 -07:00
parent 2277dd1b90
commit bb331092d0
17 changed files with 33 additions and 877 deletions

View File

@@ -20,10 +20,11 @@ class FunguyConfig(botlib.Config):
# Load configuration from file
self.load_toml(config_file)
logging.info("Loaded configuration from funguy.conf")
logging.info(f"Loaded configuration from {config_file}")
_admin_user: str = ""
_prefix: str = ""
_config_file: str= ""
# Define getters and setters for custom configuration options
@property
@@ -42,6 +43,15 @@ class FunguyConfig(botlib.Config):
def prefix(self, value):
self._prefix = value
@property
def config_file(self):
return self._config_file
@config_file.setter
def config_file(self, value):
self._config_file = value
# Method to load configuration from file
def load_config(self, config_file):
"""
@@ -53,8 +63,9 @@ class FunguyConfig(botlib.Config):
Returns:
None
"""
self.__init__()
logging.info("Loaded configuration from funguy.conf")
self.load_toml(config_file)
logging.info(f"Loaded configuration from {config_file}")
# Method to save configuration to file
def save_config(self, config_file):
@@ -68,9 +79,9 @@ class FunguyConfig(botlib.Config):
None
"""
self.save_toml(config_file)
logging.info("Saved configuration to funguy.conf")
logging.info(f"Saved configuration to {config_file}")
async def handle_command(room, message, bot, PREFIX, config):
async def handle_command(room, message, bot, prefix, config):
"""
Function to handle commands related to bot configuration.
@@ -84,7 +95,7 @@ async def handle_command(room, message, bot, PREFIX, config):
Returns:
None
"""
match = botlib.MessageMatch(room, message, bot, PREFIX)
match = botlib.MessageMatch(room, message, bot, prefix)
if match.is_not_from_this_bot() and match.prefix() and match.command("set"):
args = match.args()
if len(args) != 2:
@@ -113,10 +124,13 @@ async def handle_command(room, message, bot, PREFIX, config):
else:
await bot.api.send_text_message(room.room_id, "Invalid configuration option")
elif match.is_not_from_this_bot() and match.prefix() and match.command("save"):
config.save_config("funguy.conf")
config.load_config("funguy.conf")
await bot.api.send_text_message(room.room_id, "Configuration saved & reloaded")
elif match.is_not_from_this_bot() and match.prefix() and match.command("saveconf"):
config.save_config(config.config_file)
await bot.api.send_text_message(room.room_id, "Configuration saved")
elif match.is_not_from_this_bot() and match.prefix() and match.command("loadconf"):
config.load_config(config.config_file)
await bot.api.send_text_message(room.room_id, "Configuration loaded")
elif match.is_not_from_this_bot() and match.prefix() and match.command("show"):
admin_user = config.admin_user