Passed
Pull Request — main (#163)
by
unknown
02:19
created

pincer.middleware.channel_update   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 66.67 %

Importance

Changes 0
Metric Value
wmc 5
eloc 16
dl 30
loc 45
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A channel_update_middleware() 30 30 4
A export() 0 2 1

How to fix   Duplicated Code   

Duplicated Code

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 updated"""
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_update_middleware(self, payload: GatewayDispatch):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
12
    """|coro|
13
14
    Middleware for ``on_channel_update`` event.
15
16
    Parameters
17
    ----------
18
    self : :class:`Client`
19
        The current client/bot.
20
21
    payload : :class:`GatewayDispatch`
22
        The data received from the channel update event.
23
24
25
    Returns
26
    -------
27
    Tuple[:class:`str`, List[:class:`~pincer.objects.channel.channel.Channel`]]
28
        ``on_channel_update`` and a ``Channel``
29
    """
30
31
    channel = Channel.from_dict(construct_client_dict(self, payload.data))
32
33
    if channel.guild_id in self.guilds.keys():
34
        guild = self.guilds[channel.guild_id]
35
        old = filter(lambda c: c.id == channel.id, guild.channels)
36
        if old:
37
            guild.channels.remove(old)
38
        guild.channels.append(channel)
39
40
    return "on_channel_update", [channel]
41
42
43
def export():
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
44
    return channel_update_middleware
45