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""" """"Property which returns whether this node is connected or not"""
return self._websocket is not None and not self._websocket.closed 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 @property
async def stats(self) -> NodeStats: async def stats(self) -> NodeStats:
"""Property which returns the node stats.""" """Property which returns the node stats."""
await self.send(op="get-stats") return self._stats
node_stats = await self._bot.wait_for("node_stats")
return node_stats
@property @property
def players(self) -> Dict[int, Player]: def players(self) -> Dict[int, Player]:
@ -225,15 +216,15 @@ class Node:
return self return self
except aiohttp.WSServerHandshakeError: except aiohttp.WSServerHandshakeError:
raise NodeConnectionFailure( raise NodeConnectionFailure(
f"The password for node '{self.identifier}' is invalid." f"The password for node '{self._identifier}' is invalid."
) )
except aiohttp.InvalidURL: except aiohttp.InvalidURL:
raise NodeConnectionFailure( raise NodeConnectionFailure(
f"The URI for node '{self.identifier}' is invalid." f"The URI for node '{self._identifier}' is invalid."
) )
except socket.gaierror: except socket.gaierror:
raise NodeConnectionFailure( raise NodeConnectionFailure(
f"The node '{self.identifier}' failed to connect." f"The node '{self._identifier}' failed to connect."
) )
async def disconnect(self): async def disconnect(self):

View File

@ -1,23 +1,3 @@
"""
The MIT License (MIT)
Copyright (c) 2015-present Rapptz
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
import random import random
import time import time
from typing import Union from typing import Union
@ -35,6 +15,25 @@ ClientType = Union[AutoShardedBot, AutoShardedClient, Bot, Client]
class ExponentialBackoff: class ExponentialBackoff:
"""
The MIT License (MIT)
Copyright (c) 2015-present Rapptz
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
def __init__(self, base: int = 1, *, integral: bool = False) -> None: def __init__(self, base: int = 1, *, integral: bool = False) -> None:
@ -70,13 +69,13 @@ class NodeStats:
def __init__(self, data: dict) -> None: def __init__(self, data: dict) -> None:
memory = data.get("memory") memory: dict = data.get("memory")
self.used = memory.get("used") self.used = memory.get("used")
self.free = memory.get("free") self.free = memory.get("free")
self.reservable = memory.get("reservable") self.reservable = memory.get("reservable")
self.allocated = memory.get("allocated") self.allocated = memory.get("allocated")
cpu = data.get("cpu") cpu: dict = data.get("cpu")
self.cpu_cores = cpu.get("cores") self.cpu_cores = cpu.get("cores")
self.cpu_system_load = cpu.get("systemLoad") self.cpu_system_load = cpu.get("systemLoad")
self.cpu_process_load = cpu.get("lavalinkLoad") self.cpu_process_load = cpu.get("lavalinkLoad")