Skip to content

Route

Base classes

Name Children Inherits
Generic
typing
Abstract base class for generic types.

⋔ Inheritance diagram

graph TD
  1363218654["router.Route"]
  3481597255["typing.Generic"]
  2751680898["builtins.object"]
  3481597255 --> 1363218654
  2751680898 --> 3481597255

🛈 DocStrings

Route configuration.

Source code in src/slashed/router.py
@dataclass
class Route[TContext]:
    """Route configuration."""

    prefix: str
    """Route prefix without @ symbol"""

    context: TContext
    """Context for this route"""

    description: str
    """Route description"""

    allowed_commands: set[str] | None = None
    """Optional set of allowed commands for this route"""

    def can_execute(self, command: str) -> bool:
        """Check if command is allowed for this route.

        Args:
            command: Command name to check

        Returns:
            True if command is allowed, False otherwise
        """
        return not self.allowed_commands or command in self.allowed_commands

allowed_commands class-attribute instance-attribute

allowed_commands: set[str] | None = None

Optional set of allowed commands for this route

context instance-attribute

context: TContext

Context for this route

description instance-attribute

description: str

Route description

prefix instance-attribute

prefix: str

Route prefix without @ symbol

can_execute

can_execute(command: str) -> bool

Check if command is allowed for this route.

Parameters:

Name Type Description Default
command str

Command name to check

required

Returns:

Type Description
bool

True if command is allowed, False otherwise

Source code in src/slashed/router.py
def can_execute(self, command: str) -> bool:
    """Check if command is allowed for this route.

    Args:
        command: Command name to check

    Returns:
        True if command is allowed, False otherwise
    """
    return not self.allowed_commands or command in self.allowed_commands

:fa-brands-github: Show source on GitHub