Updated player state fetching

This commit is contained in:
cloudwithax 2021-09-27 16:07:13 -04:00
parent 3d3ae879e5
commit a8314031b0
2 changed files with 12 additions and 11 deletions

View File

@ -12,7 +12,7 @@ from . import events
import discord import discord
from discord import VoiceProtocol, VoiceChannel from discord import VoiceProtocol, VoiceChannel
from discord.ext import commands from discord.ext import commands
from typing import Optional, Any, Union from typing import Dict, Optional, Any, Union
@ -49,18 +49,19 @@ class Player(VoiceProtocol):
@property @property
def position(self): def position(self):
if not self.is_playing: if not self.is_playing or not self._current:
return 0 return 0
if self._paused: if self.is_paused:
return min(self._position, self._current.length) return min(self._last_position, self._current.length)
position = round(self._position + ((time.time() * 1000) - self._last_update)) difference = (time.time() * 1000) - self._last_update
position = self._last_position + difference
if position > self._current.length: if position > self.current.length:
return 0 return 0
return position return min(position, self.current.length)
@property @property
def is_connected(self): def is_connected(self):
@ -89,10 +90,10 @@ class Player(VoiceProtocol):
async def _update_state(self, data: dict): async def _update_state(self, data: dict):
state = data.get('state') state: dict = data.get('state')
self._last_update = state.get('time') self._last_update = time.time() * 1000
self._is_connected = state.get('connected') self._is_connected = state.get('connected')
self._position = state.get('position') self._last_position = state.get('position')
async def _dispatch_voice_update(self) -> None: async def _dispatch_voice_update(self) -> None:

View File

@ -7,7 +7,7 @@ with open("README.md") as f:
setuptools.setup( setuptools.setup(
name="pomice", name="pomice",
author="cloudwithax", author="cloudwithax",
version="1.0.1", version="1.0.2",
url="https://github.com/cloudwithax/pomice", url="https://github.com/cloudwithax/pomice",
packages=setuptools.find_packages(), packages=setuptools.find_packages(),
license="GPL", license="GPL",