feat: refactor enum models

This commit is contained in:
NiceAesth 2024-02-23 13:55:38 +02:00
parent 41f656a113
commit c492ba556d
1 changed files with 50 additions and 61 deletions

View File

@ -1,5 +1,5 @@
import re import re
from enum import Enum from enum import Enum, unique
from enum import IntEnum from enum import IntEnum
__all__ = ( __all__ = (
@ -15,7 +15,8 @@ __all__ = (
) )
class SearchType(Enum): @unique
class SearchType(str, Enum):
""" """
The enum for the different search types for Pomice. The enum for the different search types for Pomice.
This feature is exclusively for the Spotify search feature of Pomice. This feature is exclusively for the Spotify search feature of Pomice.
@ -35,11 +36,9 @@ class SearchType(Enum):
ytmsearch = "ytmsearch" ytmsearch = "ytmsearch"
scsearch = "scsearch" scsearch = "scsearch"
def __str__(self) -> str:
return self.value
@unique
class TrackType(Enum): class TrackType(str, Enum):
""" """
The enum for the different track types for Pomice. The enum for the different track types for Pomice.
@ -64,11 +63,9 @@ class TrackType(Enum):
HTTP = "http" HTTP = "http"
LOCAL = "local" LOCAL = "local"
def __str__(self) -> str:
return self.value
@unique
class PlaylistType(Enum): class PlaylistType(str, Enum):
""" """
The enum for the different playlist types for Pomice. The enum for the different playlist types for Pomice.
@ -87,11 +84,9 @@ class PlaylistType(Enum):
SPOTIFY = "spotify" SPOTIFY = "spotify"
APPLE_MUSIC = "apple_music" APPLE_MUSIC = "apple_music"
def __str__(self) -> str:
return self.value
@unique
class NodeAlgorithm(Enum): class NodeAlgorithm(str, Enum):
""" """
The enum for the different node algorithms in Pomice. The enum for the different node algorithms in Pomice.
@ -111,11 +106,9 @@ class NodeAlgorithm(Enum):
by_ping = "BY_PING" by_ping = "BY_PING"
by_players = "BY_PLAYERS" by_players = "BY_PLAYERS"
def __str__(self) -> str:
return self.value
@unique
class LoopMode(Enum): class LoopMode(str, Enum):
""" """
The enum for the different loop modes. The enum for the different loop modes.
This feature is exclusively for the queue utility of pomice. This feature is exclusively for the queue utility of pomice.
@ -124,18 +117,15 @@ class LoopMode(Enum):
LoopMode.TRACK sets the queue loop to the current track. LoopMode.TRACK sets the queue loop to the current track.
LoopMode.QUEUE sets the queue loop to the whole queue. LoopMode.QUEUE sets the queue loop to the whole queue.
""" """
# We don't have to define anything special for these, since these just serve as flags # We don't have to define anything special for these, since these just serve as flags
TRACK = "track" TRACK = "track"
QUEUE = "queue" QUEUE = "queue"
def __str__(self) -> str:
return self.value
@unique
class RouteStrategy(Enum): class RouteStrategy(str, Enum):
""" """
The enum for specifying the route planner strategy for Lavalink. The enum for specifying the route planner strategy for Lavalink.
This feature is exclusively for the RoutePlanner class. This feature is exclusively for the RoutePlanner class.
@ -153,7 +143,6 @@ class RouteStrategy(Enum):
RouteStrategy.ROTATING_NANO_SWITCH specifies that the node is switching RouteStrategy.ROTATING_NANO_SWITCH specifies that the node is switching
between IPs every CPU clock cycle and is rotating between IP blocks on between IPs every CPU clock cycle and is rotating between IP blocks on
ban. ban.
""" """
ROTATE_ON_BAN = "RotatingIpRoutePlanner" ROTATE_ON_BAN = "RotatingIpRoutePlanner"
@ -162,7 +151,8 @@ class RouteStrategy(Enum):
ROTATING_NANO_SWITCH = "RotatingNanoIpRoutePlanner" ROTATING_NANO_SWITCH = "RotatingNanoIpRoutePlanner"
class RouteIPType(Enum): @unique
class RouteIPType(str, Enum):
""" """
The enum for specifying the route planner IP block type for Lavalink. The enum for specifying the route planner IP block type for Lavalink.
This feature is exclusively for the RoutePlanner class. This feature is exclusively for the RoutePlanner class.
@ -177,9 +167,43 @@ class RouteIPType(Enum):
IPV6 = "Inet6Address" IPV6 = "Inet6Address"
@unique
class LogLevel(IntEnum):
"""
The enum for specifying the logging level within Pomice.
This class serves as shorthand for logging.<level>
This enum is exclusively for the logging feature in Pomice.
If you are not using this feature, this class is not necessary.
LogLevel.DEBUG sets the logging level to "debug".
LogLevel.INFO sets the logging level to "info".
LogLevel.WARN sets the logging level to "warn".
LogLevel.ERROR sets the logging level to "error".
LogLevel.CRITICAL sets the logging level to "CRITICAL".
"""
DEBUG = 10
INFO = 20
WARN = 30
ERROR = 40
CRITICAL = 50
@classmethod
def from_str(cls, level_str):
try:
return cls[level_str.upper()]
except KeyError:
raise ValueError(f"No such log level: {level_str}")
class URLRegex: class URLRegex:
""" """
The enum for all the URL Regexes in use by Pomice. The class for all the URL Regexes in use by Pomice.
URLRegex.SPOTIFY_URL returns the Spotify URL Regex. URLRegex.SPOTIFY_URL returns the Spotify URL Regex.
@ -196,7 +220,6 @@ class URLRegex:
URLRegex.SOUNDCLOUD_URL returns the SoundCloud URL Regex. URLRegex.SOUNDCLOUD_URL returns the SoundCloud URL Regex.
URLRegex.BASE_URL returns the standard URL Regex. URLRegex.BASE_URL returns the standard URL Regex.
""" """
SPOTIFY_URL = re.compile( SPOTIFY_URL = re.compile(
@ -246,37 +269,3 @@ class URLRegex:
LAVALINK_SEARCH = re.compile(r"(?P<type>ytm?|sc)search:") LAVALINK_SEARCH = re.compile(r"(?P<type>ytm?|sc)search:")
BASE_URL = re.compile(r"https?://(?:www\.)?.+") BASE_URL = re.compile(r"https?://(?:www\.)?.+")
class LogLevel(IntEnum):
"""
The enum for specifying the logging level within Pomice.
This class serves as shorthand for logging.<level>
This enum is exclusively for the logging feature in Pomice.
If you are not using this feature, this class is not necessary.
LogLevel.DEBUG sets the logging level to "debug".
LogLevel.INFO sets the logging level to "info".
LogLevel.WARN sets the logging level to "warn".
LogLevel.ERROR sets the logging level to "error".
LogLevel.CRITICAL sets the logging level to "CRITICAL".
"""
DEBUG = 10
INFO = 20
WARN = 30
ERROR = 40
CRITICAL = 50
@classmethod
def from_str(cls, level_str):
try:
return cls[level_str.upper()]
except KeyError:
raise ValueError(f"No such log level: {level_str}")