diff --git a/payphone/cogs/calls/cog.py b/payphone/cogs/calls/cog.py index 0575491..3716410 100644 --- a/payphone/cogs/calls/cog.py +++ b/payphone/cogs/calls/cog.py @@ -143,7 +143,10 @@ class Calls(base.Cog): await models.Message.bulk_create(message_rows, batch_size=500) break - except asyncpg.exceptions.DeadlockDetectedError: + except ( + asyncpg.exceptions.PostgresError, + asyncpg.exceptions.InterfaceError, + ): continue for _ in range(3): @@ -153,7 +156,10 @@ class Calls(base.Cog): ) break - except asyncpg.exceptions.DeadlockDetectedError: + except ( + asyncpg.exceptions.PostgresError, + asyncpg.exceptions.InterfaceError, + ): continue @commands.command(aliases=["c"]) @@ -950,13 +956,12 @@ class Calls(base.Cog): pass message_replies = await redis.hget( - constants.CALL_MESSAGE_REPLIES_TEMPLATE % channel.call_id, - message.id + constants.CALL_MESSAGE_REPLIES_TEMPLATE % channel.call_id, message.id ) if message_replies is None: return - + for message_id in message_replies.decode().split(","): try: await webhook.edit_message(message_id, embed=None) diff --git a/payphone/cogs/mods/cog.py b/payphone/cogs/mods/cog.py index 6227684..fbb2641 100644 --- a/payphone/cogs/mods/cog.py +++ b/payphone/cogs/mods/cog.py @@ -9,6 +9,7 @@ import discord from discord import errors from discord.ext import commands +import tortoise from tortoise import transactions, expressions from payphone import bot @@ -301,6 +302,8 @@ class Mods(base.Cog): await self.bot.get_cog("Calls").flush_messages() + await tortoise.Tortoise.close_connections() + await ctx.send("⚡ Messages were flushed, payphone will shut down.") sys.exit() diff --git a/payphone/db/setup.py b/payphone/db/setup.py index dcf9400..d821357 100644 --- a/payphone/db/setup.py +++ b/payphone/db/setup.py @@ -9,6 +9,8 @@ from payphone.core import config async def init() -> None: """Initialize the database and it's connections.""" + await tortoise.Tortoise.close_connections() + await tortoise.Tortoise.init(config.TORTOISE_ORM, use_tz=True) await tortoise.Tortoise.generate_schemas(safe=True)