pincer.middleware.thread_create   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 19
dl 0
loc 52
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A export() 0 2 1
A thread_create_middleware() 0 30 2
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 created/joined on the client."""
5
6
from __future__ import annotations
7
8
from typing import TYPE_CHECKING
9
10
from ..objects import Channel
11
12
if TYPE_CHECKING:
13
    from ..client import Client
14
    from ..core.gateway import Gateway
15
    from ..core.gateway import GatewayDispatch
16
17
18
async def thread_create_middleware(
19
    self: Client, gateway: Gateway, payload: GatewayDispatch
0 ignored issues
show
Unused Code introduced by
The argument gateway seems to be unused.
Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
20
):
21
    """|coro|
22
23
    Middleware for the ``on_thread_create`` event.
24
25
    Parameters
26
    ----------
27
    payload : :class:`~pincer.core.gateway.GatewayDispatch`
28
        The data received from the thread create event.
29
    gateway : :class:`~pincer.core.gateway.Gateway`
30
        The gateway for the current shard.
31
32
    Returns
33
    -------
34
    Tuple[:class:`str`, :class:`~pincer.objects.guild.channel.Channel`]
35
        ``on_thread_create`` and an ``Channel``
36
    """
37
38
    channel: Channel = Channel.from_dict(payload.data)
39
40
    if self.guilds[channel.guild_id].threads:
41
        self.guilds[channel.guild_id].threads.append(channel)
42
    else:
43
        self.guilds[channel.guild_id].threads = [channel]
44
45
    self.channels[channel.id] = channel
46
47
    return "on_thread_create", channel
48
49
50
def export():
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
51
    return thread_create_middleware
52