aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2016-07-15 23:42:53 -0400
committerRapptz <[email protected]>2016-07-15 23:42:53 -0400
commitbd39c3ef458e7b78e1e4d49367544a04ab764131 (patch)
tree530bf5fe3769ff1dac9ccaaed08f545012711375
parentAdd support for querying information about group calls. (diff)
downloaddiscord.py-bd39c3ef458e7b78e1e4d49367544a04ab764131.tar.xz
discord.py-bd39c3ef458e7b78e1e4d49367544a04ab764131.zip
Add utility properties to CallMessage to query information.
-rw-r--r--discord/calls.py46
-rw-r--r--discord/message.py2
-rw-r--r--discord/state.py2
3 files changed, 39 insertions, 11 deletions
diff --git a/discord/calls.py b/discord/calls.py
index a502dfbe..b8f3ab5b 100644
--- a/discord/calls.py
+++ b/discord/calls.py
@@ -25,6 +25,7 @@ DEALINGS IN THE SOFTWARE.
"""
from . import utils
+import datetime
from .enums import ServerRegion, try_enum
from .member import VoiceState
@@ -40,15 +41,42 @@ class CallMessage:
A naive UTC datetime object that represents the time that the call has ended.
participants: List[:class:`User`]
The list of users that are participating in this call.
- channel: :class:`PrivateChannel`
- The private channel associated with this call.
+ message: :class:`Message`
+ The message associated with this call message.
"""
- def __init__(self, channel, **kwargs):
- self.channel = channel
+ def __init__(self, message, **kwargs):
+ self.message = message
self.ended_timestamp = utils.parse_time(kwargs.get('ended_timestamp'))
self.participants = kwargs.get('participants')
+ @property
+ def call_ended(self):
+ """bool: Indicates if the call has ended."""
+ return self.ended_timestamp is not None
+
+ @property
+ def channel(self):
+ """:class:`PrivateChannel`\: The private channel associated with this message."""
+ return self.message.channel
+
+ @property
+ def duration(self):
+ """Queries the duration of the call.
+
+ If the call has not ended then the current duration will
+ be returned.
+
+ Returns
+ ---------
+ datetime.timedelta
+ The timedelta object representing the duration.
+ """
+ if self.ended_timestamp is None:
+ return datetime.datetime.utcnow() - self.message.timestamp
+ else:
+ return self.ended_timestamp - self.message.timestamp
+
class GroupCall:
"""Represents the actual group call from Discord.
@@ -56,8 +84,8 @@ class GroupCall:
Attributes
-----------
- message: :class:`CallMessage`
- The message associated with this group call.
+ call: :class:`CallMessage`
+ The call message associated with this group call.
unavailable: bool
Denotes if this group call is unavailable.
ringing: List[:class:`User`]
@@ -67,7 +95,7 @@ class GroupCall:
"""
def __init__(self, **kwargs):
- self.message = kwargs.get('message')
+ self.call = kwargs.get('call')
self.unavailable = kwargs.get('unavailable')
self._voice_states = {}
@@ -78,7 +106,7 @@ class GroupCall:
def _update(self, **kwargs):
self.region = try_enum(ServerRegion, kwargs.get('region'))
- lookup = {u.id: u for u in self.message.channel.recipients}
+ lookup = {u.id: u for u in self.call.channel.recipients}
self.ringing = list(filter(None, map(lambda i: lookup.get(i), kwargs.get('ringing', []))))
def _update_voice_state(self, data):
@@ -102,7 +130,7 @@ class GroupCall:
@property
def channel(self):
""":class:`PrivateChannel`\: Returns the channel the group call is in."""
- return self.message.channel
+ return self.call.channel
def voice_state_for(self, user):
"""Retrieves the :class:`VoiceState` for a specified :class:`User`.
diff --git a/discord/message.py b/discord/message.py
index d0399982..30929a2c 100644
--- a/discord/message.py
+++ b/discord/message.py
@@ -185,7 +185,7 @@ class Message:
participants.append(user)
call['participants'] = participants
- self.call = CallMessage(channel=self.channel, **call)
+ self.call = CallMessage(message=self, **call)
@utils.cached_slot_property('_raw_mentions')
def raw_mentions(self):
diff --git a/discord/state.py b/discord/state.py
index adac7f5f..f23ae78c 100644
--- a/discord/state.py
+++ b/discord/state.py
@@ -601,7 +601,7 @@ class ConnectionState:
def parse_call_create(self, data):
message = self._get_message(data.get('message_id'))
if message is not None:
- call = GroupCall(message=message, **data)
+ call = GroupCall(call=message, **data)
self._calls[data['channel_id']] = call
self.dispatch('call', call)