Browse Source
Discord is inconsistent here and doesn't emit a VoiceStateUpdate for the old session_id when a user connects to voice from a different device (thus disconnecting the first device). To avoid corrupting our voice state cache, we need to remove any of the users old sessions (they should have at most one). I included tests on this one because its esoteric and undocumented, so there is a high chance I'll break it in the future.pull/116/head
2 changed files with 45 additions and 0 deletions
@ -0,0 +1,39 @@ |
|||||
|
from disco.state import State, StateConfig |
||||
|
from holster.emitter import Emitter |
||||
|
from disco.gateway.events import VoiceStateUpdate |
||||
|
|
||||
|
|
||||
|
class MockClient(object): |
||||
|
def __init__(self): |
||||
|
self.events = Emitter() |
||||
|
|
||||
|
|
||||
|
def get_state(config=None): |
||||
|
return State(MockClient(), config or StateConfig()) |
||||
|
|
||||
|
|
||||
|
def test_state_remove_expired_voice_states_device_change(): |
||||
|
state = get_state() |
||||
|
|
||||
|
event = VoiceStateUpdate.create({ |
||||
|
'session_id': 'a', |
||||
|
'guild_id': 1, |
||||
|
'channel_id': 1, |
||||
|
'user_id': 1, |
||||
|
}, None) |
||||
|
state.client.events.emit('VoiceStateUpdate', event) |
||||
|
|
||||
|
assert len(state.voice_states) == 1 |
||||
|
assert 'a' in state.voice_states |
||||
|
|
||||
|
event = VoiceStateUpdate.create({ |
||||
|
'session_id': 'b', |
||||
|
'guild_id': 1, |
||||
|
'channel_id': 1, |
||||
|
'user_id': 1, |
||||
|
}, None) |
||||
|
state.client.events.emit('VoiceStateUpdate', event) |
||||
|
|
||||
|
assert len(state.voice_states) == 1 |
||||
|
assert 'a' not in state.voice_states |
||||
|
assert 'b' in state.voice_states |
Loading…
Reference in new issue