player: add inactivity timeout
This commit is contained in:
parent
7c8c5da5b2
commit
45ad8d83f6
1 changed files with 9 additions and 0 deletions
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue