aboutsummaryrefslogtreecommitdiff
path: root/discord/calls.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2016-07-15 22:46:00 -0400
committerRapptz <[email protected]>2016-07-15 22:46:00 -0400
commit1c8ab25917df5984d59869e305194ee56b300647 (patch)
tree7b9c5c5280f762a8cd66b04b1da036c0f2f503b1 /discord/calls.py
parentFix the displaying of Message.system_content (diff)
downloaddiscord.py-1c8ab25917df5984d59869e305194ee56b300647.tar.xz
discord.py-1c8ab25917df5984d59869e305194ee56b300647.zip
Add support for querying information about group calls.
Diffstat (limited to 'discord/calls.py')
-rw-r--r--discord/calls.py79
1 files changed, 78 insertions, 1 deletions
diff --git a/discord/calls.py b/discord/calls.py
index ce9e6803..a502dfbe 100644
--- a/discord/calls.py
+++ b/discord/calls.py
@@ -25,9 +25,11 @@ DEALINGS IN THE SOFTWARE.
"""
from . import utils
+from .enums import ServerRegion, try_enum
+from .member import VoiceState
class CallMessage:
- """Represents a group call from Discord.
+ """Represents a group call message from Discord.
This is only received in cases where the message type is equivalent to
:attr:`MessageType.call`.
@@ -46,3 +48,78 @@ class CallMessage:
self.channel = channel
self.ended_timestamp = utils.parse_time(kwargs.get('ended_timestamp'))
self.participants = kwargs.get('participants')
+
+class GroupCall:
+ """Represents the actual group call from Discord.
+
+ This is accompanied with a :class:`CallMessage` denoting the information.
+
+ Attributes
+ -----------
+ message: :class:`CallMessage`
+ The message associated with this group call.
+ unavailable: bool
+ Denotes if this group call is unavailable.
+ ringing: List[:class:`User`]
+ A list of users that are currently being rung to join the call.
+ region: :class:`ServerRegion`
+ The server region the group call is being hosted on.
+ """
+
+ def __init__(self, **kwargs):
+ self.message = kwargs.get('message')
+ self.unavailable = kwargs.get('unavailable')
+ self._voice_states = {}
+
+ for state in kwargs.get('voice_states', []):
+ self._update_voice_state(state)
+
+ self._update(**kwargs)
+
+ def _update(self, **kwargs):
+ self.region = try_enum(ServerRegion, kwargs.get('region'))
+ lookup = {u.id: u for u in self.message.channel.recipients}
+ self.ringing = list(filter(None, map(lambda i: lookup.get(i), kwargs.get('ringing', []))))
+
+ def _update_voice_state(self, data):
+ user_id = data['user_id']
+ # left the voice channel?
+ if data['channel_id'] is None:
+ self._voice_states.pop(user_id, None)
+ else:
+ self._voice_states[user_id] = VoiceState(**data, voice_channel=self.channel)
+
+ @property
+ def connected(self):
+ """A property that returns the list of :class:`User` that are currently in this call."""
+ ret = [u for u in self.channel.recipients if self.voice_state_for(u) is not None]
+ me = self.channel.me
+ if self.voice_state_for(me) is not None:
+ ret.append(me)
+
+ return ret
+
+ @property
+ def channel(self):
+ """:class:`PrivateChannel`\: Returns the channel the group call is in."""
+ return self.message.channel
+
+ def voice_state_for(self, user):
+ """Retrieves the :class:`VoiceState` for a specified :class:`User`.
+
+ If the :class:`User` has no voice state then this function returns
+ ``None``.
+
+ Parameters
+ ------------
+ user: :class:`User`
+ The user to retrieve the voice state for.
+
+ Returns
+ --------
+ Optiona[:class:`VoiceState`]
+ The voice state associated with this user.
+ """
+
+ return self._voice_states.get(user.id)
+