Completed
Push — main ( 3a3ea0...93fa25 )
by Yohann
23s queued 12s
created

pincer.objects.guild.member   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 43
dl 0
loc 99
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A GuildMember.__post_init__() 0 5 1
A GuildMember.from_id() 0 9 1
1
# Copyright Pincer 2021-Present
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
# Full MIT License can be found in `LICENSE` at the project root.
3
4
from __future__ import annotations
5
6
from dataclasses import dataclass
7
from typing import Optional, List, TYPE_CHECKING
8
9
from ..user import User
10
from ...core.http import HTTPClient
11
from ...utils.api_object import APIObject
12
from ...utils.conversion import convert
13
from ...utils.snowflake import Snowflake
14
from ...utils.timestamp import Timestamp
0 ignored issues
show
introduced by
Cannot import 'utils.timestamp' due to syntax error 'invalid syntax (<unknown>, line 70)'
Loading history...
Bug introduced by
The name timestamp does not seem to exist in module pincer.utils.
Loading history...
15
from ...utils.types import MISSING
16
17
if TYPE_CHECKING:
18
    from ... import Client
19
    from ...utils.types import APINullable
20
21
22
@dataclass
0 ignored issues
show
best-practice introduced by
Too many instance attributes (14/7)
Loading history...
23
class GuildMember(APIObject):
24
    """
25
    Represents a member which resides in a guild/server.
26
27
    :param _client:
28
        reference to the Client
29
30
    :param _http:
31
        reference to the HTTPClient
32
33
    :param deaf:
34
        whether the user is deafened in voice channels
35
36
    :param joined_at:
37
        when the user joined the guild
38
39
    :param mute:
40
        whether the user is muted in voice channels
41
42
    :param roles:
43
        array of role object ids
44
45
    :param nick:
46
        this users guild nickname
47
48
    :param pending:
49
        whether the user has not yet passed the guild's Membership
50
        Screening requirements
51
52
    :param is_pending:
53
        Deprecated version of pending.
54
55
    :param permissions:
56
        total permissions of the member in the channel,
57
        including overwrites, returned when in the interaction object
58
59
    :param premium_since:
60
        when the user started boosting the guild
61
62
    :param user:
63
        the user this guild member represents
64
    """
65
66
    _client: Client
67
    _http: HTTPClient
68
69
    deaf: bool
70
    joined_at: Timestamp
71
    mute: bool
72
    roles: List[Snowflake]
73
74
    hoisted_role: APINullable[Snowflake] = MISSING
75
    nick: APINullable[Optional[str]] = MISSING
76
    pending: APINullable[bool] = MISSING
77
    is_pending: APINullable[bool] = MISSING
78
    permissions: APINullable[str] = MISSING
79
    premium_since: APINullable[Optional[Timestamp]] = MISSING
80
    user: APINullable[User] = MISSING
81
    avatar: APINullable[str] = MISSING
82
83
    def __post_init__(self):
84
        self.roles = convert(self.roles, Snowflake.from_string)
85
        self.user = convert(self.user, User.from_dict, User, self._client)
86
        self.premium_since = convert(
87
            self.premium_since, Timestamp.parse, Timestamp
88
        )
89
90
    @classmethod
91
    async def from_id(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
92
            cls,
93
            client: Client,
94
            guild_id: int,
95
            _id: int
96
    ) -> GuildMember:
97
        data = await client.http.get(f"guilds/{guild_id}/members/{_id}")
98
        return cls.from_dict({**data, "_client": client, "_http": client.http})
99