diff --git a/src/irc_link.py b/src/irc_link.py index 091087b..11c5d4d 100644 --- a/src/irc_link.py +++ b/src/irc_link.py @@ -102,7 +102,7 @@ async def initialize(): def disconnect(conn, event): logging.warn("Disconnected from IRC, reinitializing") teardown() - asyncio.create_task(initialize()) + if not conn.planned_disconnection: asyncio.create_task(initialize()) # TODO: do better thing conn.add_global_handler("welcome", connect) @@ -117,5 +117,7 @@ def setup(bot): asyncio.create_task(initialize()) def teardown(bot=None): - if global_conn: global_conn.disconnect() + if global_conn: + global_conn.planned_disconnection = True + global_conn.disconnect() if unlisten: unlisten() diff --git a/src/telephone.py b/src/telephone.py index ee8b3db..38c424d 100644 --- a/src/telephone.py +++ b/src/telephone.py @@ -126,7 +126,7 @@ class Telephone(commands.Cog): else: try: replying_to = await self.bot.get_guild(msg.reference.guild_id).get_channel(msg.reference.channel_id).fetch_message(msg.reference.message_id) - except discord.HTTPException: + except (discord.HTTPException, AttributeError): replying_to = None if replying_to: reply = (eventbus.AuthorInfo(replying_to.author.name, replying_to.author.id, str(replying_to.author.display_avatar.url), replying_to.author.bot), parse_formatting(self.bot, replying_to.content))