| Total Complexity | 3 |
| Total Lines | 49 |
| 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 TYPE_CHECKING |
||
| 9 | |||
| 10 | from ..objects.events.thread import ThreadListSyncEvent |
||
| 11 | |||
| 12 | if TYPE_CHECKING: |
||
| 13 | from ..client import Client |
||
| 14 | from ..core.gateway import Gateway |
||
| 15 | from ..core.gateway import GatewayDispatch |
||
| 16 | |||
| 17 | |||
| 18 | async def thread_list_sync( |
||
| 19 | self: Client, gateway: Gateway, payload: GatewayDispatch |
||
| 20 | ): |
||
| 21 | """|coro| |
||
| 22 | |||
| 23 | Middleware for the ``on_thread_list_sync`` event. |
||
| 24 | |||
| 25 | Parameters |
||
| 26 | ---------- |
||
| 27 | payload : :class:`~pincer.core.gateway.GatewayDispatch` |
||
| 28 | The data received from the thread list sync event. |
||
| 29 | gateway : :class:`~pincer.core.gateway.Gateway` |
||
| 30 | The gateway for the current shard. |
||
| 31 | |||
| 32 | Returns |
||
| 33 | ------- |
||
| 34 | Tuple[:class:`str`, :class:`~pincer.objects.guild.events.thread.ThreadListSyncEvent`] |
||
| 35 | ``on_thread_list_sync`` and an ``ThreadListSyncEvent`` |
||
| 36 | """ # noqa: E501 |
||
| 37 | |||
| 38 | event = ThreadListSyncEvent.from_dict(payload.data) |
||
| 39 | guild = self.guilds.get(event.guild_id) |
||
| 40 | |||
| 41 | if guild: |
||
| 42 | guild.threads = event.threads |
||
| 43 | |||
| 44 | return "on_thread_list_sync", event |
||
| 45 | |||
| 46 | |||
| 47 | def export(): |
||
| 48 | return thread_list_sync |
||
| 49 |