pincer.middleware.thread_update   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 58.18 %

Importance

Changes 0
Metric Value
wmc 4
eloc 23
dl 32
loc 55
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A export() 0 2 1
A thread_update_middleware() 32 32 3

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 thread is updated"""
5
6
from __future__ import annotations
7
8
from typing import TYPE_CHECKING
9
10
from ..objects import Channel
11
from ..utils import replace
12
13
if TYPE_CHECKING:
14
    from ..client import Client
15
    from ..core.gateway import Gateway
16
    from ..core.gateway import GatewayDispatch
17
18
19 View Code Duplication
async def thread_update_middleware(
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
20
    self: Client, gateway: Gateway, payload: GatewayDispatch
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Unused Code introduced by
The argument gateway seems to be unused.
Loading history...
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():
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
54
    return thread_update_middleware
55