Passed
Pull Request — main (#238)
by
unknown
01:33
created

pincer.objects.guild.guild.Guild.delete_role()   A

Complexity

Conditions 1

Size

Total Lines 12
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 12
rs 10
c 0
b 0
f 0
cc 1
nop 2
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, field
7
from enum import IntEnum
8
from typing import overload, TYPE_CHECKING
9
10
from .ban import Ban
11
from .channel import Channel
0 ignored issues
show
introduced by
Cannot import 'channel' due to syntax error 'invalid syntax (<unknown>, line 251)'
Loading history...
12
from .member import GuildMember
13
from ...exceptions import UnavailableGuildError
14
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 80)'
Loading history...
15
from ...utils.conversion import construct_client_dict
16
from ...utils.types import MISSING
17
18
if TYPE_CHECKING:
19
    from typing import Any, Dict, List, Optional, Union
20
21
    from .features import GuildFeature
22
    from .role import Role
23
    from .stage import StageInstance
24
    from .welcome_screen import WelcomeScreen
25
    from ..events.presence import PresenceUpdateEvent
26
    from ..message.emoji import Emoji
27
    from ..message.sticker import Sticker
28
    from ..user.voice_state import VoiceState
29
    from ...client import Client
0 ignored issues
show
introduced by
Cannot import 'client' due to syntax error 'invalid syntax (<unknown>, line 354)'
Loading history...
30
    from ...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 'utils.timestamp' due to syntax error 'invalid syntax (<unknown>, line 103)'
Loading history...
31
    from ...utils.types import APINullable
32
    from ...utils.snowflake import Snowflake
33
34
35
class PremiumTier(IntEnum):
36
    """Represents the boost tier of a guild.
37
    Attributes
38
    ----------
39
    NONE:
40
        Guild has not unlocked any Server Boost perks.
41
    TIER_1:
42
        Guild has unlocked Server Boost level 1 perks.
43
    TIER_2:
44
        Guild has unlocked Server Boost level 2 perks.
45
    TIER_3:
46
        Guild has unlocked Server Boost level 3 perks.
47
    """
48
    NONE = 0
49
    TIER_1 = 1
50
    TIER_2 = 2
51
    TIER_3 = 3
52
53
54
class GuildNSFWLevel(IntEnum):
55
    """Represents the NSFW level of a guild.
56
    Attributes
57
    ----------
58
    DEFAULT:
59
        Default NSFW level.
60
    EXPLICIT:
61
        Explicit NSFW level.
62
    SAFE:
63
        SAFE NSFW level.
64
    AGE_RESTRICTED:
65
        Age restricted NSFW level.
66
    """
67
    DEFAULT = 0
68
    EXPLICIT = 1
69
    SAFE = 2
70
    AGE_RESTRICTED = 3
71
72
73
class ExplicitContentFilterLevel(IntEnum):
74
    """Represents the filter content level of a guild.
75
    Attributes
76
    ----------
77
    DISABLED:
78
        Media content will not be scanned.
79
    MEMBERS_WITHOUT_ROLES:
80
        Media content sent by members without roles will be scanned.
81
    ALL_MEMBERS:
82
        Media content sent by all members will be scanned.
83
    """
84
    DISABLED = 0
85
    MEMBERS_WITHOUT_ROLES = 1
86
    ALL_MEMBERS = 2
87
88
89
class MFALevel(IntEnum):
90
    """Represents the multi factor authentication level of a guild.
91
    Attributes
92
    ----------
93
    NONE:
94
        Guild has no MFA/2FA requirement for moderation actions.
95
    ELEVATED:
96
        Guild has a 2FA requirement for moderation actions
97
    """
98
    NONE = 0
99
    ELEVATED = 1
100
101
102
class VerificationLevel(IntEnum):
103
    """Represents the verification level of a guild.
104
    Attributes
105
    ----------
106
    NONE:
107
        Unrestricted.
108
    LOW:
109
        Must have verified email on account.
110
    MEDIUM:
111
        Must be registered on Discord for longer than 5 minutes.
112
    HIGH:
113
        Must be a member of the server for longer than 10 minutes.
114
    VERY_HIGH:
115
        Must have a verified phone number.
116
    """
117
    NONE = 0
118
    LOW = 1
119
    MEDIUM = 2
120
    HIGH = 3
121
    VERY_HIGH = 4
122
123
124
class DefaultMessageNotificationLevel(IntEnum):
125
    """Represents the default message notification level of a guild.
126
    Attributes
127
    ----------
128
    ALL_MESSAGES:
129
        Members will receive notifications for all messages by default.
130
    ONLY_MENTIONS:
131
        Members will receive notifications only for messages that @mention them by default.
132
    """
133
    # noqa: E501
134
    ALL_MESSAGES = 0
135
    ONLY_MENTIONS = 1
136
137
138
class SystemChannelFlags(IntEnum):
139
    """Represents the system channel flags of a guild.
140
    Attributes
141
    ----------
142
    SUPPRESS_JOIN_NOTIFICATIONS:
143
        Suppress member join notifications.
144
    SUPPRESS_PREMIUM_SUBSCRIPTIONS:
145
        Suppress server boost notifications.
146
    SUPPRESS_GUILD_REMINDER_NOTIFICATIONS:
147
        Suppress server setup tips.
148
    SUPPRESS_JOIN_NOTIFICATION_REPLIES:
149
        Hide member join sticker reply buttons
150
    """
151
    SUPPRESS_JOIN_NOTIFICATIONS = 1 << 0
152
    SUPPRESS_PREMIUM_SUBSCRIPTIONS = 1 << 1
153
    SUPPRESS_GUILD_REMINDER_NOTIFICATIONS = 1 << 2
154
    SUPPRESS_JOIN_NOTIFICATION_REPLIES = 1 << 3
155
156
157
@dataclass
0 ignored issues
show
best-practice introduced by
Too many instance attributes (10/7)
Loading history...
158
class GuildPreview(APIObject):
159
    """Represents a guild preview.
160
    Attributes
161
    ----------
162
    id: :class:`Snowflake`
163
        The guild ID.
164
    name: :class:`str`
165
        The guild name.
166
    icon: :class:`str`
167
        The guild icon hash.
168
    splash: :class:`str`
169
        The guild splash hash.
170
    discovery_splash: :class:`str`
171
        The guild discovery splash hash.
172
    emojis: :class:`List[Emoji]`
173
        The guild emojis.
174
    features: :class:`List[GuildFeature]`
175
        The guild features.
176
    approximate_member_count: :class:`int`
177
        The approximate member count.
178
    approximate_presence_count: :class:`int`
179
        The approximate number of online members in this guild
180
    description: :class:`str`
181
        The guild description.
182
    """
183
    id: Snowflake
184
    name: str
185
    emojis: List[Emoji]
186
    features: List[GuildFeature]
187
    approximate_member_count: int
188
    approximate_presence_count: int
189
190
    icon: APINullable[str] = MISSING
191
    splash: APINullable[str] = MISSING
192
    discovery_splash: APINullable[str] = MISSING
193
    description: APINullable[str] = MISSING
194
195
196
@dataclass
0 ignored issues
show
best-practice introduced by
Too many instance attributes (59/7)
Loading history...
197
class Guild(APIObject):
198
    """Represents a Discord guild/server in which your client resides.
199
    Attributes
200
    ----------
201
    afk_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
202
        Id of afk channel
203
    afk_timeout: :class:`int`
204
        Afk timeout in seconds
205
    application_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
206
        Application id of the guild creator if it is bot-created
207
    banner: Optional[:class:`str`]
208
        Banner hash
209
    default_message_notifications: :class:`~pincer.objects.guild.guild.DefaultMessageNotificationLevel`
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (103/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
210
        Default message notifications level
211
    description: Optional[:class:`str`]
212
        The description of a Community guild
213
    discovery_splash: Optional[:class:`str`]
214
        Discovery splash hash;
215
        only present for guilds with the "DISCOVERABLE" feature
216
    emojis: List[:class:`~pincer.objects.message.emoji.Emoji`]
217
        Custom guild emojis
218
    explicit_content_filter: :class:`~pincer.objects.guild.guild.ExplicitContentFilterLevel`
219
        Explicit content filter level
220
    features: List[:class:`~pincer.objects.guild.features.GuildFeature`]
221
        Enabled guild features
222
    id: :class:`~pincer.utils.snowflake.Snowflake`
223
        Guild id
224
    icon: Optional[:class:`str`]
225
        Icon hash
226
    mfa_level: :class:`~pincer.objects.guild.guild.MFALevel`
227
        Required MFA level for the guild
228
    name: :class:`str`
229
        Guild name (2-100 characters, excluding trailing and leading
230
        whitespace)
231
    nsfw_level: :class:`~pincer.objects.guild.guild.NSFWLevel`
232
        Guild NSFW level
233
    owner_id: :class:`~pincer.utils.snowflake.Snowflake`
234
        Id of owner
235
    preferred_locale: :class:`str`
236
        The preferred locale of a Community guild;
237
        used in server discovery and notices from Discord;
238
        defaults to "en-US"
239
    premium_tier: :class:`~pincer.objects.guild.guild.PremiumTier`
240
        Premium tier (Server Boost level)
241
    public_updates_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
242
        The id of the channel where admins
243
        and moderators of Community guilds receive notices from Discord
244
    roles: List[:class:`~pincer.objects.guild.role.Role`]
245
        Roles in the guild
246
    rules_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
247
        The id of the channel where Community guilds can display rules
248
        and/or guidelines
249
    splash: Optional[:class:`str`]
250
        Splash hash
251
    system_channel_flags: :class:`~pincer.objects.guild.guild.SystemChannelFlags`
252
        System channel flags
253
    system_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
254
        The id of the channel where guild notices
255
        such as welcome messages and boost events are posted
256
    vanity_url_code: Optional[:class:`str`]
257
        The vanity url code for the guild
258
    verification_level: :class:`~pincer.objects.guild.guild.VerificationLevel`
259
        Verification level required for the guild
260
    approximate_member_count: APINullable[:class:`int`]
261
        Approximate number of members in this guild, returned from the
262
        `GET /guilds/<id>` endpoint when with_counts is true
263
    approximate_presence_count: APINullable[:class:`int`]
264
        Approximate number of non-offline members in this guild,
265
        returned from the `GET /guilds/<id>`
266
        endpoint when with_counts is true
267
    channels: APINullable[List[:class:`~pincer.objects.guild.channel.Channel`]]
268
        Channels in the guild
269
    icon_hash: APINullable[Optional[:class:`str`]]
270
        Icon hash, returned when in the template object
271
    joined_at: APINullable[:class:`~pincer.utils.timestamp.Timestamp`]
272
        When this guild was joined at
273
    large: APINullable[:class:`bool`]
274
        True if this is considered a large guild
275
    max_members: APINullable[:class:`int`]
276
        The maximum number of members for the guild
277
    max_presences: APINullable[Optional[:class:`int`]]
278
        The maximum number of presences for the guild
279
        (null is always returned, apart from the largest of guilds)
280
    max_video_channel_users: APINullable[:class:`int`]
281
        The maximum amount of users in a video channel
282
    members: APINullable[List[:class:`~pincer.objects.guild.member.GuildMember`]]
283
        Users in the guild
284
    member_count: APINullable[:class:`bool`]
285
        Total number of members in this guild
286
    nsfw: APINullable[:class:`bool`]
287
        Boolean if the server is NSFW
288
    owner: APINullable[:class:`bool`]
289
        True if the user is the owner of the guild
290
    permissions: APINullable[:class:`str`]
291
        Total permissions for the user in the guild
292
        (excludes overwrites)
293
    premium_subscription_count: APINullable[:class:`int`]
294
        The number of boosts this guild currently has
295
    presences: APINullable[List[:class:`~pincer.objects.events.presence.PresenceUpdateEvent`]]
296
        Presences of the members in the guild,
297
        will only include non-offline members if the size is greater
298
        than large threshold
299
    stage_instances: APINullable[List[:class:`~pincer.objects.guild.stage.StageInstance`]]
300
        Stage instances in the guild
301
    stickers: Optional[List[:class:`~pincer.objects.message.sticker.Sticker`]]
302
        Custom guild stickers
303
    region: APINullable[Optional[:class:`str`]]
304
        Voice region id for the guild (deprecated)
305
    threads: APINullable[List[:class:`~pincer.objects.guild.channel.Channel`]]
306
        All active threads in the guild that current user
307
        has permission to view
308
    unavailable: APINullable[:class:`bool`]
309
        True if this guild is unavailable due to an outage
310
    voice_states: APINullable[List[:class:`~pincer.objects.user.voice_state.VoiceState`]]
311
        States of members currently in voice channels;
312
        lacks the guild_id key
313
    widget_enabled: APINullable[:class:`bool`]
314
        True if the server widget is enabled
315
    widget_channel_id: APINullable[Optional[:class:`~pincer.utils.snowflake.Snowflake`]]
316
        The channel id that the widget will generate an invite to,
317
        or null if set to no invite
318
    welcome_screen: APINullable[:class:`~pincer.objects.guild.welcome_screen.WelcomeScreen`]
319
        The welcome screen of a Community guild, shown to new members,
320
        returned in an Invite's guild object
321
    """
322
    # noqa: E501
323
    afk_timeout: int
324
    default_message_notifications: DefaultMessageNotificationLevel
325
    emojis: List[Emoji]
326
    explicit_content_filter: ExplicitContentFilterLevel
327
    features: List[GuildFeature]
328
    id: Snowflake
329
    mfa_level: MFALevel
330
    name: str
331
    nsfw_level: GuildNSFWLevel
332
    owner_id: Snowflake
333
    preferred_locale: str
334
    premium_tier: PremiumTier
335
    roles: List[Role]
336
    system_channel_flags: SystemChannelFlags
337
    verification_level: VerificationLevel
338
339
    guild_scheduled_events: APINullable[List] = MISSING
340
    lazy: APINullable[bool] = MISSING
341
    premium_progress_bar_enabled: APINullable[bool] = MISSING
342
    guild_hashes: APINullable[Dict] = MISSING
343
    afk_channel_id: APINullable[Snowflake] = MISSING
344
    application_id: APINullable[Snowflake] = MISSING
345
    embedded_activities: APINullable[List] = MISSING
346
    banner: APINullable[str] = MISSING
347
    description: APINullable[str] = MISSING
348
    discovery_splash: APINullable[str] = MISSING
349
    icon: APINullable[str] = MISSING
350
    public_updates_channel_id: APINullable[Snowflake] = MISSING
351
    rules_channel_id: APINullable[Snowflake] = MISSING
352
    splash: APINullable[str] = MISSING
353
    system_channel_id: APINullable[Snowflake] = MISSING
354
    vanity_url_code: APINullable[str] = MISSING
355
356
    application_command_counts: APINullable[Dict] = MISSING
357
    application_command_count: APINullable[int] = MISSING
358
    approximate_member_count: APINullable[int] = MISSING
359
    approximate_presence_count: APINullable[int] = MISSING
360
    channels: APINullable[List[Channel]] = field(default_factory=list)
361
    # TODO: Add type when type is known
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
362
    hub_type: APINullable[Any] = MISSING
363
    icon_hash: APINullable[Optional[str]] = MISSING
364
    joined_at: APINullable[Timestamp] = MISSING
365
    large: APINullable[bool] = MISSING
366
    max_members: APINullable[int] = MISSING
367
    max_presences: APINullable[Optional[int]] = MISSING
368
    max_video_channel_users: APINullable[int] = MISSING
369
    members: APINullable[List[GuildMember]] = MISSING
370
    member_count: APINullable[bool] = MISSING
371
    nsfw: APINullable[bool] = MISSING
372
    # Note: This is missing from discord's docs but in the api
373
    owner: APINullable[bool] = MISSING
374
    permissions: APINullable[str] = MISSING
375
    premium_subscription_count: APINullable[int] = MISSING
376
    presences: APINullable[List[PresenceUpdateEvent]] = MISSING
377
    stage_instances: APINullable[List[StageInstance]] = MISSING
378
    stickers: APINullable[List[Sticker]] = MISSING
379
    region: APINullable[Optional[str]] = MISSING
380
    threads: APINullable[List[Channel]] = MISSING
381
    # Guilds are considered available unless otherwise specified
382
    unavailable: APINullable[bool] = False
383
    voice_states: APINullable[List[VoiceState]] = MISSING
384
    widget_enabled: APINullable[bool] = MISSING
385
    widget_channel_id: APINullable[Optional[Snowflake]] = MISSING
386
    welcome_screen: APINullable[WelcomeScreen] = MISSING
387
388
    @classmethod
389
    async def from_id(cls, client: Client, _id: Union[int, Snowflake]) -> Guild:
390
        """
391
        Parameters
392
        ----------
393
        client : `~pincer.Client`
394
            Client object to use the http gateway from.
395
        _id : :class: `pincer.utils.snowflake.Snowflake`
396
            Guild ID.
397
        Returns
398
        -------
399
        :class: `~pincer.objects.guild.guild.Guild`
400
            The new guild object.
401
        """
402
        data = await client.http.get(f"/guilds/{_id}")
403
        channel_data = await client.http.get(f"/guilds/{_id}/channels")
404
405
        data["channels"]: List[Channel] = [
406
            Channel.from_dict({**i, "_client": client, "_http": client.http})
407
            for i in (channel_data or [])
408
        ]
409
410
        return Guild.from_dict(construct_client_dict(client, data))
411
412
    async def get_member(self, _id: int) -> GuildMember:
413
        """|coro|
414
        Fetches a GuildMember from its identifier
415
        Parameters
416
        ----------
417
        _id:
418
            The id of the guild member which should be fetched from the Discord
419
            gateway.
420
        Returns
421
        -------
422
        :class:`~pincer.objects.guild.member.GuildMember`
423
            A GuildMember object.
424
        """
425
        return await GuildMember.from_id(self._client, self.id, _id)
426
427
    @overload
428
    async def modify_member(
429
            self, *,
430
            _id: int,
431
            nick: Optional[str] = None,
432
            roles: Optional[List[Snowflake]] = None,
433
            mute: Optional[bool] = None,
434
            deaf: Optional[bool] = None,
435
            channel_id: Optional[Snowflake] = None
436
    ) -> GuildMember:
437
        """|coro|
438
        Modifies a member in the guild from its identifier and based on the
439
        keyword arguments provided.
440
        Parameters
441
        ----------
442
        _id : int
443
            Id of the member to modify
444
        nick : Optional[:class:`str`]
445
            New nickname for the member |default| :data:`None`
446
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake]]
447
            New roles for the member |default| :data:`None`
448
        mute : Optional[:class:`bool`]
449
            Whether the member is muted |default| :data:`None`
450
        deaf : Optional[:class:`bool`]
451
            Whether the member is deafened |default| :data:`None`
452
        channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake]
453
            Voice channel id to move to |default| :data:`None`
454
        Returns
455
        -------
456
        :class:`~pincer.objects.guild.member.GuildMember`
457
            The new member object.
458
        """
459
        ...
460
461
    async def modify_member(self, _id: int, **kwargs) -> GuildMember:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
462
        data = await self._http.patch(
463
            f"guilds/{self.id}/members/{_id}",
464
            data=kwargs
465
        )
466
        return GuildMember.from_dict(construct_client_dict(self._client, data))
467
468
    async def ban(self, member_id: int, **kwargs):
469
        """|coro|
470
        Bans a guild member.
471
        Parameters
472
        ----------
473
        member_id : :class:`int`
474
            ID of the guild member to ban.
475
        \\*\\* kwargs
476
            Additional keyword arguments to ban the guild member with.
477
        """
478
        await self._http.put(f"guilds/{self.id}/bans/{member_id}", data=kwargs)
479
480
    async def kick(self, member_id: int):
481
        """|coro|
482
        Kicks a guild member.
483
        Parameters
484
        ----------
485
        member_id : :class:`int`
486
            ID of the guild member to kick.
487
        """
488
        await self._http.delete(f"guilds/{self.id}/members/{member_id}")
489
490
    async def get_roles(self):
491
        """|coro|
492
        Fetches all the roles in the guild.
493
494
        Returns
495
        -------
496
        List[:class:`~pincer.objects.guild.role.Role`]
497
            A list of Role objects.
498
        """
499
        data = await self._http.get(f"guilds/{self.id}/roles")
500
        return [Role.from_dict(construct_client_dict(self._client, i)) for i in data]
501
502
    @overload
503
    async def create_role(
504
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
505
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
506
        name: Optional[str] = "new role",
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
507
        permissions: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
508
        color: Optional[int] = 0,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
509
        hoist: Optional[bool] = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
510
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
511
        unicode_emoji: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
512
        mentionable: Optional[bool] = False
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
513
    ) -> Role:
514
        """|coro|
515
        Creates a new role for the guild.
516
        Requires the `MANAGE_ROLES` permission.
517
518
        Parameters
519
        ----------
520
        name : Optional[:class:`str`]
521
            name of the role |default| data:`"new role"`
522
        permissions : Optional[:class:`str`]
523
            bitwise value of the enabled/disabled
524
            permissions |default| data:`None`
525
        color : Optional[:class:`int`]
526
            RGB color value |default| data:`0`
527
        hoist : Optional[:class:`bool`]
528
            whether the role should be displayed
529
            separately in the sidebar |default| data:`False`
530
        icon : Optional[:class:`str`]
531
            the role's icon image (if the guild has
532
            the `ROLE_ICONS` feature) |default| data:`None`
533
        unicode_emoji : Optional[:class:`str`]
534
            the role's unicode emoji as a standard emoji (if the guild
535
            has the `ROLE_ICONS` feature) |default| data:`None`
536
        mentionable : Optional[:class:`bool`]
537
            whether the role should be mentionable |default| data:`False`
538
539
        Returns
540
        -------
541
        :class:`~pincer.objects.guild.role.Role`
542
            The new role object.
543
        """
544
        ...
545
546
    async def create_role(self, **kwargs) -> Role:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
547
        return await self._http.post(f"guilds/{self.id}/roles", data=kwargs)
548
549
    async def edit_role_position(
550
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
551
        id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Bug Best Practice introduced by
This seems to re-define the built-in id.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
552
        position: Optional[int] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
553
    ) -> List[Role]:
554
        """|coro|
555
        Edits the position of a role.
556
557
        Parameters
558
        ----------
559
        id : :class:`~pincer.utils.snowflake.Snowflake`
560
            The role ID
561
        position : Optional[:class:`int`]
562
            Sorting position of the role |default| data:`None`
563
564
        Returns
565
        -------
566
        List[:class:`~pincer.objects.guild.role.Role`]
567
            A list of all of the guild's role objects.
568
        """
569
        return [
570
            Role.from_dict(construct_client_dict(self._client, i))
571
            for i in await self._http.patch(
572
                f"guilds/{self.id}/roles",
573
                data={"id": id, "position": position}
574
            )
575
        ]
576
577
    @overload
578
    async def edit_role(
579
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
580
        id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Bug Best Practice introduced by
This seems to re-define the built-in id.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
581
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
582
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
583
        permissions: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
584
        color: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
585
        hoist: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
586
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
587
        unicode_emoji: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
588
        mentionable: Optional[bool] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
589
    ) -> Role:
590
        """|coro|
591
        Edits a role.
592
        Requires the `MANAGE_ROLES` permission.
593
594
        Parameters
595
        ----------
596
        id : :class:`~pincer.utils.snowflake.Snowflake`
597
            The role ID
598
        name : Optional[:class:`str`]
599
            Name of the role |default| data:`None`
600
        permissions : Optional[:class:`str`]
601
            Bitwise value of the enabled/disabled
602
            permissions |default| data:`None`
603
        color : Optional[:class:`int`]
604
            RGB color value |default| data:`None`
605
        hoist : Optional[:class:`bool`]
606
            Whether the role should be displayed
607
            separately in the sidebar |default| data:`None`
608
        icon : Optional[:class:`str`]
609
            The role's icon image (if the guild has
610
            the `ROLE_ICONS` feature) |default| data:`None`
611
        unicode_emoji : Optional[:class:`str`]
612
            The role's unicode emoji as a standard emoji (if the guild
613
            has the `ROLE_ICONS` feature) |default| data:`None`
614
        mentionable : Optional[:class:`bool`]
615
            Whether the role should be mentionable |default| data:`None`
616
617
        Returns
618
        -------
619
        :class:`~pincer.objects.guild.role.Role`
620
            The edited role object.
621
        """
622
        ...
623
624
    async def edit_role(self, id: Snowflake, **kwargs) -> Role:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
Bug Best Practice introduced by
This seems to re-define the built-in id.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
625
        return Role.from_dict(
626
            construct_client_dict(
627
                self._client,
628
                await self._http.patch(f"guilds/{self.id}/roles/{id}", data=kwargs)
629
            )
630
        )
631
632
    async def delete_role(self, id: Snowflake):
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in id.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
633
        """|coro|
634
        Deletes a role.
635
        Requires the `MANAGE_ROLES` permission.
636
        Returns `204 No Content` on success.
637
638
        Parameters
639
        ----------
640
        id : :class:`~pincer.utils.snowflake.Snowflake`
641
            The role ID
642
        """
643
        await self._http.delete(f"guilds/{self.id}/roles/{id}")
644
645
    async def get_bans(self) -> List[Ban]:
646
        """|coro|
647
        Fetches all the bans in the guild.
648
649
        Returns
650
        -------
651
        List[:class:`~pincer.objects.guild.ban.Ban`]
652
            A list of Ban objects.
653
        """
654
        data = await self._http.get(f"guilds/{self.id}/bans")
655
        return [Ban.from_dict(construct_client_dict(self._client, i)) for i in data]
656
657
    async def get_ban(self, id: Snowflake) -> Ban:
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in id.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
658
        """|coro|
659
        Fetches a ban from the guild.
660
        Returns `404 Not Found` if the user is not banned.
661
662
        Parameters
663
        ----------
664
        id : :class:`~pincer.utils.snowflake.Snowflake`
665
            The user ID
666
667
        Returns
668
        -------
669
        :class:`~pincer.objects.guild.ban.Ban`
670
            The Ban object.
671
        """
672
        return Ban.from_dict(
673
            construct_client_dict(
674
                self._client,
675
                await self._http.get(f"guilds/{self.id}/bans/{id}")
676
            )
677
        )
678
679
    async def unban(self, id: Snowflake):
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in id.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
680
        """|coro|
681
        Unbans a user from the guild.
682
        Returns `204 No Content` on success.
683
684
        Parameters
685
        ----------
686
        id : :class:`~pincer.utils.snowflake.Snowflake`
687
            The user ID
688
        """
689
        await self._http.delete(f"guilds/{self.id}/bans/{id}")
690
691
    @overload
692
    async def edit(
0 ignored issues
show
Comprehensibility introduced by
This function exceeds the maximum number of variables (20/15).
Loading history...
693
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
694
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
695
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
696
        region: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
697
        verification_level: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
698
        default_message_notifications: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
699
        explicit_content_filter: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
700
        afk_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
701
        afk_timeout: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
702
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
703
        owner_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
704
        splash: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
705
        discovery_splash: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
706
        banner: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
707
        system_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
708
        system_channel_flags: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
709
        rules_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
710
        public_updates_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
711
        preferred_locale: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
712
        features: Optional[List[GuildFeature]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
713
        description: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
714
    ) -> Guild:
715
        """|coro|
716
        Modifies the guild
717
718
        Parameters
719
        ----------
720
        name : Optional[:class:`str`]
721
            Guild name |default| :data:`None`
722
        region : Optional[:class:`str`]
723
            Guild voice region ID |default| :data:`None`
724
        verification_level : Optional[:class:`int`]
725
            Verification level |default| :data:`None`
726
        default_message_notifications : Optional[:class:`int`]
727
            Default message notification level |default| :data:`None`
728
        explicit_content_filter : Optional[:class:`int`]
729
            Explicit content filter level |default| :data:`None`
730
        afk_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
731
            ID for AFK channel |default| :data:`None`
732
        afk_timeout : Optional[:class:`int`]
733
            AFK timeout in seconds |default| :data:`None`
734
        icon : Optional[:class:`str`]
735
            base64 1024x1024 png/jpeg/gif image for the guild icon
736
            (can be animated gif when the server
737
            has the `ANIMATED_ICON` feature) |default| :data:`None`
738
        owner_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
739
            User ID to transfer guild ownership to (must be owner) |default| :data:`None`
740
        splash : Optional[:class:`str`]
741
            base64 16:9 png/jpeg image for the guild splash (when the
742
            server has the `INVITE_SPLASH` feature) |default| :data:`None`
743
        discovery_splash : Optional[:class:`str`]
744
            base64 16:9 png/jpeg image for the guild discovery splash
745
            (when the server has the `DISCOVERABLE` feature) |default| :data:`None`
746
        banner : Optional[:class:`str`]
747
            base64 16:9 png/jpeg image for the guild banner (when the
748
            server has the `BANNER` feature) |default| :data:`None`
749
        system_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
750
            The ID of the channel where guild notices such as welcome
751
            messages and boost events are posted |default| :data:`None`
752
        system_channel_flags : Optional[:class:`int`]
753
            System channel flags |default| :data:`None`
754
        rules_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
755
            The ID of the channel where Community guilds display rules
756
            and/or guidelines |default| :data:`None`
757
        public_updates_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
758
            The ID of the channel where admins and moderators of
759
            Community guilds receive notices from Discord |default| :data:`None`
760
        preferred_locale : Optional[:class:`str`]
761
            The preferred locale of a Community guild used in server
762
            discovery and notices from Discord; defaults to "en-US" |default| :data:`None`
763
        features : Optional[List[:class:`GuildFeature`]]
764
            Enabled guild features |default| :data:`None`
765
        description : Optional[:class:`str`]
766
            The description for the guild, if the guild is discoverable |default| :data:`None`
767
768
        Returns
769
        -------
770
        :class:`~pincer.objects.guild.Guild`
771
            The modified guild object.
772
        """
773
        ...
774
775
    async def edit(self, **kwargs) -> Guild:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
776
        g = await self._http.patch(f"guilds/{self.id}", data=kwargs)
777
        return Guild.from_dict(construct_client_dict(self._client, g))
778
779
    async def preview(self) -> GuildPreview:
780
        """|coro|
781
        Previews the guild.
782
783
        Returns
784
        -------
785
        :class:`~pincer.objects.guild.guild.GuildPreview`
786
            The guild preview object.
787
        """
788
        data = await self._http.get(f"guilds/{self.id}/preview")
789
        return GuildPreview.from_dict(data)
790
791
    async def delete(self):
792
        """|coro|
793
        Deletes the guild. Returns `204 No Content` on success.
794
        """
795
        await self._http.delete(f"guilds/{self.id}")
796
797
    @classmethod
798
    def from_dict(cls, data) -> Guild:
799
        """
800
        Parameters
801
        ----------
802
        data : :class:`Dict`
803
            Guild data received from the discord API.
804
        Returns
805
        -------
806
        :class: `~pincer.objects.guild.guild.Guild`
807
            The new guild object.
808
        Raises
809
        :class: `~pincer.exceptions.UnavailableGuildError`
810
            The guild is unavailable due to a discord outage.
811
        """
812
        if data.get("unavailable", False):
813
            raise UnavailableGuildError(
814
                f"Guild \"{data['id']}\" is unavailable due to a discord"
815
                " outage."
816
            )
817
818
        return super().from_dict(data)
819
820
821
@dataclass
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
822
class UnavailableGuild(APIObject):
823
    id: Snowflake
824
    unavailable: bool = True
825