跳转至

saya

Ariadne 控制台对 Saya 封装的 Behaviour 与 Schema

ConsoleBehaviour 🔗

Bases: Behaviour

控制台的 Saya Behaviour 实现, 传入 Console 对象

Source code in src/graia/ariadne/console/saya.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class ConsoleBehaviour(Behaviour):
    """控制台的 Saya Behaviour 实现, 传入 Console 对象"""

    def __init__(self, console: Console) -> None:
        self.console = console

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

    def release(self, cube: Cube[ConsoleSchema]):
        if not isinstance(cube.metaclass, ConsoleSchema):
            return
        for val in self.console.registry[:]:
            if cube.content is val[0]:
                self.console.registry.remove(val)
        return True

    uninstall = release  # FIXME: backward compatibility

ConsoleSchema dataclass 🔗

Bases: BaseSchema

控制台监听 Schema, 相当于 console.register

Source code in src/graia/ariadne/console/saya.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
@dataclass
class ConsoleSchema(BaseSchema):
    """控制台监听 Schema, 相当于 console.register"""

    dispatchers: List[BaseDispatcher] = field(default_factory=list)
    decorators: List[Decorator] = field(default_factory=list)

    def register(self, func: Callable, console: Console):
        """注册 func 至 console

        Args:
            func (Callable): 监听函数
            console (Console): 注册到的 console
        """
        console.register(self.dispatchers, self.decorators)(func)

register 🔗

register(func: Callable, console: Console)

注册 func 至 console

Parameters:

  • func (Callable) –

    监听函数

  • console (Console) –

    注册到的 console

Source code in src/graia/ariadne/console/saya.py
21
22
23
24
25
26
27
28
def register(self, func: Callable, console: Console):
    """注册 func 至 console

    Args:
        func (Callable): 监听函数
        console (Console): 注册到的 console
    """
    console.register(self.dispatchers, self.decorators)(func)