Passed
Push — main ( 515ac2...5218dd )
by
unknown
01:49
created

pincer.objects.user   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 142
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 43
dl 0
loc 142
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A User.premium() 0 9 2
A User.__str__() 0 3 1
A User.__post_init__() 0 2 1
A User.mention() 0 3 1
1
# -*- coding: utf-8 -*-
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
# MIT License
3
#
4
# Copyright (c) 2021 Pincer
5
#
6
# Permission is hereby granted, free of charge, to any person obtaining
7
# a copy of this software and associated documentation files
8
# (the "Software"), to deal in the Software without restriction,
9
# including without limitation the rights to use, copy, modify, merge,
10
# publish, distribute, sublicense, and/or sell copies of the Software,
11
# and to permit persons to whom the Software is furnished to do so,
12
# subject to the following conditions:
13
#
14
# The above copyright notice and this permission notice shall be
15
# included in all copies or substantial portions of the Software.
16
#
17
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
from __future__ import annotations
25
26
from dataclasses import dataclass
27
from enum import IntEnum
28
from typing import Optional
29
30
from ..utils import APIObject, APINullable, MISSING, Snowflake, convert
31
32
33
class PremiumTypes(IntEnum):
34
    """
35
    The type of Discord premium a user has.
36
    """
37
    NONE = 0
38
    NITRO_CLASSIC = 1
39
    NITRO = 2
40
41
42
class VisibilityType(IntEnum):
43
    """
44
    The type of a connection visibility.
45
    """
46
    NONE = 0
47
    EVERYONE = 1
48
49
50
@dataclass
0 ignored issues
show
best-practice introduced by
Too many instance attributes (15/7)
Loading history...
51
class User(APIObject):
52
    """
53
    Represents a Discord user. This can be a bot account or a
54
    human account.
55
56
    :param avatar:
57
        the user's avatar hash
58
59
    :param discriminator:
60
        the user's 4-digit discord-tag
61
62
    :param flags:
63
        the flags on a user's account
64
65
    :param id:
66
        the user's id
67
68
    :param username:
69
        the user's username, not unique across the platform
70
71
    :param accent_color:
72
        the user's banner color encoded as an integer representation of
73
        hexadecimal color code
74
75
    :param banner:
76
        the user's banner, or null if unset
77
78
    :param bot:
79
        whether the user belongs to an OAuth2 application
80
81
    :param email:
82
        the user's email
83
84
    :param locale:
85
        the user's chosen language option
86
87
    :param mfa_enabled:
88
        whether the user has two factor enabled on their account
89
90
    :param premium_type:
91
        the type of Nitro subscription on a user's account
92
93
    :param public_flags:
94
        the public flags on a user's account
95
96
    :param system:
97
        whether the user is an Official Discord System user
98
        (part of the urgent message system)
99
100
    :param verified:
101
        whether the email on this account has been verified
102
    """
103
104
    avatar: Optional[str]
105
    discriminator: str
106
    id: Snowflake
107
    username: str
108
109
    flags: APINullable[int] = MISSING
110
    accent_color: APINullable[Optional[int]] = MISSING
111
    banner: APINullable[Optional[str]] = MISSING
112
    bot: APINullable[bool] = MISSING
113
    email: APINullable[Optional[str]] = MISSING
114
    locale: APINullable[str] = MISSING
115
    mfa_enabled: APINullable[bool] = MISSING
116
    premium_type: APINullable[int] = MISSING
117
    public_flags: APINullable[int] = MISSING
118
    system: APINullable[bool] = MISSING
119
    verified: APINullable[bool] = MISSING
120
121
    @property
122
    def premium(self) -> APINullable[PremiumTypes]:
123
        """
124
        The user their premium type in a usable enum.
125
        """
126
        return (
127
            MISSING
128
            if self.premium_type is MISSING
129
            else PremiumTypes(self.premium_type)
130
        )
131
132
    @property
133
    def mention(self) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
134
        return f"<@!{self.id}>"
135
136
    def __str__(self):
137
        """Return the discord tag when object gets used as a string."""
138
        return self.username + '#' + self.discriminator
139
140
    def __post_init__(self):
141
        self.id = convert(self.id, Snowflake.from_string)
142