This commit is contained in:
2025-04-02 16:02:22 +03:00
parent 8810e12551
commit 1c6f896b73
5 changed files with 69 additions and 74 deletions
+17 -19
View File
@@ -51,23 +51,20 @@ class Router:
def input_command_handler(self, input_command: InputCommand):
input_command_name: str = input_command.get_trigger()
input_command_flags: InputFlags = input_command.get_input_flags()
for command_handler in self._command_handlers:
handle_command = command_handler.get_handled_command()
if input_command_name.lower() == handle_command.get_trigger().lower():
if handle_command.get_registered_flags():
if input_command_flags:
for flag in input_command_flags:
is_valid = handle_command.validate_input_flag(flag)
if not is_valid:
self._not_valid_flag_handler(flag)
return
if handle_command.get_registered_flags().get_flags():
if input_command_flags.get_flags():
if self._validate_input_flags(handle_command, input_command_flags):
command_handler.handling(input_command_flags)
return
else:
command_handler.handling(input_command_flags)
return
else:
command_handler.handling({})
return
else:
if input_command_flags:
if input_command_flags.get_flags():
self._not_valid_flag_handler(input_command_flags[0])
return
else:
@@ -75,6 +72,15 @@ class Router:
return
def _validate_input_flags(self, handle_command: Command, input_flags: InputFlags):
for flag in input_flags:
is_valid = handle_command.validate_input_flag(flag)
if not is_valid:
self._not_valid_flag_handler(flag)
return False
return True
@staticmethod
def _validate_command(command: Command):
command_name: str = command.get_trigger()
@@ -119,11 +125,3 @@ class Router:
def set_title(self, title: str):
self._title = title
def get_all_commands(self) -> list[str]:
all_commands: list[str] = []
for command_handler in self._command_handlers:
all_commands.append(command_handler.get_handled_command().get_trigger())
return all_commands