15
15
16
16
if TYPE_CHECKING :
17
17
from interactions .client import Client
18
- from interactions .models import TYPE_GUILD_CHANNEL
18
+ from interactions .models import TYPE_GUILD_CHANNEL , Guild
19
19
from interactions .models .discord .user import User
20
20
from interactions .models .discord .snowflake import Snowflake_Type
21
21
25
25
@attrs .define (eq = False , order = False , hash = False , kw_only = True )
26
26
class Invite (ClientObject ):
27
27
code : str = attrs .field (repr = True )
28
- """the invite code (unique ID)"""
28
+ """The invite code (unique ID)"""
29
29
30
30
# metadata
31
31
uses : int = attrs .field (default = 0 , repr = True )
32
- """the guild this invite is for """
32
+ """How many times this invite has been used """
33
33
max_uses : int = attrs .field (repr = False , default = 0 )
34
- """max number of times this invite can be used"""
34
+ """Max number of times this invite can be used"""
35
35
max_age : int = attrs .field (repr = False , default = 0 )
36
- """duration (in seconds) after which the invite expires"""
36
+ """Duration (in seconds) after which the invite expires"""
37
37
created_at : Timestamp = attrs .field (default = MISSING , converter = optional_c (timestamp_converter ), repr = True )
38
- """when this invite was created"""
38
+ """When this invite was created"""
39
39
temporary : bool = attrs .field (default = False , repr = True )
40
- """whether this invite only grants temporary membership"""
40
+ """Whether this invite only grants temporary membership"""
41
41
42
42
# target data
43
43
target_type : Optional [Union [InviteTargetType , int ]] = attrs .field (
44
44
default = None , converter = optional_c (InviteTargetType ), repr = True
45
45
)
46
- """the type of target for this voice channel invite"""
46
+ """The type of target for this voice channel invite"""
47
47
approximate_presence_count : Optional [int ] = attrs .field (repr = False , default = MISSING )
48
- """approximate count of online members, returned from the `GET / invites/<code>` endpoint when `with_counts` is `True`"""
48
+ """Approximate count of online members, returned when fetching invites with `with_counts` set as `True`"""
49
49
approximate_member_count : Optional [int ] = attrs .field (repr = False , default = MISSING )
50
- """approximate count of total members, returned from the `GET / invites/<code>` endpoint when `with_counts` is `True`"""
50
+ """Approximate count of total members, returned when fetching invites with `with_counts` set as `True`"""
51
51
scheduled_event : Optional ["Snowflake_Type" ] = attrs .field (
52
52
default = None , converter = optional_c (to_snowflake ), repr = True
53
53
)
54
- """guild scheduled event data, only included if `guild_scheduled_event_id` contains a valid guild scheduled event id"""
54
+ """Guild scheduled event data, only included if `guild_scheduled_event_id` contains a valid guild scheduled event id"""
55
55
expires_at : Optional [Timestamp ] = attrs .field (default = None , converter = optional_c (timestamp_converter ), repr = True )
56
- """the expiration date of this invite, returned from the `GET / invites/<code>` endpoint when `with_expiration` is `True`"""
56
+ """The expiration date of this invite, returned when fetching invites with `with_expiration` set as `True`"""
57
57
stage_instance : Optional [StageInstance ] = attrs .field (repr = False , default = None )
58
- """stage instance data if there is a public Stage instance in the Stage channel this invite is for (deprecated)"""
58
+ """Stage instance data if there is a public Stage instance in the Stage channel this invite is for (deprecated)"""
59
59
target_application : Optional [dict ] = attrs .field (repr = False , default = None )
60
- """the embedded application to open for this voice channel embedded application invite"""
60
+ """The embedded application to open for this voice channel embedded application invite"""
61
61
guild_preview : Optional [GuildPreview ] = attrs .field (repr = False , default = MISSING )
62
- """the guild this invite is for"""
62
+ """The guild this invite is for - not given in invite events """
63
63
64
64
# internal for props
65
65
_channel_id : "Snowflake_Type" = attrs .field (converter = to_snowflake , repr = True )
66
+ _guild_id : Optional ["Snowflake_Type" ] = attrs .field (default = None , converter = optional_c (to_snowflake ), repr = True )
66
67
_inviter_id : Optional ["Snowflake_Type" ] = attrs .field (default = None , converter = optional_c (to_snowflake ), repr = True )
67
68
_target_user_id : Optional ["Snowflake_Type" ] = attrs .field (
68
69
repr = False , default = None , converter = optional_c (to_snowflake )
69
70
)
70
71
71
72
@property
72
- def channel (self ) -> "TYPE_GUILD_CHANNEL" :
73
- """The channel the invite is for."""
73
+ def channel (self ) -> Optional [ "TYPE_GUILD_CHANNEL" ] :
74
+ """The cached channel the invite is for."""
74
75
return self ._client .cache .get_channel (self ._channel_id )
75
76
77
+ @property
78
+ def guild (self ) -> Optional ["Guild" ]:
79
+ """The cached guild the invite is."""
80
+ return self ._client .cache .get_guild (self ._guild_id ) if self ._guild_id else None
81
+
76
82
@property
77
83
def inviter (self ) -> Optional ["User" ]:
78
84
"""The user that created the invite or None."""
@@ -95,16 +101,23 @@ def _process_dict(cls, data: Dict[str, Any], client: "Client") -> Dict[str, Any]
95
101
data ["scheduled_event" ] = data ["target_event_id" ]
96
102
97
103
if channel := data .pop ("channel" , None ):
98
- # invite metadata does not contain enough info to create a channel object
104
+ client . cache . place_channel_data ( channel )
99
105
data ["channel_id" ] = channel ["id" ]
100
106
101
107
if guild := data .pop ("guild" , None ):
102
108
data ["guild_preview" ] = GuildPreview .from_dict (guild , client )
109
+ data ["guild_id" ] = guild ["id" ]
110
+ elif guild_id := data .pop ("guild_id" , None ):
111
+ data ["guild_id" ] = guild_id
103
112
104
113
if inviter := data .pop ("inviter" , None ):
105
114
inviter = client .cache .place_user_data (inviter )
106
115
data ["inviter_id" ] = inviter .id
107
116
117
+ if target_user := data .pop ("target_user" , None ):
118
+ target_user = client .cache .place_user_data (target_user )
119
+ data ["target_user_id" ] = target_user .id
120
+
108
121
return data
109
122
110
123
def __str__ (self ) -> str :
0 commit comments