Total Complexity | 5 |
Total Lines | 50 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | # Copyright Pincer 2021-Present |
||
2 | # Full MIT License can be found in `LICENSE` at the project root. |
||
3 | |||
4 | """ |
||
5 | non-subscription event sent immediately after connecting, |
||
6 | contains server information |
||
7 | """ |
||
8 | |||
9 | from ..commands import ChatCommandHandler |
||
|
|||
10 | from ..core.dispatch import GatewayDispatch |
||
11 | from ..exceptions import InvalidPayload |
||
12 | from ..objects import User |
||
13 | from ..utils import Coro |
||
14 | from ..utils.conversion import construct_client_dict |
||
15 | |||
16 | |||
17 | async def ready_middleware(self, payload: GatewayDispatch): |
||
18 | """|coro| |
||
19 | |||
20 | Middleware for ``on_ready`` event. |
||
21 | |||
22 | Parameters |
||
23 | ---------- |
||
24 | payload : :class:`GatewayDispatch` |
||
25 | The data recieved from the stage instance create event |
||
26 | |||
27 | Returns |
||
28 | ------- |
||
29 | Tuple[:class:`str`] |
||
30 | ``on_ready`` |
||
31 | """ |
||
32 | user = payload.data.get("user") |
||
33 | guilds = payload.data.get("guilds") |
||
34 | |||
35 | if not user or guilds is None: |
||
36 | raise InvalidPayload( |
||
37 | "A `user` and `guilds` key/value pair is expected on the " |
||
38 | "`ready` payload event." |
||
39 | ) |
||
40 | |||
41 | self.bot = User.from_dict(construct_client_dict(self, user)) |
||
42 | self.guilds = dict(map(lambda i: (i["id"], None), guilds)) |
||
43 | |||
44 | await ChatCommandHandler(self).initialize() |
||
45 | return ("on_ready",) |
||
46 | |||
47 | |||
48 | def export() -> Coro: |
||
49 | return ready_middleware |
||
50 |