diff --git a/pomice/models/__init__.py b/pomice/models/__init__.py new file mode 100644 index 0000000..7653113 --- /dev/null +++ b/pomice/models/__init__.py @@ -0,0 +1,6 @@ +import pydantic +from pydantic import ConfigDict + + +class BaseModel(pydantic.BaseModel): + model_config = ConfigDict(populate_by_name=True) diff --git a/pomice/models/version.py b/pomice/models/version.py new file mode 100644 index 0000000..6ea8bff --- /dev/null +++ b/pomice/models/version.py @@ -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 diff --git a/pomice/player.py b/pomice/player.py index e062456..73a5ec0 100644 --- a/pomice/player.py +++ b/pomice/player.py @@ -30,7 +30,7 @@ from .objects import Playlist from .objects import Track from .pool import Node from .pool import NodePool -from pomice.utils import LavalinkVersion +from pomice.models.version import LavalinkVersion if TYPE_CHECKING: from discord.types.voice import VoiceServerUpdate diff --git a/pomice/pool.py b/pomice/pool.py index 64564af..8494730 100644 --- a/pomice/pool.py +++ b/pomice/pool.py @@ -20,16 +20,13 @@ import aiohttp import orjson as json from discord import Client from discord.ext import commands -from discord.utils import MISSING from websockets import client from websockets import exceptions -from websockets import typing as wstype from . import __version__ from . import applemusic from . import spotify from .enums import * -from .enums import LogLevel from .exceptions import InvalidSpotifyClientAuthorization from .exceptions import LavalinkVersionIncompatible from .exceptions import NodeConnectionFailure @@ -43,9 +40,9 @@ from .objects import Playlist from .objects import Track from .routeplanner import RoutePlanner from .utils import ExponentialBackoff -from .utils import LavalinkVersion from .utils import NodeStats from .utils import Ping +from pomice.models.version import LavalinkVersion if TYPE_CHECKING: from .player import Player diff --git a/pomice/utils.py b/pomice/utils.py index e18b937..9eed7eb 100644 --- a/pomice/utils.py +++ b/pomice/utils.py @@ -8,7 +8,6 @@ from typing import Any from typing import Callable from typing import Dict from typing import Iterable -from typing import NamedTuple from typing import Optional from .enums import RouteIPType @@ -20,7 +19,6 @@ __all__ = ( "FailingIPBlock", "RouteStats", "Ping", - "LavalinkVersion", ) @@ -226,53 +224,3 @@ class Ping: s_runtime = 1000 * (cost_time) 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)