Passed
Push — main ( 2a237c...d48b11 )
by Yohann
02:04 queued 11s
created

pincer.objects.guild.invite   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 142
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 52
dl 0
loc 142
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A Invite.__str__() 0 2 1
A Invite.__repr__() 0 2 1
A Invite.link() 0 3 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, eg for a channel or guild.
32
    EMBEDDED_APPLICATION:
33
        An embedded application invite, eg 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 InviteMetadata(APIObject):
62
    """Extra information about an invite, will extend the invite object.
63
64
    Attributes
65
    ----------
66
    uses: :class:`int`
67
        number of times this invite has been used
68
    max_uses: :class:`int`
69
        Max number of times this invite can be used
70
    max_age: :class:`int`
71
        Duration (in seconds) after which the invite expires
72
    temporary:  :class:`bool`
73
        Whether this invite only grants temporary membership
74
    created_at: :class:`~pincer.utils.timestamp.Timestamp`
75
        When this invite was created
76
    """
77
    uses: int
78
    max_uses: int
79
    max_age: int
80
    temporary: bool
81
    created_at: Timestamp
82
83
84
@dataclass(repr=False)
85
class Invite(APIObject):
0 ignored issues
show
best-practice introduced by
Too many instance attributes (11/7)
Loading history...
86
    """Represents a Discord invite.
87
88
    Attributes
89
    ----------
90
    channel: :class:`~pincer.objects.guild.channel.Channel`
91
        The channel this invite is for
92
    code: :class:`str`
93
        The invite code (unique ID)
94
    approximate_member_count: APINullable[:class:`int`]
95
        Approximate count of total members, returned from the GET
96
        /invites/<code> endpoint when with_counts is true
97
    approximate_presence_count: APINullable[:class:`int`]
98
        Approximate count of online members, returned from the GET
99
        /invites/<code> endpoint when with_counts is true
100
    expires_at: APINullable[Optional[:class:`~pincer.utils.timestamp.Timestamp`]]
101
        The expiration date of this invite, returned from the GET
102
        /invites/<code> endpoint when with_expiration is true
103
    inviter: APINullable[:class:`~pincer.objects.user.user.User`]
104
        The user who created the invite
105
    guild: :class:`~pincer.objects.guild.guild.Guild`
106
        The guild this invite is for
107
    stage_instance: :class:`~pincer.objects.guild.invite.InviteStageInstance`
108
        Stage instance data if there is a public Stage instance in the Stage
109
        channel this invite is for
110
    target_type: :class:`~pincer.objects.guild.invite.InviteTargetType`
111
        The type of target for this voice channel invite
112
    target_user: :class:`~pincer.objects.user.user.User`
113
        The user whose stream to display for this voice channel stream invite
114
    target_application: :class:`~pincer.objects.app.application.Application`
115
        The embedded application to open for this voice channel embedded
116
        application invite
117
    """
118
    # noqa: E501
119
120
    channel: Channel
121
    code: str
122
123
    approximate_member_count: APINullable[int] = MISSING
124
    approximate_presence_count: APINullable[int] = MISSING
125
    expires_at: APINullable[Optional[Timestamp]] = MISSING
126
    inviter: APINullable[User] = MISSING
127
    guild: APINullable[Guild] = MISSING
128
    stage_instance: APINullable[InviteStageInstance] = MISSING
129
    target_type: APINullable[InviteTargetType] = MISSING
130
    target_user: APINullable[User] = MISSING
131
    target_application: APINullable[Application] = MISSING
132
133
    def __repr__(self) -> str:
134
        return f"Invite(code={self.code}, channel={self.channel})"
135
136
    def __str__(self) -> str:
137
        return self.link
138
139
    @property
140
    def link(self):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
141
        return f"https://discord.gg/{self.code}"
142