跳转至

saya

CommandSchema dataclass 🔗

Bases: BaseSchema

命令监听 Schema, 相当于 commander.command

Source code in src/graia/ariadne/message/commander/saya.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
@dataclass
class CommandSchema(BaseSchema):
    """命令监听 Schema, 相当于 commander.command"""

    command: str
    settings: Dict[str, Union[Slot, Arg]] = field(default_factory=dict)
    dispatchers: List[BaseDispatcher] = field(default_factory=list)
    decorators: List[Decorator] = field(default_factory=list)
    priority: int = 16

    def register(self, func: Callable, commander: Commander):
        """注册 func 至 commander

        Args:
            func (Callable): 命令函数
            commander (Commander): 命令对象
        """
        commander.command(self.command, self.settings, self.dispatchers, self.decorators, self.priority)(func)

register 🔗

register(func: Callable, commander: Commander)

注册 func 至 commander

Parameters:

Source code in src/graia/ariadne/message/commander/saya.py
23
24
25
26
27
28
29
30
def register(self, func: Callable, commander: Commander):
    """注册 func 至 commander

    Args:
        func (Callable): 命令函数
        commander (Commander): 命令对象
    """
    commander.command(self.command, self.settings, self.dispatchers, self.decorators, self.priority)(func)

CommanderBehaviour 🔗

Bases: Behaviour

命令行为

Source code in src/graia/ariadne/message/commander/saya.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class CommanderBehaviour(Behaviour):
    """命令行为"""

    def __init__(self, commander: Commander) -> None:
        self.commander = commander

    def allocate(self, cube: Cube[CommandSchema]):
        if not isinstance(cube.metaclass, CommandSchema):
            return
        cube.metaclass.register(cube.content, self.commander)
        return True

    def release(self, cube: Cube[CommandSchema]):
        if not isinstance(cube.metaclass, CommandSchema):
            return
        for entry in self.commander.entries:
            if entry.callable is cube.content:
                self.commander.entries.remove(entry)  # refs buried in MatchNode should be released
                break

        return True

    uninstall = release  # FIXME: backward compatibility