Browse Source

Fix voice state update issue in on_voice_state_update

Bug was caused to the shallow copy not copying over the VoiceState
information embedded into the copy. This would mean that when the event
is called, before and after voice state information is essentially
equivalent.

The solution to fix this is to also copy the VoiceState objects.
pull/276/head
Rapptz 9 years ago
parent
commit
b0e5357716
  1. 11
      discord/member.py
  2. 4
      discord/server.py
  3. 4
      discord/state.py

11
discord/member.py

@ -29,6 +29,7 @@ from .game import Game
from . import utils
from .enums import Status, ChannelType
from .colour import Colour
import copy
class VoiceState:
"""Represents a Discord user's voice state.
@ -63,10 +64,7 @@ class VoiceState:
self.is_afk = kwargs.get('suppress', False)
self.mute = kwargs.get('mute', False)
self.deaf = kwargs.get('deaf', False)
self._handle_voice_channel(kwargs.get('voice_channel'), kwargs.get('user_id'))
def _handle_voice_channel(self, voice_channel, user_id):
self.voice_channel = voice_channel
self.voice_channel = kwargs.get('voice_channel')
def flatten_voice_states(cls):
for attr in VoiceState.__slots__:
@ -142,6 +140,11 @@ class Member(User):
self.voice.voice_channel = vc
def _copy(self):
ret = copy.copy(self)
ret.voice = copy.copy(self.voice)
return ret
@property
def colour(self):
"""A property that returns a :class:`Colour` denoting the rendered colour

4
discord/server.py

@ -31,7 +31,6 @@ from .game import Game
from .channel import Channel
from .enums import ServerRegion, Status
from .mixins import Hashable
import copy
class Server(Hashable):
"""Represents a Discord server.
@ -137,8 +136,9 @@ class Server(Hashable):
def _update_voice_state(self, data):
user_id = data.get('user_id')
member = self.get_member(user_id)
before = copy.copy(member)
before = None
if member is not None:
before = member._copy()
ch_id = data.get('channel_id')
channel = self.get_channel(ch_id)
member._update_voice_state(voice_channel=channel, **data)

4
discord/state.py

@ -268,7 +268,7 @@ class ConnectionState:
member = self._make_member(server, data)
server._add_member(member)
old_member = copy.copy(member)
old_member = member._copy()
member.status = data.get('status')
try:
member.status = Status(member.status)
@ -385,7 +385,7 @@ class ConnectionState:
member = server.get_member(user_id)
if member is not None:
user = data['user']
old_member = copy.copy(member)
old_member = member._copy()
member.name = user['username']
member.discriminator = user['discriminator']
member.avatar = user['avatar']

Loading…
Cancel
Save