Improve reloading on config change
This commit is contained in:
parent
e6d13afcca
commit
cceb0e3ea3
@ -40,16 +40,18 @@ class FjerkroaBot(commands.Bot):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load_config(self, config_file: str = "config.toml"):
|
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:
|
with open(config_file, encoding='utf-8') as file:
|
||||||
return toml.load(file)
|
return toml.load(file)
|
||||||
|
|
||||||
def on_config_file_modified(self, event):
|
def on_config_file_modified(self, event):
|
||||||
if event.src_path == self.config_file:
|
if event.src_path == self.config_file:
|
||||||
self.config = self.load_config(self.config_file)
|
new_config = self.load_config(self.config_file)
|
||||||
self.airesponder.config = self.config
|
if repr(new_config) != repr(self.config):
|
||||||
for responder in self.aichannels.values():
|
logging.info(f"config file {self.config_file} changed, reloading.")
|
||||||
responder.config = self.config
|
self.config = new_config
|
||||||
|
self.airesponder.config = self.config
|
||||||
|
for responder in self.aichannels.values():
|
||||||
|
responder.config = self.config
|
||||||
|
|
||||||
async def on_ready(self):
|
async def on_ready(self):
|
||||||
print(f"We have logged in as {self.user}")
|
print(f"We have logged in as {self.user}")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user