Add utility properties to CallMessage to query information.
This commit is contained in:
parent
1c8ab25917
commit
bd39c3ef45
@ -25,6 +25,7 @@ DEALINGS IN THE SOFTWARE.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from . import utils
|
from . import utils
|
||||||
|
import datetime
|
||||||
from .enums import ServerRegion, try_enum
|
from .enums import ServerRegion, try_enum
|
||||||
from .member import VoiceState
|
from .member import VoiceState
|
||||||
|
|
||||||
@ -40,15 +41,42 @@ class CallMessage:
|
|||||||
A naive UTC datetime object that represents the time that the call has ended.
|
A naive UTC datetime object that represents the time that the call has ended.
|
||||||
participants: List[:class:`User`]
|
participants: List[:class:`User`]
|
||||||
The list of users that are participating in this call.
|
The list of users that are participating in this call.
|
||||||
channel: :class:`PrivateChannel`
|
message: :class:`Message`
|
||||||
The private channel associated with this call.
|
The message associated with this call message.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, channel, **kwargs):
|
def __init__(self, message, **kwargs):
|
||||||
self.channel = channel
|
self.message = message
|
||||||
self.ended_timestamp = utils.parse_time(kwargs.get('ended_timestamp'))
|
self.ended_timestamp = utils.parse_time(kwargs.get('ended_timestamp'))
|
||||||
self.participants = kwargs.get('participants')
|
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:
|
class GroupCall:
|
||||||
"""Represents the actual group call from Discord.
|
"""Represents the actual group call from Discord.
|
||||||
|
|
||||||
@ -56,8 +84,8 @@ class GroupCall:
|
|||||||
|
|
||||||
Attributes
|
Attributes
|
||||||
-----------
|
-----------
|
||||||
message: :class:`CallMessage`
|
call: :class:`CallMessage`
|
||||||
The message associated with this group call.
|
The call message associated with this group call.
|
||||||
unavailable: bool
|
unavailable: bool
|
||||||
Denotes if this group call is unavailable.
|
Denotes if this group call is unavailable.
|
||||||
ringing: List[:class:`User`]
|
ringing: List[:class:`User`]
|
||||||
@ -67,7 +95,7 @@ class GroupCall:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
self.message = kwargs.get('message')
|
self.call = kwargs.get('call')
|
||||||
self.unavailable = kwargs.get('unavailable')
|
self.unavailable = kwargs.get('unavailable')
|
||||||
self._voice_states = {}
|
self._voice_states = {}
|
||||||
|
|
||||||
@ -78,7 +106,7 @@ class GroupCall:
|
|||||||
|
|
||||||
def _update(self, **kwargs):
|
def _update(self, **kwargs):
|
||||||
self.region = try_enum(ServerRegion, kwargs.get('region'))
|
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', []))))
|
self.ringing = list(filter(None, map(lambda i: lookup.get(i), kwargs.get('ringing', []))))
|
||||||
|
|
||||||
def _update_voice_state(self, data):
|
def _update_voice_state(self, data):
|
||||||
@ -102,7 +130,7 @@ class GroupCall:
|
|||||||
@property
|
@property
|
||||||
def channel(self):
|
def channel(self):
|
||||||
""":class:`PrivateChannel`\: Returns the channel the group call is in."""
|
""":class:`PrivateChannel`\: Returns the channel the group call is in."""
|
||||||
return self.message.channel
|
return self.call.channel
|
||||||
|
|
||||||
def voice_state_for(self, user):
|
def voice_state_for(self, user):
|
||||||
"""Retrieves the :class:`VoiceState` for a specified :class:`User`.
|
"""Retrieves the :class:`VoiceState` for a specified :class:`User`.
|
||||||
|
@ -185,7 +185,7 @@ class Message:
|
|||||||
participants.append(user)
|
participants.append(user)
|
||||||
|
|
||||||
call['participants'] = participants
|
call['participants'] = participants
|
||||||
self.call = CallMessage(channel=self.channel, **call)
|
self.call = CallMessage(message=self, **call)
|
||||||
|
|
||||||
@utils.cached_slot_property('_raw_mentions')
|
@utils.cached_slot_property('_raw_mentions')
|
||||||
def raw_mentions(self):
|
def raw_mentions(self):
|
||||||
|
@ -601,7 +601,7 @@ class ConnectionState:
|
|||||||
def parse_call_create(self, data):
|
def parse_call_create(self, data):
|
||||||
message = self._get_message(data.get('message_id'))
|
message = self._get_message(data.get('message_id'))
|
||||||
if message is not None:
|
if message is not None:
|
||||||
call = GroupCall(message=message, **data)
|
call = GroupCall(call=message, **data)
|
||||||
self._calls[data['channel_id']] = call
|
self._calls[data['channel_id']] = call
|
||||||
self.dispatch('call', call)
|
self.dispatch('call', call)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user