refactor(handlers): refactor COMMAND attribute as property
This commit is contained in:
parent
7c3b7e578c
commit
e6dfafb8c7
@ -21,7 +21,16 @@ class AbstractCommandHandler(ABC):
|
||||
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
|
||||
def get_filters(self) -> Filter:
|
||||
|
@ -19,14 +19,11 @@ class AICommandHandler(AbstractCommandHandler):
|
||||
and returns the generated response.
|
||||
|
||||
Attributes:
|
||||
COMMAND (`str`): The name of the command that this handler handles.
|
||||
logger (`Logger`): Logger instance for logging events.
|
||||
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:
|
||||
"""
|
||||
Initializes the AICommandHandler.
|
||||
@ -37,6 +34,16 @@ class AICommandHandler(AbstractCommandHandler):
|
||||
"""
|
||||
self.logger: Logger = logger
|
||||
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:
|
||||
"""
|
||||
|
@ -29,9 +29,6 @@ class VideoCommandHandler(AbstractCommandHandler):
|
||||
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
|
||||
LANGUAGE_ALIASES: dict[str, list[str]] = {
|
||||
"en": ["en", "eng", "english"],
|
||||
@ -61,6 +58,16 @@ class VideoCommandHandler(AbstractCommandHandler):
|
||||
`pyrogram.filters.Filter`: A Pyrogram filter matching the /video 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:
|
||||
"""
|
||||
|
@ -27,9 +27,6 @@ class VoiceCommandHandler(AbstractCommandHandler):
|
||||
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
|
||||
LANGUAGE_ALIASES: dict[str, list[str]] = {
|
||||
"en": ["en", "eng", "english"],
|
||||
@ -50,6 +47,16 @@ class VoiceCommandHandler(AbstractCommandHandler):
|
||||
logger (`Logger`): Logger instance for logging events.
|
||||
"""
|
||||
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:
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user