feat(agent): Allow boolean values for available param on @command

This commit is contained in:
Reinier van der Leer
2024-03-20 17:24:11 +01:00
parent e985f7c105
commit 1262b72f5c
2 changed files with 3 additions and 3 deletions

View File

@@ -25,7 +25,7 @@ def command(
enabled: Literal[True] | Callable[[Config], bool] = True,
disabled_reason: Optional[str] = None,
aliases: list[str] = [],
available: Literal[True] | Callable[[BaseAgent], bool] = True,
available: bool | Callable[[BaseAgent], bool] = True,
) -> Callable[[Callable[P, CO]], Callable[P, CO]]:
"""
The command decorator is used to create Command objects from ordinary functions.

View File

@@ -32,7 +32,7 @@ class Command:
enabled: Literal[True] | Callable[[Config], bool] = True,
disabled_reason: Optional[str] = None,
aliases: list[str] = [],
available: Literal[True] | Callable[[BaseAgent], bool] = True,
available: bool | Callable[[BaseAgent], bool] = True,
):
self.name = name
self.description = description
@@ -55,7 +55,7 @@ class Command:
)
raise RuntimeError(f"Command '{self.name}' is disabled")
if callable(self.available) and not self.available(agent):
if not self.available or callable(self.available) and not self.available(agent):
raise RuntimeError(f"Command '{self.name}' is not available")
return self.method(*args, **kwargs, agent=agent)