| Total Complexity | 5 |
| Total Lines | 43 |
| Duplicated Lines | 65.12 % |
| Changes | 0 | ||
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 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 deleted""" |
||
| 5 | |||
| 6 | from ..core.dispatch import GatewayDispatch |
||
| 7 | from ..objects import Channel |
||
| 8 | from ..utils.conversion import construct_client_dict |
||
| 9 | |||
| 10 | |||
| 11 | View Code Duplication | async def channel_delete_middleware(self, payload: GatewayDispatch): |
|
|
|
|||
| 12 | """|coro| |
||
| 13 | |||
| 14 | Middleware for ``on_channel_delete``, |
||
| 15 | |||
| 16 | Parameters |
||
| 17 | ---------- |
||
| 18 | self : :class:`Client` |
||
| 19 | The current client/bot. |
||
| 20 | |||
| 21 | payload : :class:`pincer.core.dispatch.GatewayDispatch` |
||
| 22 | The data received from the channel delete event. |
||
| 23 | |||
| 24 | Returns |
||
| 25 | ------- |
||
| 26 | Tuple[:class:`str`, `~pincer.objects.guild.channel.Channel`] |
||
| 27 | ``on_channel_delete`` and a ``Channel`` |
||
| 28 | """ |
||
| 29 | |||
| 30 | channel = Channel.from_dict(construct_client_dict(self, payload.data)) |
||
| 31 | |||
| 32 | if channel.guild_id in self.guilds: |
||
| 33 | guild = self.guilds[channel.guild_id] |
||
| 34 | old = filter(lambda c: c.id == channel.id, guild.channels) |
||
| 35 | if old: |
||
| 36 | guild.channels.remove(old) |
||
| 37 | |||
| 38 | return "on_channel_delete", [channel] |
||
| 39 | |||
| 40 | |||
| 41 | def export(): |
||
| 42 | return channel_delete_middleware |
||
| 43 |