Passed
Push — main ( f6a351...3d8f6e )
by
unknown
01:59
created

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

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nop 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 Enum
28
from typing import Optional
29
30
from ..utils import APIObject, APINullable, MISSING, Snowflake, convert
31
32
33
class PremiumTypes(Enum):
34
    """
35
    The type of Discord premium a user has.
36
    """
37
    NONE = 0
38
    NITRO_CLASSIC = 1
39
    NITRO = 2
40
41
42
@dataclass
0 ignored issues
show
best-practice introduced by
Too many instance attributes (15/7)
Loading history...
43
class User(APIObject):
44
    """
45
    Represents a Discord user. This can be a bot account or a
46
    human account.
47
48
    :param avatar:
49
        the user's avatar hash
50
51
    :param discriminator:
52
        the user's 4-digit discord-tag
53
54
    :param flags:
55
        the flags on a user's account
56
57
    :param id:
58
        the user's id
59
60
    :param username:
61
        the user's username, not unique across the platform
62
63
    :param accent_color:
64
        the user's banner color encoded as an integer representation of
65
        hexadecimal color code
66
67
    :param banner:
68
        the user's banner, or null if unset
69
70
    :param bot:
71
        whether the user belongs to an OAuth2 application
72
73
    :param email:
74
        the user's email
75
76
    :param locale:
77
        the user's chosen language option
78
79
    :param mfa_enabled:
80
        whether the user has two factor enabled on their account
81
82
    :param premium_type:
83
        the type of Nitro subscription on a user's account
84
85
    :param public_flags:
86
        the public flags on a user's account
87
88
    :param system:
89
        whether the user is an Official Discord System user (part of the urgent
90
        message system)
91
92
    :param verified:
93
        whether the email on this account has been verified
94
    """
95
96
    avatar: Optional[str]
97
    discriminator: str
98
    id: Snowflake
99
    username: str
100
101
    flags: APINullable[int] = MISSING
102
    accent_color: APINullable[Optional[int]] = MISSING
103
    banner: APINullable[Optional[str]] = MISSING
104
    bot: APINullable[bool] = MISSING
105
    email: APINullable[Optional[str]] = MISSING
106
    locale: APINullable[str] = MISSING
107
    mfa_enabled: APINullable[bool] = MISSING
108
    premium_type: APINullable[int] = MISSING
109
    public_flags: APINullable[int] = MISSING
110
    system: APINullable[bool] = MISSING
111
    verified: APINullable[bool] = MISSING
112
113
    @property
114
    def premium(self) -> PremiumTypes:
115
        """
116
        The user their premium type in a usable enum.
117
        """
118
        return MISSING \
119
            if self.premium_type is MISSING \
120
            else PremiumTypes(self.premium_type)
121
122
    def __str__(self):
123
        """Return the discord tag when object gets used as a string."""
124
        return self.username + '#' + self.discriminator
125
126
    def __post_init__(self):
127
        self.id = convert(self.id, Snowflake.from_string)
128