player: add inactivity timeout

This commit is contained in:
bain 2023-01-06 22:50:33 +01:00
parent 7c8c5da5b2
commit 45ad8d83f6
Signed by: bain
GPG key ID: 31F0F25E3BED0B9B

View file

@ -48,6 +48,8 @@ class Player:
async def run(self): async def run(self):
logger.info(f"{hash(self)} running player") logger.info(f"{hash(self)} running player")
self._running = True self._running = True
timeout = 60
while not self.queue.empty() and self.voice.is_connected() and self._running: while not self.queue.empty() and self.voice.is_connected() and self._running:
music = self.queue.pop() music = self.queue.pop()
if self._skip > 0: if self._skip > 0:
@ -77,6 +79,13 @@ class Player:
self.voice.stop() self.voice.stop()
self._skip -= 1 self._skip -= 1
break break
if len(self.voice.channel.members) < 2:
timeout -= 1
if timeout == 0:
logger.debug("player inactivity timeout")
self.stop()
else:
timeout = 60
await asyncio.sleep(1) await asyncio.sleep(1)
except CacheError: except CacheError:
await self.add_error(music) await self.add_error(music)