@@ 19-50 (lines=32) @@ | ||
16 | from ..core.gateway import GatewayDispatch |
|
17 | ||
18 | ||
19 | async def thread_update_middleware( |
|
20 | self: Client, gateway: Gateway, payload: GatewayDispatch |
|
21 | ): |
|
22 | """|coro| |
|
23 | ||
24 | Middleware for the ``on_thread_update`` event. |
|
25 | ||
26 | Parameters |
|
27 | ---------- |
|
28 | payload : :class:`~pincer.core.gateway.GatewayDispatch` |
|
29 | The data received from the thread update event. |
|
30 | gateway : :class:`~pincer.core.gateway.Gateway` |
|
31 | The gateway for the current shard. |
|
32 | ||
33 | Returns |
|
34 | ------- |
|
35 | Tuple[:class:`str`, :class:`~pincer.objects.guild.channel.Channel`] |
|
36 | ``on_thread_update`` and an ``Channel`` |
|
37 | """ |
|
38 | ||
39 | channel = Channel.from_dict(payload.data) |
|
40 | guild = self.guilds.get(channel.guild_id) |
|
41 | ||
42 | if guild: |
|
43 | guild.threads = replace( |
|
44 | lambda _channel: _channel.id == channel.id, |
|
45 | self.guilds[channel.guild_id].threads, |
|
46 | channel, |
|
47 | ) |
|
48 | self.channels[channel.id] = channel |
|
49 | ||
50 | return "on_thread_update", channel |
|
51 | ||
52 | ||
53 | def export(): |
@@ 19-50 (lines=32) @@ | ||
16 | from ..core.gateway import GatewayDispatch |
|
17 | ||
18 | ||
19 | async def channel_update_middleware( |
|
20 | self: Client, gateway: Gateway, payload: GatewayDispatch |
|
21 | ): |
|
22 | """|coro| |
|
23 | ||
24 | Middleware for the ``on_channel_update`` event. |
|
25 | ||
26 | Parameters |
|
27 | ---------- |
|
28 | payload : :class:`~pincer.core.gateway.GatewayDispatch` |
|
29 | The data received from the channel update event. |
|
30 | gateway : :class:`~pincer.core.gateway.Gateway` |
|
31 | The gateway for the current shard. |
|
32 | ||
33 | Returns |
|
34 | ------- |
|
35 | Tuple[:class:`str`, :class:`~pincer.objects.channel.channel.Channel`] |
|
36 | ``on_channel_update`` and a ``Channel`` |
|
37 | """ |
|
38 | ||
39 | channel = Channel.from_dict(payload.data) |
|
40 | guild = self.guilds.get(channel.guild_id) |
|
41 | ||
42 | if guild: |
|
43 | guild.channels = replace( |
|
44 | lambda _channel: _channel.id == channel.id, |
|
45 | self.guilds[channel.guild_id].channels, |
|
46 | channel, |
|
47 | ) |
|
48 | self.channels[channel.id] = channel |
|
49 | ||
50 | return "on_channel_update", channel |
|
51 | ||
52 | ||
53 | def export(): |