From b8bb75a89706f83131bda8c3ced09f264ecabd32 Mon Sep 17 00:00:00 2001 From: Joscha Date: Mon, 4 Sep 2017 16:32:32 +0000 Subject: [PATCH] Fix previous "lingering bot" bug When using !spawnevil on @TestSummoner, the @TestSpawn which was created would reconnect to the room because of faulty logic in room._run(). This would cause a few errors to occur. Fixed now! --- yaboli/connection.py | 4 +++- yaboli/controller.py | 4 ++-- yaboli/room.py | 9 +++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/yaboli/connection.py b/yaboli/connection.py index cba46bb..b0a108d 100644 --- a/yaboli/connection.py +++ b/yaboli/connection.py @@ -33,6 +33,8 @@ class Connection: Returns the task listening for packets, or None if the attempt failed. """ + logger.debug(f"Attempting to connect, max_tries={max_tries}") + await self.stop() tries_left = max_tries @@ -147,7 +149,7 @@ class Connection: #else: #logger.debug(f"Deleting task: {task}") #self._spawned_tasks = tasks - #self._spawned_tasks = {task for task in self._spawned_tasks if not task.done()} # TODO: Reenable + self._spawned_tasks = {task for task in self._spawned_tasks if not task.done()} # TODO: Reenable def _wait_for_response(self, pid): future = asyncio.Future() diff --git a/yaboli/controller.py b/yaboli/controller.py index 97e626f..062c7a0 100644 --- a/yaboli/controller.py +++ b/yaboli/controller.py @@ -113,9 +113,9 @@ class Controller: async def stop(self): if self.room: - logger.info(f"&{self.room.roomname}: Stopping") + logger.info(f"@{self.nick}: Stopping") await self.room.stop() - logger.debug(f"&{self.room.roomname}: Stopped. Deleting room") + logger.debug(f"@{self.nick}: Stopped. Deleting room") self.room = None async def set_nick(self, nick): diff --git a/yaboli/room.py b/yaboli/room.py index 3d90c25..ad9e32f 100644 --- a/yaboli/room.py +++ b/yaboli/room.py @@ -53,12 +53,13 @@ class Room: async def _run(self, task, max_tries=10, delay=60): while not self._stopping: + if task.done(): + task = await self._conn.connect(max_tries=max_tries, delay=delay) + if not task: + return + await task await self.controller.on_disconnected() - - task = await self._conn.connect(max_tries=max_tries, delay=delay) - if not task: - return self.stopping = False