Passed
Pull Request — main (#393)
by Yohann
03:30 queued 01:19
created

pincer.objects.guild.invite.Invite.delete()   A

Complexity

Conditions 1

Size

Total Lines 13
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 13
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 TYPE_CHECKING
9
10
from ...utils.api_object import APIObject
11
from ...utils.types import MISSING
12
13
if TYPE_CHECKING:
14
    from typing import List, Optional
15
16
    from .guild import Guild
17
    from ..app.application import Application
18
    from ..guild.channel import Channel
19
    from ..guild.member import GuildMember
20
    from ..user.user import User
21
    from ...utils.timestamp import Timestamp
22
    from ...utils.types import APINullable
23
24
25
class InviteTargetType(IntEnum):
26
    """Represents the type of the invite.
27
28
    Attributes
29
    ----------
30
    STREAM:
31
        A normal Discord invite, e.g. for a channel or guild.
32
    EMBEDDED_APPLICATION:
33
        An embedded application invite, e.g. poker-night etc.
34
    """
35
    STREAM = 1
36
    EMBEDDED_APPLICATION = 2
37
38
39
@dataclass(repr=False)
40
class InviteStageInstance(APIObject):
41
    """Represents an invite for a Discord stages channel.
42
43
    Attributes
44
    ----------
45
    members: List[:class:`~pincer.objects.guild.member.GuildMember`]
46
        the members speaking in the Stage
47
    participant_count: :class:`int`
48
        the number of users in the Stage
49
    speaker_count: :class:`int`
50
        the number of users speaking in the Stage
51
    topic: :class:`str`
52
        the topic of the Stage instance (1-120 characters)
53
    """
54
    members: List[GuildMember]
55
    participant_count: int
56
    speaker_count: int
57
    topic: str
58
59
60
@dataclass(repr=False)
61
class Invite(APIObject):
0 ignored issues
show
best-practice introduced by
Too many instance attributes (16/7)
Loading history...
62
    """Represents a Discord invite. Can also include information from InviteMetadata.
63
64
    Attributes
65
    ----------
66
    channel: :class:`~pincer.objects.guild.channel.Channel`
67
        The channel this invite is for
68
    code: :class:`str`
69
        The invite code (unique ID)
70
    approximate_member_count: APINullable[:class:`int`]
71
        Approximate count of total members, returned from the GET
72
        /invites/<code> endpoint when with_counts is true
73
    approximate_presence_count: APINullable[:class:`int`]
74
        Approximate count of online members, returned from the GET
75
        /invites/<code> endpoint when with_counts is true
76
    expires_at: APINullable[Optional[:class:`~pincer.utils.timestamp.Timestamp`]]
77
        The expiration date of this invite, returned from the GET
78
        /invites/<code> endpoint when with_expiration is true
79
    inviter: APINullable[:class:`~pincer.objects.user.user.User`]
80
        The user who created the invite
81
    guild: :class:`~pincer.objects.guild.guild.Guild`
82
        The guild this invite is for
83
    stage_instance: :class:`~pincer.objects.guild.invite.InviteStageInstance`
84
        Stage instance data if there is a public Stage instance in the Stage
85
        channel this invite is for
86
    target_type: :class:`~pincer.objects.guild.invite.InviteTargetType`
87
        The type of target for this voice channel invite
88
    target_user: :class:`~pincer.objects.user.user.User`
89
        The user whose stream to display for this voice channel stream invite
90
    target_application: :class:`~pincer.objects.app.application.Application`
91
        The embedded application to open for this voice channel embedded
92
        application invite
93
    uses: APINullable[:class:`int`]
94
        number of times this invite has been used
95
    max_uses: APINullable[:class:`int`]
96
        Max number of times this invite can be used
97
    max_age: APINullable[:class:`int`]
98
        Duration (in seconds) after which the invite expires
99
    temporary:  APINullable[:class:`bool`]
100
        Whether this invite only grants temporary membership
101
    created_at: APINullable[:class:`~pincer.utils.timestamp.Timestamp`]
102
        When this invite was created
103
    """
104
    # noqa: E501
105
106
    channel: Channel
107
    code: str
108
109
    approximate_member_count: APINullable[int] = MISSING
110
    approximate_presence_count: APINullable[int] = MISSING
111
    expires_at: APINullable[Optional[Timestamp]] = MISSING
112
    inviter: APINullable[User] = MISSING
113
    guild: APINullable[Guild] = MISSING
114
    stage_instance: APINullable[InviteStageInstance] = MISSING
115
    target_type: APINullable[InviteTargetType] = MISSING
116
    target_user: APINullable[User] = MISSING
117
    target_application: APINullable[Application] = MISSING
118
    uses: APINullable[int] = MISSING
119
    max_uses: APINullable[int] = MISSING
120
    max_age: APINullable[int] = MISSING
121
    temporary: APINullable[bool] = MISSING
122
    created_at: APINullable[Timestamp] = MISSING
123
124
    def __repr__(self) -> str:
125
        return f"Invite(code={self.code}, channel={self.channel})"
126
127
    def __str__(self) -> str:
128
        return self.link
129
130
    @property
131
    def link(self):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
132
        return f"https://discord.gg/{self.code}"
133
134
    def delete(self):
135
        """Delete this invite.
136
137
        Raises
138
        ------
139
        Forbidden
140
            You do not have permission to delete this invite
141
        NotFound
142
            This invite does not exist
143
        HTTPException
144
            Deleting the invite failed
145
        """
146
        return self._http.delete(f"guilds/{self.guild.id}/invites/{self.code}")
147