Passed
Pull Request — main (#158)
by
unknown
03:42
created

pincer.objects.user.user.User.mention()   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nop 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 enum import IntEnum
8
from typing import Optional, TYPE_CHECKING
9
10
from ...core.http import HTTPClient
0 ignored issues
show
Unused Code introduced by
Unused HTTPClient imported from core.http
Loading history...
11
from ...utils.api_object import APIObject
0 ignored issues
show
Bug introduced by
The name api_object does not seem to exist in module pincer.utils.
Loading history...
introduced by
Cannot import 'utils.api_object' due to syntax error 'invalid syntax (<unknown>, line 81)'
Loading history...
12
from ...utils.conversion import convert, construct_client_dict
0 ignored issues
show
Unused Code introduced by
Unused convert imported from utils.conversion
Loading history...
13
from ...utils.snowflake import Snowflake
14
from ...utils.types import MISSING
15
16
if TYPE_CHECKING:
17
    from ... import Client
18
    from ...utils import APINullable
19
20
21
class PremiumTypes(IntEnum):
22
    """
23
    The type of Discord premium a user has.
24
    """
25
    NONE = 0
26
    NITRO_CLASSIC = 1
27
    NITRO = 2
28
29
30
class VisibilityType(IntEnum):
31
    """
32
    The type of a connection visibility.
33
    """
34
    NONE = 0
35
    EVERYONE = 1
36
37
38
@dataclass
0 ignored issues
show
best-practice introduced by
Too many instance attributes (16/7)
Loading history...
39
class User(APIObject):
40
    """
41
    Represents a Discord user. This can be a bot account or a
42
    human account.
43
44
    :param avatar:
45
        the user's avatar hash
46
47
    :param discriminator:
48
        the user's 4-digit discord-tag
49
50
    :param flags:
51
        the flags on a user's account
52
53
    :param id:
54
        the user's id
55
56
    :param username:
57
        the user's username, not unique across the platform
58
59
    :param accent_color:
60
        the user's banner color encoded as an integer representation of
61
        hexadecimal color code
62
63
    :param banner:
64
        the user's banner, or null if unset
65
66
    :param banner_color:
67
        the color of the user's banner
68
69
    :param bot:
70
        whether the user belongs to an OAuth2 application
71
72
    :param email:
73
        the user's email
74
75
    :param locale:
76
        the user's chosen language option
77
78
    :param mfa_enabled:
79
        whether the user has two factor enabled on their account
80
81
    :param premium_type:
82
        the type of Nitro subscription on a user's account
83
84
    :param public_flags:
85
        the public flags on a user's account
86
87
    :param system:
88
        whether the user is an Official Discord System user
89
        (part of the urgent message system)
90
91
    :param verified:
92
        whether the email on this account has been verified
93
    """
94
    avatar: Optional[str]
95
    discriminator: str
96
    id: Snowflake
97
    username: str
98
99
    flags: APINullable[int] = MISSING
100
    accent_color: APINullable[Optional[int]] = MISSING
101
    banner: APINullable[Optional[str]] = MISSING
102
    banner_color: APINullable[Optional[int]] = MISSING
103
    bot: APINullable[bool] = MISSING
104
    email: APINullable[Optional[str]] = MISSING
105
    locale: APINullable[str] = MISSING
106
    mfa_enabled: APINullable[bool] = MISSING
107
    premium_type: APINullable[int] = MISSING
108
    public_flags: APINullable[int] = MISSING
109
    system: APINullable[bool] = MISSING
110
    verified: APINullable[bool] = MISSING
111
112
    @property
113
    def premium(self) -> APINullable[PremiumTypes]:
114
        """
115
        The user their premium type in a usable enum.
116
        """
117
        return (
118
            MISSING
119
            if self.premium_type is MISSING
120
            else PremiumTypes(self.premium_type)
121
        )
122
123
    @property
124
    def mention(self) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
125
        return f"<@!{self.id}>"
126
127
    def __str__(self):
128
        """Return the discord tag when object gets used as a string."""
129
        return self.username + '#' + self.discriminator
130
131
    @classmethod
132
    async def from_id(cls, client: Client, user_id: int) -> User:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
133
        data = await client.http.get(f"users/{user_id}")
134
        return cls.from_dict(construct_client_dict(client, data))
135