跳转至

dispatcher

Ariadne 内置的 Dispatcher

BaseDispatcher 🔗

Bases: AbstractDispatcher

空 Dispatcher

Source code in src/graia/ariadne/dispatcher.py
136
137
138
139
140
141
class BaseDispatcher(AbstractDispatcher):
    """空 Dispatcher"""

    @staticmethod
    async def catch(*_):
        pass

ContextDispatcher 🔗

Bases: AbstractDispatcher

提取上下文的 Dispatcher

Source code in src/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 src/graia/ariadne/dispatcher.py
144
145
146
147
148
149
150
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 src/graia/ariadne/dispatcher.py
153
154
155
156
157
158
159
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 src/graia/ariadne/dispatcher.py
162
163
164
165
166
167
168
169
170
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 src/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 src/graia/ariadne/dispatcher.py
69
70
71
72
73
74
75
76
77
78
79
80
81
class NoneDispatcher(AbstractDispatcher):
    """给 Optional[...] 提供 None 的 Dispatcher"""

    @staticmethod
    async def catch(interface: DispatcherInterface):
        if NoneDispatcher in interface.current_oplog:  # FIXME: Workaround
            return None
            # oplog cached NoneDispatcher, which is undesirable
            # return "None" causes it to clear the cache
            # Then all the dispatchers are revisited
            # So that "None" is normally dispatched.
        if generic_isinstance(None, interface.annotation):
            return Force(None)

OperatorDispatcher 🔗

Bases: AbstractDispatcher

提取 Operator 的 Dispatcher

Source code in src/graia/ariadne/dispatcher.py
173
174
175
176
177
178
179
180
181
182
183
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 src/graia/ariadne/dispatcher.py
186
187
188
189
190
191
192
193
194
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 src/graia/ariadne/dispatcher.py
 97
 98
 99
100
101
102
103
104
105
106
107
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 src/graia/ariadne/dispatcher.py
110
111
112
113
114
115
116
117
118
119
120
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 src/graia/ariadne/dispatcher.py
84
85
86
87
88
89
90
91
92
93
94
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 src/graia/ariadne/dispatcher.py
123
124
125
126
127
128
129
130
131
132
133
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