77 lines
1.7 KiB
Python
77 lines
1.7 KiB
Python
# =====IMPORTS=====
|
|
# Future imports
|
|
from __future__ import annotations
|
|
|
|
# Own imports
|
|
from .classes import RegularCommand, RegexCommand, Daemon, Default
|
|
|
|
# Typing imports
|
|
from typing import TYPE_CHECKING
|
|
|
|
if TYPE_CHECKING:
|
|
# Built-in imports
|
|
from typing import Union, List
|
|
|
|
|
|
def command(
|
|
cmd,
|
|
help_str: str = None,
|
|
alias: Union[str, List[str]] = None,
|
|
requires_prefix: bool = False,
|
|
) -> callable:
|
|
"""
|
|
Converts a method into a command by replacing it with a Command object.
|
|
|
|
Args:
|
|
cmd: keyword used to call this function
|
|
help_str: short description of the command
|
|
alias: alias(es) for the command
|
|
requires_prefix: defines wether the command needs the Frank prefix for
|
|
its aliases to work or not
|
|
"""
|
|
|
|
def inner(func):
|
|
return RegularCommand(func, cmd, help_str, aliases)
|
|
|
|
return inner
|
|
|
|
|
|
def regex_command(pattern: str, help_str: str = None) -> callable:
|
|
"""
|
|
Converts the method into a RegexCommand.
|
|
|
|
Args:
|
|
pattern: regex pattern to match command with
|
|
help_str: short description of the command
|
|
"""
|
|
|
|
def inner(func):
|
|
return RegexCommand(func, pattern, help_str)
|
|
|
|
return inner
|
|
|
|
|
|
def daemon(interval: Union[int, float] = 0) -> callable:
|
|
"""
|
|
Converts the method into a Daemon, which will then be run when the module
|
|
is started.
|
|
"""
|
|
|
|
def inner(func):
|
|
return Daemon(func, interval)
|
|
|
|
return inner
|
|
|
|
|
|
# TODO: make sure the default is unique
|
|
def default(help_str: str = None) -> callable:
|
|
"""
|
|
Converts the method into the Default method, making it the default command
|
|
when the module is run without a command.
|
|
"""
|
|
|
|
def inner(func):
|
|
return Default(func, help_str)
|
|
|
|
return inner
|