Total Complexity | 2 |
Total Lines | 48 |
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 channel is created/joined on the client.""" |
||
5 | from __future__ import annotations |
||
6 | |||
7 | from typing import TYPE_CHECKING |
||
8 | |||
9 | from ..objects.guild.channel import Channel |
||
10 | |||
11 | if TYPE_CHECKING: |
||
12 | from typing import Tuple |
||
13 | from ..core.gateway import GatewayDispatch |
||
14 | from ..client import Client |
||
15 | from ..core.gateway import Gateway |
||
16 | |||
17 | |||
18 | async def channel_create_middleware( |
||
19 | self: Client, gateway: Gateway, payload: GatewayDispatch |
||
20 | ) -> Tuple[str, Channel]: |
||
21 | """|coro| |
||
22 | |||
23 | Middleware for the ``on_channel_creation`` event. |
||
24 | |||
25 | Parameters |
||
26 | ---------- |
||
27 | payload : :class:`~pincer.core.gateway.GatewayDispatch` |
||
28 | The data received from the ready event. |
||
29 | gateway : :class:`~pincer.core.gateway.Gateway` |
||
30 | The gateway for the current shard. |
||
31 | |||
32 | Returns |
||
33 | ------- |
||
34 | Tuple[:class:`str`, List[:class:`~pincer.objects.guild.channel.Channel`]] |
||
35 | ``on_channel_creation`` and a channel. |
||
36 | """ |
||
37 | |||
38 | channel: Channel = Channel.from_dict(payload.data) |
||
39 | |||
40 | self.guilds[channel.guild_id].channels.append(channel) |
||
41 | self.channels[channel.id] = channel |
||
42 | |||
43 | return "on_channel_creation", channel |
||
44 | |||
45 | |||
46 | def export(): |
||
47 | return channel_create_middleware |
||
48 |