Improve reloading on config change

This commit is contained in:
Fjerkroa Auto 2023-03-29 17:26:43 +02:00
parent e6d13afcca
commit cceb0e3ea3

View File

@ -40,16 +40,18 @@ class FjerkroaBot(commands.Bot):
@classmethod
def load_config(self, config_file: str = "config.toml"):
logging.info(f"config file {config_file} changed, reloading.")
with open(config_file, encoding='utf-8') as file:
return toml.load(file)
def on_config_file_modified(self, event):
if event.src_path == self.config_file:
self.config = self.load_config(self.config_file)
self.airesponder.config = self.config
for responder in self.aichannels.values():
responder.config = self.config
new_config = self.load_config(self.config_file)
if repr(new_config) != repr(self.config):
logging.info(f"config file {self.config_file} changed, reloading.")
self.config = new_config
self.airesponder.config = self.config
for responder in self.aichannels.values():
responder.config = self.config
async def on_ready(self):
print(f"We have logged in as {self.user}")