Passed
Pull Request — main (#174)
by
unknown
01:46
created

pincer.middleware.ready.ready_middleware()   A

Complexity

Conditions 4

Size

Total Lines 29
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 29
rs 9.9
c 0
b 0
f 0
cc 4
nop 2
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
0 ignored issues
show
introduced by
Cannot import 'commands' due to syntax error 'invalid syntax (<unknown>, line 109)'
Loading history...
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:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
49
    return ready_middleware
50