mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-07 12:18:59 +00:00
VoiceChannel.voice_members is now computed when needed.
This commit is contained in:
parent
4bd8382e06
commit
aae8b783e9
@ -174,20 +174,17 @@ class VoiceChannel(discord.abc.GuildChannel, Hashable):
|
|||||||
top channel is position 0.
|
top channel is position 0.
|
||||||
bitrate: int
|
bitrate: int
|
||||||
The channel's preferred audio bitrate in bits per second.
|
The channel's preferred audio bitrate in bits per second.
|
||||||
voice_members
|
|
||||||
A list of :class:`Members` that are currently inside this voice channel.
|
|
||||||
user_limit: int
|
user_limit: int
|
||||||
The channel's limit for number of members that can be in a voice channel.
|
The channel's limit for number of members that can be in a voice channel.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = ( 'voice_members', 'name', 'id', 'guild', 'bitrate',
|
__slots__ = ('name', 'id', 'guild', 'bitrate', 'user_limit',
|
||||||
'user_limit', '_state', 'position', '_overwrites' )
|
'_state', 'position', '_overwrites' )
|
||||||
|
|
||||||
def __init__(self, *, state, guild, data):
|
def __init__(self, *, state, guild, data):
|
||||||
self._state = state
|
self._state = state
|
||||||
self.id = int(data['id'])
|
self.id = int(data['id'])
|
||||||
self._update(guild, data)
|
self._update(guild, data)
|
||||||
self.voice_members = []
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<VoiceChannel id={0.id} name={0.name!r} position={0.position}>'.format(self)
|
return '<VoiceChannel id={0.id} name={0.name!r} position={0.position}>'.format(self)
|
||||||
@ -200,6 +197,17 @@ class VoiceChannel(discord.abc.GuildChannel, Hashable):
|
|||||||
self.user_limit = data.get('user_limit')
|
self.user_limit = data.get('user_limit')
|
||||||
self._fill_overwrites(data)
|
self._fill_overwrites(data)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def voice_members(self):
|
||||||
|
"""Returns a list of :class:`Member` that are currently inside this voice channel."""
|
||||||
|
ret = []
|
||||||
|
for user_id, state in self.guild._voice_states.items():
|
||||||
|
if state.channel.id == self.id:
|
||||||
|
member = self.guild.get_member(user_id)
|
||||||
|
if member is not None:
|
||||||
|
ret.append(member)
|
||||||
|
return ret
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def edit(self, **options):
|
def edit(self, **options):
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
@ -164,23 +164,6 @@ class Guild(Hashable):
|
|||||||
self._voice_states[user_id] = after
|
self._voice_states[user_id] = after
|
||||||
|
|
||||||
member = self.get_member(user_id)
|
member = self.get_member(user_id)
|
||||||
if member is not None:
|
|
||||||
old = before.channel
|
|
||||||
# update the references pointed to by the voice channels
|
|
||||||
if old is None and channel is not None:
|
|
||||||
# we joined a channel
|
|
||||||
channel.voice_members.append(member)
|
|
||||||
elif old is not None:
|
|
||||||
try:
|
|
||||||
# we either left a channel or switched channels
|
|
||||||
old.voice_members.remove(member)
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
finally:
|
|
||||||
# we switched channels
|
|
||||||
if channel is not None:
|
|
||||||
channel.voice_members.append(member)
|
|
||||||
|
|
||||||
return member, before, after
|
return member, before, after
|
||||||
|
|
||||||
def _add_role(self, role):
|
def _add_role(self, role):
|
||||||
|
@ -50,7 +50,7 @@ class VoiceState:
|
|||||||
Indicates if the user is currently deafened by their own accord.
|
Indicates if the user is currently deafened by their own accord.
|
||||||
is_afk: bool
|
is_afk: bool
|
||||||
Indicates if the user is currently in the AFK channel in the guild.
|
Indicates if the user is currently in the AFK channel in the guild.
|
||||||
channel: Optional[Union[:class:`Channel`, :class:`PrivateChannel`]]
|
channel: :class:`VoiceChannel`
|
||||||
The voice channel that the user is currently connected to. None if the user
|
The voice channel that the user is currently connected to. None if the user
|
||||||
is not currently in a voice channel.
|
is not currently in a voice channel.
|
||||||
"""
|
"""
|
||||||
@ -70,6 +70,9 @@ class VoiceState:
|
|||||||
self.deaf = data.get('deaf', False)
|
self.deaf = data.get('deaf', False)
|
||||||
self.channel = channel
|
self.channel = channel
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return '<VoiceState self_mute={0.self_mute} self_deaf={0.self_deaf} channel={0.channel!r}>'.format(self)
|
||||||
|
|
||||||
def flatten_user(cls):
|
def flatten_user(cls):
|
||||||
for attr, value in User.__dict__.items():
|
for attr, value in User.__dict__.items():
|
||||||
# ignore private/special methods
|
# ignore private/special methods
|
||||||
|
Loading…
x
Reference in New Issue
Block a user