Completed
Push — main ( b12314...8ccbcd )
by Yohann
17s queued 14s
created

pincer.objects.guild   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 282
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 74
dl 0
loc 282
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A Guild.from_dict() 0 17 2
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 typing import Optional, List
28
29
from pincer.exceptions import UnavailableGuildError
30
from pincer.objects.channel import Channel
31
from pincer.objects.emoji import Emoji
32
from pincer.objects.guild_member import GuildMember
33
from pincer.objects.role import Role
34
from pincer.objects.stage import StageInstance
35
from pincer.objects.sticker import Sticker
36
from pincer.objects.welcome_screen import WelcomeScreen
37
from pincer.utils.api_object import APIObject
38
from pincer.utils.constants import APINullable, MISSING
39
from pincer.utils.snowflake import Snowflake
40
from pincer.utils.timestamp import Timestamp
0 ignored issues
show
Bug introduced by
The name timestamp does not seem to exist in module pincer.utils.
Loading history...
introduced by
Cannot import 'pincer.utils.timestamp' due to syntax error 'invalid syntax (<unknown>, line 91)'
Loading history...
41
42
43
@dataclass
0 ignored issues
show
best-practice introduced by
Too many instance attributes (50/7)
Loading history...
44
class Guild(APIObject):
45
    """
46
    Represents a Discord guild/server in which your client resides.
47
48
    :param afk_channel_id:
49
        id of afk channel
50
51
    :param afk_timeout:
52
        afk timeout in seconds
53
54
    :param application_id:
55
        application id of the guild creator if it is bot-created
56
57
    :param banner:
58
        banner hash
59
60
    :param default_message_notifications:
61
        default message notifications level
62
63
    :param description:
64
        the description of a Community guild
65
66
    :param discovery_splash:
67
        discovery splash hash; only present for guilds with the "DISCOVERABLE"
68
        feature
69
70
    :param emojis:
71
        custom guild emojis
72
73
    :param explicit_content_filter:
74
        explicit content filter level
75
76
    :param features:
77
        enabled guild features
78
79
    :param id:
80
        guild id
81
82
    :param icon:
83
        icon hash
84
85
    :param mfa_level:
86
        required MFA level for the guild
87
88
    :param name:
89
        guild name (2-100 characters, excluding trailing and leading
90
        whitespace)
91
92
    :param nsfw_level:
93
        guild NSFW level
94
95
    :param owner_id:
96
        id of owner
97
98
    :param preferred_locale:
99
        the preferred locale of a Community guild; used in server discovery and
100
        notices from Discord; defaults to "en-US"
101
102
    :param premium_tier:
103
        premium tier (Server Boost level)
104
105
    :param public_updates_channel_id:
106
        the id of the channel where admins and moderators of Community guilds
107
        receive notices from Discord
108
109
    :param roles:
110
        roles in the guild
111
112
    :param rules_channel_id:
113
        the id of the channel where Community guilds can display rules and/or
114
        guidelines
115
116
    :param splash:
117
        splash hash
118
119
    :param system_channel_flags:
120
        system channel flags
121
122
    :param system_channel_id:
123
        the id of the channel where guild notices such as welcome messages and
124
        boost events are posted
125
126
    :param vanity_url_code:
127
        the vanity url code for the guild
128
129
    :param verification_level:
130
        verification level required for the guild
131
132
    :param approximate_member_count:
133
        approximate number of members in this guild, returned from the
134
        `GET /guilds/<id>` endpoint when with_counts is true
135
136
    :param approximate_presence_count:
137
        approximate number of non-offline members in this guild, returned from
138
        the `GET /guilds/<id>` endpoint when with_counts is true
139
140
    :param channels:
141
        channels in the guild
142
143
    :param icon_hash:
144
        icon hash, returned when in the template object
145
146
    :param joined_at:
147
        when this guild was joined at
148
149
    :param large:
150
        true if this is considered a large guild
151
152
    :param max_members:
153
        the maximum number of members for the guild
154
155
    :param max_presences:
156
        the maximum number of presences for the guild (null is always returned,
157
        apart from the largest of guilds)
158
159
    :param max_video_channel_users:
160
        the maximum amount of users in a video channel
161
162
    :param members:
163
        users in the guild
164
165
    :param member_count:
166
        total number of members in this guild
167
168
    :param owner:
169
        true if the user is the owner of the guild
170
171
    :param permissions:
172
        total permissions for the user in the guild (excludes overwrites)
173
174
    :param premium_subscription_count:
175
        the number of boosts this guild currently has
176
177
    :param presences:
178
        presences of the members in the guild, will only include non-offline
179
        members if the size is greater than large threshold
180
181
    :param stage_instances:
182
        Stage instances in the guild
183
184
    :param stickers:
185
        custom guild stickers
186
187
    :param region:
188
        voice region id for the guild (deprecated)
189
190
    :param threads:
191
        all active threads in the guild that current user has permission to
192
        view
193
194
    :param unavailable:
195
        true if this guild is unavailable due to an outage
196
197
    :param voice_states:
198
        states of members currently in voice channels; lacks the guild_id key
199
200
    :param widget_enabled:
201
        true if the server widget is enabled
202
203
    :param widget_channel_id:
204
        the channel id that the widget will generate an invite to, or null if
205
        set to no invite
206
207
    :param welcome_screen:
208
        the welcome screen of a Community guild, shown to new members, returned
209
        in an Invite's guild object
210
    """
211
212
    afk_channel_id: Optional[Snowflake]
213
    afk_timeout: int
214
    application_id: Optional[int]
215
    banner: Optional[str]
216
    default_message_notifications: int
217
    description: Optional[str]
218
    discovery_splash: Optional[str]
219
    emojis: List[Emoji]
220
    explicit_content_filter: int
221
    features: List[...]
222
    id: Snowflake
1 ignored issue
show
Coding Style Naming introduced by
Attribute name "id" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
223
    icon: Optional[str]
224
    mfa_level: int
225
    name: str
226
    nsfw_level: int
227
    owner_id: Snowflake
228
    preferred_locale: str
229
    premium_tier: int
230
    public_updates_channel_id: Optional[Snowflake]
231
    roles: List[Role]
232
    rules_channel_id: Optional[int]
233
    splash: Optional[str]
234
    system_channel_flags: int
235
    system_channel_id: Optional[int]
236
    vanity_url_code: Optional[str]
237
    verification_level: int
238
239
    approximate_member_count: APINullable[int] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
240
    approximate_presence_count: APINullable[int] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
241
    channels: APINullable[List[Channel]] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
242
    icon_hash: APINullable[Optional[str]] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
243
    joined_at: APINullable[Timestamp] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
244
    large: APINullable[bool] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
245
    max_members: APINullable[int] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
246
    max_presences: APINullable[Optional[int]] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
247
    max_video_channel_users: APINullable[int] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
248
    members: APINullable[List[GuildMember]] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
249
    member_count: APINullable[bool] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
250
    owner: APINullable[bool] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
251
    permissions: APINullable[str] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
252
    premium_subscription_count: APINullable[int] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
253
    presences: APINullable[List[...]] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
254
    stage_instances: APINullable[List[StageInstance]] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
255
    stickers: APINullable[List[Sticker]] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
256
    region: APINullable[Optional[str]] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
257
    threads: APINullable[List[Channel]] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
258
    # Guilds are considered available unless otherwise specified
259
    unavailable: APINullable[bool] = False
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
260
    voice_states: APINullable[bool] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
261
    widget_enabled: APINullable[bool] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
262
    widget_channel_id: APINullable[Optional[Snowflake]] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
263
    welcome_screen: APINullable[WelcomeScreen] = MISSING
0 ignored issues
show
introduced by
Value 'APINullable' is unsubscriptable
Loading history...
264
265
    @classmethod
266
    def from_dict(cls, data) -> Guild:
267
        """
268
        Instantiate a new guild from a dictionary.
269
270
        Also handles it if the guild isn't available.
271
272
        :raises UnavailableGuildError:
273
            Exception gets raised when guild is unavailable.
274
        """
275
        if data.get("unavailable", False):
276
            raise UnavailableGuildError(
277
                f"Guild \"{data['id']}\" is unavailable due"
278
                " to a discord outage."
279
            )
280
281
        return cls.from_dict(data)
282