Total Complexity | 2 |
Total Lines | 40 |
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 | """sent when a guild is updated""" |
||
5 | from typing import List |
||
6 | |||
7 | from ..core.dispatch import GatewayDispatch |
||
8 | from ..objects import Guild, Channel |
||
9 | from ..utils.conversion import construct_client_dict |
||
10 | |||
11 | |||
12 | async def guild_update_middleware(self, payload: GatewayDispatch): |
||
13 | """ |
||
14 | Middleware for ``on_guild_update``, |
||
15 | creates a object for the guild that is updated |
||
16 | |||
17 | :param self: |
||
18 | The current client. |
||
19 | |||
20 | :param payload: |
||
21 | The data received from the guild update event. |
||
22 | """ |
||
23 | channel_list = payload.data.pop("channels", []) |
||
24 | |||
25 | channels: List[Channel] = [ |
||
26 | Channel.from_dict(construct_client_dict(self, channel)) |
||
27 | for channel in channel_list |
||
28 | ] |
||
29 | |||
30 | return "on_guild_update", [ |
||
31 | Guild.from_dict(construct_client_dict( |
||
32 | self, |
||
33 | {"channels": channels, **payload.data} |
||
34 | )) |
||
35 | ] |
||
36 | |||
37 | |||
38 | def export(): |
||
|
|||
39 | return guild_update_middleware |
||
40 |