Handle unknown exceptions in matrix bot

This commit is contained in:
git-bruh 2021-01-21 14:14:15 +05:30
parent 3dcc56c3a2
commit 032e996aa3
No known key found for this signature in database
GPG key ID: E1475C50075ADCE6

12
main.py
View file

@ -229,7 +229,9 @@ class DiscordClient(discord.ext.commands.Bot):
config["homeserver"], config["username"]
)
self.bg_task = self.loop.create_task(self.matrix_client.start(self))
self.bg_task = self.loop.create_task(
self.log_exceptions(self.matrix_client)
)
self.add_cogs()
@ -244,6 +246,14 @@ class DiscordClient(discord.ext.commands.Bot):
or str(channel_id) not in config["bridge"].keys():
return True
async def log_exceptions(self, matrix_client):
try:
return await matrix_client.start(self)
except Exception as e:
matrix_client.logger.warning(f"Unknown exception occurred: {e}")
await matrix_client.close()
async def on_ready(self):
for channel in config["bridge"].keys():
channel_store[channel] = self.get_channel(int(channel))