aboutsummaryrefslogtreecommitdiff
path: root/discord
diff options
context:
space:
mode:
authorRapptz <[email protected]>2020-01-17 19:15:49 -0500
committerRapptz <[email protected]>2020-01-17 19:20:53 -0500
commit7b2c01c48a93a834c5cf9f0858b41f172431ce67 (patch)
tree3348dec9d580befe4222c4889eaac9de45bf37d8 /discord
parentMake CustomActivity.__str__ not raise errors and match the client (diff)
downloaddiscord.py-7b2c01c48a93a834c5cf9f0858b41f172431ce67.tar.xz
discord.py-7b2c01c48a93a834c5cf9f0858b41f172431ce67.zip
Add support for on_invite_create and on_invite_delete
Diffstat (limited to 'discord')
-rw-r--r--discord/invite.py22
-rw-r--r--discord/state.py9
2 files changed, 28 insertions, 3 deletions
diff --git a/discord/invite.py b/discord/invite.py
index 28458b7a..a70d39e4 100644
--- a/discord/invite.py
+++ b/discord/invite.py
@@ -25,7 +25,8 @@ DEALINGS IN THE SOFTWARE.
"""
from .asset import Asset
-from .utils import parse_time, snowflake_time
+from .utils import parse_time, snowflake_time, _get_as_snowflake
+from .object import Object
from .mixins import Hashable
from .enums import ChannelType, VerificationLevel, try_enum
from collections import namedtuple
@@ -228,7 +229,7 @@ class Invite(Hashable):
How long the before the invite expires in seconds. A value of 0 indicates that it doesn't expire.
code: :class:`str`
The URL fragment used for the invite.
- guild: Union[:class:`Guild`, :class:`PartialInviteGuild`]
+ guild: Union[:class:`Guild`, :class:`Object`, :class:`PartialInviteGuild`]
The guild the invite is for.
revoked: :class:`bool`
Indicates if the invite has been revoked.
@@ -248,7 +249,7 @@ class Invite(Hashable):
approximate_presence_count: Optional[:class:`int`]
The approximate number of members currently active in the guild.
This includes idle, dnd, online, and invisible members. Offline members are excluded.
- channel: Union[:class:`abc.GuildChannel`, :class:`PartialInviteChannel`]
+ channel: Union[:class:`abc.GuildChannel`, :class:`Object`, :class:`PartialInviteChannel`]
The channel the invite is for.
"""
@@ -292,6 +293,21 @@ class Invite(Hashable):
data['channel'] = channel
return cls(state=state, data=data)
+ @classmethod
+ def from_gateway(cls, *, state, data):
+ guild_id = _get_as_snowflake(data, 'guild_id')
+ guild = state._get_guild(guild_id)
+ channel_id = _get_as_snowflake(data, 'channel_id')
+ if guild is not None:
+ channel = guild.get_channel(channel_id) or Object(id=channel_id)
+ else:
+ guild = Object(id=guild_id)
+ channel = Object(id=channel_id)
+
+ data['guild'] = guild
+ data['channel'] = channel
+ return cls(state=state, data=data)
+
def __str__(self):
return self.url
diff --git a/discord/state.py b/discord/state.py
index a215ee3a..aea0984d 100644
--- a/discord/state.py
+++ b/discord/state.py
@@ -50,6 +50,7 @@ from .enums import ChannelType, try_enum, Status, Enum
from . import utils
from .embeds import Embed
from .object import Object
+from .invite import Invite
class ListenerType(Enum):
chunk = 0
@@ -537,6 +538,14 @@ class ConnectionState:
def parse_user_update(self, data):
self.user._update(data)
+ def parse_invite_create(self, data):
+ invite = Invite.from_gateway(state=self, data=data)
+ self.dispatch('invite_create', invite)
+
+ def parse_invite_delete(self, data):
+ invite = Invite.from_gateway(state=self, data=data)
+ self.dispatch('invite_delete', invite)
+
def parse_channel_delete(self, data):
guild = self._get_guild(utils._get_as_snowflake(data, 'guild_id'))
channel_id = int(data['id'])