Revert property changes and fix bugs

This commit is contained in:
cloudwithax 2021-11-04 08:07:27 -04:00
parent a8fb8529c6
commit 43edfacda1
2 changed files with 25 additions and 35 deletions

View File

@ -109,20 +109,11 @@ class Node:
""""Property which returns whether this node is connected or not"""
return self._websocket is not None and not self._websocket.closed
@property
async def latency(self) -> int:
"""Property which returns the latency of the node in milliseconds"""
start_time = time.time()
await self.send(op="ping")
end_time = await self._bot.wait_for("node_ping")
return (end_time - start_time) * 1000
@property
async def stats(self) -> NodeStats:
"""Property which returns the node stats."""
await self.send(op="get-stats")
node_stats = await self._bot.wait_for("node_stats")
return node_stats
return self._stats
@property
def players(self) -> Dict[int, Player]:
@ -225,15 +216,15 @@ class Node:
return self
except aiohttp.WSServerHandshakeError:
raise NodeConnectionFailure(
f"The password for node '{self.identifier}' is invalid."
f"The password for node '{self._identifier}' is invalid."
)
except aiohttp.InvalidURL:
raise NodeConnectionFailure(
f"The URI for node '{self.identifier}' is invalid."
f"The URI for node '{self._identifier}' is invalid."
)
except socket.gaierror:
raise NodeConnectionFailure(
f"The node '{self.identifier}' failed to connect."
f"The node '{self._identifier}' failed to connect."
)
async def disconnect(self):

View File

@ -1,3 +1,20 @@
import random
import time
from typing import Union
from discord import AutoShardedClient, Client
from discord.ext.commands import AutoShardedBot, Bot
__all__ = [
"ClientType",
"ExponentialBackoff",
"NodeStats"
]
ClientType = Union[AutoShardedBot, AutoShardedClient, Bot, Client]
class ExponentialBackoff:
"""
The MIT License (MIT)
Copyright (c) 2015-present Rapptz
@ -18,24 +35,6 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
import random
import time
from typing import Union
from discord import AutoShardedClient, Client
from discord.ext.commands import AutoShardedBot, Bot
__all__ = [
"ClientType",
"ExponentialBackoff",
"NodeStats"
]
ClientType = Union[AutoShardedBot, AutoShardedClient, Bot, Client]
class ExponentialBackoff:
def __init__(self, base: int = 1, *, integral: bool = False) -> None:
self._base = base
@ -70,13 +69,13 @@ class NodeStats:
def __init__(self, data: dict) -> None:
memory = data.get("memory")
memory: dict = data.get("memory")
self.used = memory.get("used")
self.free = memory.get("free")
self.reservable = memory.get("reservable")
self.allocated = memory.get("allocated")
cpu = data.get("cpu")
cpu: dict = data.get("cpu")
self.cpu_cores = cpu.get("cores")
self.cpu_system_load = cpu.get("systemLoad")
self.cpu_process_load = cpu.get("lavalinkLoad")