Passed
Pull Request — main (#174)
by
unknown
02:24
created

pincer.middleware.ready.on_ready_middleware()   A

Complexity

Conditions 4

Size

Total Lines 24
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 24
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
    
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
20
    Middleware for ``on_ready`` event.
21
22
    Parameters
23
    ----------
24
    self : :class:`Client`
25
        The current client/bot
26
27
    payload : :class:`GatewayDispatch`
28
        The data recieved from the stage instance create event
29
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
30
    Returns
31
    -------
32
    Tuple[:class:`str`]
33
        ``on_ready``
34
    """
35
    user = payload.data.get("user")
36
    guilds = payload.data.get("guilds")
37
38
    if not user or guilds is None:
39
        raise InvalidPayload(
40
            "A `user` and `guilds` key/value pair is expected on the "
41
            "`ready` payload event."
42
        )
43
44
    self.bot = User.from_dict(construct_client_dict(self, user))
45
    self.guilds = dict(map(lambda i: (i["id"], None), guilds))
46
47
    await ChatCommandHandler(self).initialize()
48
    return ("on_ready",)
49
50
51
def export() -> Coro:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
52
    return ready_middleware
53