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