Total Complexity | 2 |
Total Lines | 45 |
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 the client gains access to a channel""" |
||
5 | |||
6 | from __future__ import annotations |
||
7 | |||
8 | from typing import List |
||
9 | |||
10 | from ..core.dispatch import GatewayDispatch |
||
11 | from ..objects import Channel, ThreadMember |
||
12 | from ..objects.events.thread import ThreadListSyncEvent |
||
13 | from ..utils.conversion import construct_client_dict |
||
14 | |||
15 | |||
16 | async def thread_list_sync(self, payload: GatewayDispatch): |
||
17 | """ |
||
18 | Middleware for ``on_thread_list_sync`` event. |
||
19 | |||
20 | :param self: |
||
21 | The current client |
||
22 | |||
23 | :param payload: |
||
24 | The data received from the thread list sync event. |
||
25 | """ |
||
26 | threads: List[Channel] = [ |
||
27 | Channel.from_dict(construct_client_dict(self, thread)) |
||
28 | for thread in payload.data.pop("threads") |
||
29 | ] |
||
30 | |||
31 | members: List[ThreadMember] = [ |
||
32 | ThreadMember.from_dict(construct_client_dict(self, member)) |
||
33 | for member in payload.data.pop("members") |
||
34 | ] |
||
35 | |||
36 | return "on_thread_list_sync", [ |
||
37 | ThreadListSyncEvent.from_dict( |
||
38 | {"threads": threads, "members": members, **payload.data} |
||
39 | ) |
||
40 | ] |
||
41 | |||
42 | |||
43 | def export(): |
||
|
|||
44 | return thread_list_sync |
||
45 |