File tree Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -72,3 +72,17 @@ Callbacks
72
72
73
73
:param node: The node that sent the statistics.
74
74
:type node: :class: `Node `
75
+
76
+ .. function :: on_node_ready()
77
+
78
+ Called when Lavalink node is ready.
79
+
80
+ :param node: The node that was ready.
81
+ :type node: :class: `Node `
82
+
83
+ .. function :: on_node_unavailable()
84
+
85
+ Called when Lavalink node becomes unavailable.
86
+
87
+ :param node: The node that became unavailable.
88
+ :type node: :class: `Node `
Original file line number Diff line number Diff line change @@ -759,7 +759,9 @@ async def _ws_listener(self) -> None:
759
759
760
760
if _type is aiohttp .WSMsgType .CLOSED :
761
761
self ._available = False
762
+ self ._client .dispatch ("node_unavailable" , self )
762
763
close_code = self ._ws .close_code
764
+ self ._ready .clear ()
763
765
self ._ws = None
764
766
765
767
wait_time = backoff .delay ()
Original file line number Diff line number Diff line change @@ -91,8 +91,8 @@ def label_to_node(cls) -> dict[str, Node[ClientT]]:
91
91
92
92
@classproperty
93
93
def nodes (cls ) -> list [Node [ClientT ]]:
94
- """Get the list of all nodes."""
95
- return list (cls ._nodes .values ())
94
+ """Get the list of all available nodes."""
95
+ return list (filter ( lambda n : n . available , cls ._nodes .values () ))
96
96
97
97
async def create_node (
98
98
self ,
@@ -366,7 +366,10 @@ def get_random_node(cls) -> Node[ClientT]:
366
366
ValueError
367
367
If there are no nodes.
368
368
"""
369
- if node := choice (list (cls ._nodes .values ())):
369
+ # It is a classproperty.
370
+ nodes = cast (list [Node [ClientT ]], cls .nodes ) # pyright: ignore # noqa: PGH003
371
+
372
+ if node := choice (nodes ):
370
373
return node
371
374
372
375
raise NoNodesAvailable
You can’t perform that action at this time.
0 commit comments