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!
This commit is contained in:
Joscha 2017-09-04 16:32:32 +00:00
parent 1c3b9d0a20
commit b8bb75a897
3 changed files with 10 additions and 7 deletions

View file

@ -33,6 +33,8 @@ class Connection:
Returns the task listening for packets, or None if the attempt failed. 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() await self.stop()
tries_left = max_tries tries_left = max_tries
@ -147,7 +149,7 @@ class Connection:
#else: #else:
#logger.debug(f"Deleting task: {task}") #logger.debug(f"Deleting task: {task}")
#self._spawned_tasks = tasks #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): def _wait_for_response(self, pid):
future = asyncio.Future() future = asyncio.Future()

View file

@ -113,9 +113,9 @@ class Controller:
async def stop(self): async def stop(self):
if self.room: if self.room:
logger.info(f"&{self.room.roomname}: Stopping") logger.info(f"@{self.nick}: Stopping")
await self.room.stop() await self.room.stop()
logger.debug(f"&{self.room.roomname}: Stopped. Deleting room") logger.debug(f"@{self.nick}: Stopped. Deleting room")
self.room = None self.room = None
async def set_nick(self, nick): async def set_nick(self, nick):

View file

@ -53,13 +53,14 @@ class Room:
async def _run(self, task, max_tries=10, delay=60): async def _run(self, task, max_tries=10, delay=60):
while not self._stopping: while not self._stopping:
await task if task.done():
await self.controller.on_disconnected()
task = await self._conn.connect(max_tries=max_tries, delay=delay) task = await self._conn.connect(max_tries=max_tries, delay=delay)
if not task: if not task:
return return
await task
await self.controller.on_disconnected()
self.stopping = False self.stopping = False
async def stop(self): async def stop(self):