Add new node algo, NodeAlgorithm.by_players
This commit is contained in:
parent
3ef98104ce
commit
42dde4ce44
|
|
@ -35,11 +35,15 @@ class NodeAlgorithm(Enum):
|
|||
NodeAlgorithm.by_region returns a node based on its voice region,
|
||||
which the region is specified by the user in the method as an arg.
|
||||
This method will only work if you set a voice region when you create a node.
|
||||
|
||||
NodeAlgorithm.by_players return a nodes based on how many players it has.
|
||||
This algorithm prefers nodes with the least amount of players.
|
||||
"""
|
||||
|
||||
# We don't have to define anything special for these, since these just serve as flags
|
||||
by_ping = auto()
|
||||
by_region = auto()
|
||||
by_players = auto()
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.value
|
||||
|
|
@ -466,6 +466,10 @@ class NodePool:
|
|||
Use NodeAlgorithm.by_region if you want to get the best node
|
||||
based on the node's voice region. This method will only work
|
||||
if you set a voice region when you create a node.
|
||||
|
||||
Use NodeAlgorithm.by_players if you want to get the best node
|
||||
based on how players it has. This method will return a node with
|
||||
the least amount of players
|
||||
"""
|
||||
available_nodes = [node for node in cls._nodes.values() if node._available]
|
||||
|
||||
|
|
@ -476,6 +480,10 @@ class NodePool:
|
|||
tested_nodes = {node: node.latency for node in available_nodes}
|
||||
return min(tested_nodes, key=tested_nodes.get)
|
||||
|
||||
elif algorithm == NodeAlgorithm.by_players:
|
||||
tested_nodes = {node: len(node.players.keys()) for node in available_nodes}
|
||||
return min(tested_nodes, key=tested_nodes.get)
|
||||
|
||||
else:
|
||||
if voice_region == None:
|
||||
raise NodeException("You must specify a VoiceRegion in order to use this functionality.")
|
||||
|
|
|
|||
Loading…
Reference in New Issue