feat: move version model

This commit is contained in:
NiceAesth 2024-02-23 12:52:55 +02:00
parent d27f95a863
commit 3657c28495
5 changed files with 35 additions and 57 deletions

View File

@ -0,0 +1,6 @@
import pydantic
from pydantic import ConfigDict
class BaseModel(pydantic.BaseModel):
model_config = ConfigDict(populate_by_name=True)

27
pomice/models/version.py Normal file
View File

@ -0,0 +1,27 @@
from typing import NamedTuple
class LavalinkVersion(NamedTuple):
major: int
minor: int
fix: int
def __eq__(self, other: object) -> bool:
if not isinstance(other, LavalinkVersion):
return False
return (
(self.major == other.major) and (self.minor == other.minor) and (self.fix == other.fix)
)
def __lt__(self, other: object) -> bool:
if not isinstance(other, LavalinkVersion):
return False
if self.major > other.major:
return False
if self.minor > other.minor:
return False
if self.fix > other.fix:
return False
return True

View File

@ -30,7 +30,7 @@ from .objects import Playlist
from .objects import Track from .objects import Track
from .pool import Node from .pool import Node
from .pool import NodePool from .pool import NodePool
from pomice.utils import LavalinkVersion from pomice.models.version import LavalinkVersion
if TYPE_CHECKING: if TYPE_CHECKING:
from discord.types.voice import VoiceServerUpdate from discord.types.voice import VoiceServerUpdate

View File

@ -20,16 +20,13 @@ import aiohttp
import orjson as json import orjson as json
from discord import Client from discord import Client
from discord.ext import commands from discord.ext import commands
from discord.utils import MISSING
from websockets import client from websockets import client
from websockets import exceptions from websockets import exceptions
from websockets import typing as wstype
from . import __version__ from . import __version__
from . import applemusic from . import applemusic
from . import spotify from . import spotify
from .enums import * from .enums import *
from .enums import LogLevel
from .exceptions import InvalidSpotifyClientAuthorization from .exceptions import InvalidSpotifyClientAuthorization
from .exceptions import LavalinkVersionIncompatible from .exceptions import LavalinkVersionIncompatible
from .exceptions import NodeConnectionFailure from .exceptions import NodeConnectionFailure
@ -43,9 +40,9 @@ from .objects import Playlist
from .objects import Track from .objects import Track
from .routeplanner import RoutePlanner from .routeplanner import RoutePlanner
from .utils import ExponentialBackoff from .utils import ExponentialBackoff
from .utils import LavalinkVersion
from .utils import NodeStats from .utils import NodeStats
from .utils import Ping from .utils import Ping
from pomice.models.version import LavalinkVersion
if TYPE_CHECKING: if TYPE_CHECKING:
from .player import Player from .player import Player

View File

@ -8,7 +8,6 @@ from typing import Any
from typing import Callable from typing import Callable
from typing import Dict from typing import Dict
from typing import Iterable from typing import Iterable
from typing import NamedTuple
from typing import Optional from typing import Optional
from .enums import RouteIPType from .enums import RouteIPType
@ -20,7 +19,6 @@ __all__ = (
"FailingIPBlock", "FailingIPBlock",
"RouteStats", "RouteStats",
"Ping", "Ping",
"LavalinkVersion",
) )
@ -226,53 +224,3 @@ class Ping:
s_runtime = 1000 * (cost_time) s_runtime = 1000 * (cost_time)
return s_runtime return s_runtime
class LavalinkVersion(NamedTuple):
major: int
minor: int
fix: int
def __eq__(self, other: object) -> bool:
if not isinstance(other, LavalinkVersion):
return False
return (
(self.major == other.major) and (self.minor == other.minor) and (self.fix == other.fix)
)
def __ne__(self, other: object) -> bool:
if not isinstance(other, LavalinkVersion):
return False
return not (self == other)
def __lt__(self, other: object) -> bool:
if not isinstance(other, LavalinkVersion):
return False
if self.major > other.major:
return False
if self.minor > other.minor:
return False
if self.fix > other.fix:
return False
return True
def __gt__(self, other: object) -> bool:
if not isinstance(other, LavalinkVersion):
return False
return not (self < other)
def __le__(self, other: object) -> bool:
if not isinstance(other, LavalinkVersion):
return False
return (self < other) or (self == other)
def __ge__(self, other: object) -> bool:
if not isinstance(other, LavalinkVersion):
return False
return (self > other) or (self == other)