refactor(handlers): refactor COMMAND attribute as property

This commit is contained in:
parent 7c3b7e578c
commit e6dfafb8c7
4 changed files with 41 additions and 11 deletions

View File

@ -21,7 +21,16 @@ class AbstractCommandHandler(ABC):
COMMAND (`str`): The name of the command that this handler handles. COMMAND (`str`): The name of the command that this handler handles.
""" """
COMMAND: str = "" @property
@abstractmethod
def COMMAND(self) -> str:
"""
The name of the command that this handler handles.
Returns:
str: The command name.
"""
pass
@abstractmethod @abstractmethod
def get_filters(self) -> Filter: def get_filters(self) -> Filter:

View File

@ -19,14 +19,11 @@ class AICommandHandler(AbstractCommandHandler):
and returns the generated response. and returns the generated response.
Attributes: Attributes:
COMMAND (`str`): The name of the command that this handler handles.
logger (`Logger`): Logger instance for logging events. logger (`Logger`): Logger instance for logging events.
gigachat_client (`GigaChatClient`): Client for interacting with the GigaChat API. gigachat_client (`GigaChatClient`): Client for interacting with the GigaChat API.
COMMAND (`str`): The name of the command that this handler handles.
""" """
# The name of the command that this handler handles
COMMAND: str = "ai"
def __init__(self, logger: Logger, gigachat_client: GigaChatClient) -> None: def __init__(self, logger: Logger, gigachat_client: GigaChatClient) -> None:
""" """
Initializes the AICommandHandler. Initializes the AICommandHandler.
@ -38,6 +35,16 @@ class AICommandHandler(AbstractCommandHandler):
self.logger: Logger = logger self.logger: Logger = logger
self.gigachat_client: GigaChatClient = gigachat_client self.gigachat_client: GigaChatClient = gigachat_client
@property
def COMMAND(self) -> str:
"""
The name of the command that this handler handles.
Returns:
str: The command name.
"""
return "ai"
def get_filters(self) -> Filter: def get_filters(self) -> Filter:
""" """
Returns the filter for the /ai command. Returns the filter for the /ai command.

View File

@ -29,9 +29,6 @@ class VideoCommandHandler(AbstractCommandHandler):
logger (`Logger`): Logger instance for logging events. logger (`Logger`): Logger instance for logging events.
""" """
# The name of the command that this handler handles
COMMAND: str = "video"
# Mapping of language codes to their aliases # Mapping of language codes to their aliases
LANGUAGE_ALIASES: dict[str, list[str]] = { LANGUAGE_ALIASES: dict[str, list[str]] = {
"en": ["en", "eng", "english"], "en": ["en", "eng", "english"],
@ -62,6 +59,16 @@ class VideoCommandHandler(AbstractCommandHandler):
""" """
return filters.command(self.COMMAND) return filters.command(self.COMMAND)
@property
def COMMAND(self) -> str:
"""
The name of the command that this handler handles.
Returns:
str: The command name.
"""
return "video"
async def handle(self, client: Client, message: Message) -> None: async def handle(self, client: Client, message: Message) -> None:
""" """
Handles the /video command. Handles the /video command.

View File

@ -27,9 +27,6 @@ class VoiceCommandHandler(AbstractCommandHandler):
logger (`Logger`): Logger instance for logging events. logger (`Logger`): Logger instance for logging events.
""" """
# The name of the command that this handler handles
COMMAND: str = "voice"
# Mapping of language codes to their aliases # Mapping of language codes to their aliases
LANGUAGE_ALIASES: dict[str, list[str]] = { LANGUAGE_ALIASES: dict[str, list[str]] = {
"en": ["en", "eng", "english"], "en": ["en", "eng", "english"],
@ -51,6 +48,16 @@ class VoiceCommandHandler(AbstractCommandHandler):
""" """
self.logger: Logger = logger self.logger: Logger = logger
@property
def COMMAND(self) -> str:
"""
The name of the command that this handler handles.
Returns:
str: The command name.
"""
return "voice"
def get_filters(self) -> Filter: def get_filters(self) -> Filter:
""" """
Returns the filter for the /voice command. Returns the filter for the /voice command.