feat: use regex for version matching
This commit is contained in:
parent
a8a586bfb1
commit
9c262c7455
|
|
@ -50,6 +50,8 @@ __all__ = (
|
||||||
"NodePool",
|
"NodePool",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
VERSION_REGEX = re.compile(r"(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:[a-zA-Z0-9_-]+)?")
|
||||||
|
|
||||||
|
|
||||||
class Node:
|
class Node:
|
||||||
"""The base class for a node.
|
"""The base class for a node.
|
||||||
|
|
@ -244,15 +246,24 @@ class Node:
|
||||||
self._version = LavalinkVersion(major=4, minor=0, fix=0)
|
self._version = LavalinkVersion(major=4, minor=0, fix=0)
|
||||||
return
|
return
|
||||||
|
|
||||||
# this crazy ass line maps the split version string into
|
_version_rx = VERSION_REGEX.match(version)
|
||||||
# an iterable with ints instead of strings and then
|
if not _version_rx:
|
||||||
# turns that iterable into a tuple. yeah, i know
|
self._available = False
|
||||||
|
raise LavalinkVersionIncompatible(
|
||||||
|
"The Lavalink version you're using is incompatible. "
|
||||||
|
"Lavalink version 3.7.0 or above is required to use this library.",
|
||||||
|
)
|
||||||
|
|
||||||
split = tuple(map(int, tuple(version.split("."))))
|
_version_groups = _version_rx.groups()
|
||||||
self._version = LavalinkVersion(*split)
|
major, minor, fix = (
|
||||||
if not version.endswith("-SNAPSHOT") and (
|
int(_version_groups[0] or 0),
|
||||||
self._version.major == 3 and self._version.minor < 7
|
int(_version_groups[1] or 0),
|
||||||
):
|
int(_version_groups[2] or 0),
|
||||||
|
)
|
||||||
|
|
||||||
|
self._log.debug(f"Parsed Lavalink version: {major}.{minor}.{fix}")
|
||||||
|
self._version = LavalinkVersion(major=major, minor=minor, fix=fix)
|
||||||
|
if self._version < LavalinkVersion(3, 7, 0):
|
||||||
self._available = False
|
self._available = False
|
||||||
raise LavalinkVersionIncompatible(
|
raise LavalinkVersionIncompatible(
|
||||||
"The Lavalink version you're using is incompatible. "
|
"The Lavalink version you're using is incompatible. "
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue