跳转至

dispatcher

Ariadne 内置的 Dispatcher

BaseDispatcher 🔗

Bases: AbstractDispatcher

空 Dispatcher

Source code in graia/ariadne/dispatcher.py
130
131
132
133
134
135
class BaseDispatcher(AbstractDispatcher):
    """空 Dispatcher"""

    @staticmethod
    async def catch(*_):
        pass

ContextDispatcher 🔗

Bases: AbstractDispatcher

提取上下文的 Dispatcher

Source code in graia/ariadne/dispatcher.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class ContextDispatcher(AbstractDispatcher):
    """提取上下文的 Dispatcher"""

    @staticmethod
    async def catch(interface: DispatcherInterface):
        from .app import Ariadne

        if generic_isinstance(interface.event, interface.annotation):
            return interface.event

        if generic_issubclass(Broadcast, interface.annotation):
            return Ariadne.service.broadcast

        if generic_issubclass(asyncio.AbstractEventLoop, interface.annotation):
            return Ariadne.service.broadcast.loop

        if generic_issubclass(Ariadne, interface.annotation):
            return Ariadne.current()

FriendDispatcher 🔗

Bases: AbstractDispatcher

提取 Friend 的 Dispatcher

Source code in graia/ariadne/dispatcher.py
138
139
140
141
142
143
144
class FriendDispatcher(AbstractDispatcher):
    """提取 Friend 的 Dispatcher"""

    @staticmethod
    async def catch(interface: DispatcherInterface):
        if generic_issubclass(Friend, interface.annotation):
            return interface.event.friend

GroupDispatcher 🔗

Bases: AbstractDispatcher

提取 Group 的 Dispatcher

Source code in graia/ariadne/dispatcher.py
147
148
149
150
151
152
153
class GroupDispatcher(AbstractDispatcher):
    """提取 Group 的 Dispatcher"""

    @staticmethod
    async def catch(interface: DispatcherInterface):
        if generic_issubclass(Group, interface.annotation):
            return interface.event.group

MemberDispatcher 🔗

Bases: AbstractDispatcher

提取 Member 的 Dispatcher

Source code in graia/ariadne/dispatcher.py
156
157
158
159
160
161
162
163
164
class MemberDispatcher(AbstractDispatcher):
    """提取 Member 的 Dispatcher"""

    @staticmethod
    async def catch(interface: DispatcherInterface):
        if generic_issubclass(Member, interface.annotation):
            return interface.event.member
        elif generic_issubclass(Group, interface.annotation):
            return interface.event.member.group

MessageChainDispatcher 🔗

Bases: AbstractDispatcher

从 MessageEvent 提取 MessageChain 的 Dispatcher

Source code in graia/ariadne/dispatcher.py
19
20
21
22
23
24
25
26
27
28
29
class MessageChainDispatcher(AbstractDispatcher):
    """从 MessageEvent 提取 MessageChain 的 Dispatcher"""

    @staticmethod
    async def catch(interface: DispatcherInterface):
        from .event.message import ActiveMessage, MessageEvent

        if isinstance(interface.event, (MessageEvent, ActiveMessage)) and generic_issubclass(
            MessageChain, interface.annotation
        ):
            return interface.event.message_chain

NoneDispatcher 🔗

Bases: AbstractDispatcher

给 Optional[...] 提供 None 的 Dispatcher

Source code in graia/ariadne/dispatcher.py
69
70
71
72
73
74
75
class NoneDispatcher(AbstractDispatcher):
    """给 Optional[...] 提供 None 的 Dispatcher"""

    @staticmethod
    async def catch(interface: DispatcherInterface):
        if generic_isinstance(None, interface.annotation):
            return Force(None)

OperatorDispatcher 🔗

Bases: AbstractDispatcher

提取 Operator 的 Dispatcher

Source code in graia/ariadne/dispatcher.py
167
168
169
170
171
172
173
174
175
176
177
class OperatorDispatcher(AbstractDispatcher):
    """提取 Operator 的 Dispatcher"""

    @staticmethod
    async def catch(interface: DispatcherInterface):
        if generic_issubclass(Member, interface.annotation):
            return interface.event.operator
        elif generic_issubclass(Group, interface.annotation):
            # NOTE: operator 不为 None。因为 operator 可为 None 的事件必有 group 属性,
            # 会由 dispatcher 之前的 GroupDispatcher 处理,不可能进入此处。
            return interface.event.operator.group

OperatorMemberDispatcher 🔗

Bases: AbstractDispatcher

提取 Operator 的 Dispatcher (同时有 Member 和 Operator)

Source code in graia/ariadne/dispatcher.py
180
181
182
183
184
185
186
187
188
class OperatorMemberDispatcher(AbstractDispatcher):
    """提取 Operator 的 Dispatcher (同时有 Member 和 Operator)"""

    @staticmethod
    async def catch(interface: DispatcherInterface):
        if generic_issubclass(Member, interface.annotation):
            return interface.event.operator if interface.name == "operator" else interface.event.member
        elif generic_issubclass(Group, interface.annotation):
            return interface.event.member.group

QuoteDispatcher 🔗

Bases: AbstractDispatcher

提取 MessageEvent 消息链 Quote 元素的 Dispatcher

Source code in graia/ariadne/dispatcher.py
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
class QuoteDispatcher(AbstractDispatcher):
    """提取 MessageEvent 消息链 Quote 元素的 Dispatcher"""

    @staticmethod
    async def catch(interface: DispatcherInterface):
        from .event.message import ActiveMessage, MessageEvent

        if isinstance(interface.event, (MessageEvent, ActiveMessage)) and generic_issubclass(
            Quote, interface.annotation
        ):
            return interface.event.quote

SenderDispatcher 🔗

Bases: AbstractDispatcher

从 MessageEvent 提取 sender 的 Dispatcher.

Source code in graia/ariadne/dispatcher.py
104
105
106
107
108
109
110
111
112
113
114
class SenderDispatcher(AbstractDispatcher):
    """从 MessageEvent 提取 sender 的 Dispatcher."""

    @staticmethod
    async def catch(interface: DispatcherInterface):
        from .event.message import MessageEvent

        if isinstance(interface.event, MessageEvent):
            with contextlib.suppress(TypeError):
                if generic_isinstance(interface.event.sender, interface.annotation):
                    return interface.event.sender

SourceDispatcher 🔗

Bases: AbstractDispatcher

提取 MessageEvent 消息链 Source 元素的 Dispatcher

Source code in graia/ariadne/dispatcher.py
78
79
80
81
82
83
84
85
86
87
88
class SourceDispatcher(AbstractDispatcher):
    """提取 MessageEvent 消息链 Source 元素的 Dispatcher"""

    @staticmethod
    async def catch(interface: DispatcherInterface):
        from .event.message import ActiveMessage, MessageEvent

        if isinstance(interface.event, (MessageEvent, ActiveMessage)) and generic_issubclass(
            Source, interface.annotation
        ):
            return interface.event.source

SubjectDispatcher 🔗

Bases: AbstractDispatcher

从 ActiveMessage 提取 subject 的 Dispatcher

Source code in graia/ariadne/dispatcher.py
117
118
119
120
121
122
123
124
125
126
127
class SubjectDispatcher(AbstractDispatcher):
    """从 ActiveMessage 提取 subject 的 Dispatcher"""

    @staticmethod
    async def catch(interface: DispatcherInterface):
        from .event.message import ActiveMessage

        if isinstance(interface.event, ActiveMessage) and generic_issubclass(
            interface.annotation, interface.event.subject
        ):
            return interface.event.subject