mirror of https://gitlab.com/litecord/litecord.git
gateway.websocket: handle chan_id=None
- gateway.websocket: change fetch_state to get_state - voice.manager: add get_state()
This commit is contained in:
parent
22402fd4cb
commit
d47d79977b
|
|
@ -691,6 +691,15 @@ class GatewayWebsocket:
|
||||||
|
|
||||||
async def _create_voice(self, guild_id, channel_id, _state, data):
|
async def _create_voice(self, guild_id, channel_id, _state, data):
|
||||||
"""Create a voice state."""
|
"""Create a voice state."""
|
||||||
|
|
||||||
|
# if we are trying to create a voice state pointing torwards
|
||||||
|
# nowhere, we ignore it.
|
||||||
|
|
||||||
|
# NOTE: HOWEVER, shouldn't we update the users' settings for
|
||||||
|
# self_mute and self_deaf?
|
||||||
|
if channel_id is None:
|
||||||
|
return
|
||||||
|
|
||||||
# we ignore the given existing state as it'll be basically
|
# we ignore the given existing state as it'll be basically
|
||||||
# none, lol.
|
# none, lol.
|
||||||
|
|
||||||
|
|
@ -711,10 +720,8 @@ class GatewayWebsocket:
|
||||||
channel_id = int_(data.get('channel_id'))
|
channel_id = int_(data.get('channel_id'))
|
||||||
guild_id = int_(data.get('guild_id'))
|
guild_id = int_(data.get('guild_id'))
|
||||||
|
|
||||||
|
|
||||||
# fetch an existing voice state
|
# fetch an existing voice state
|
||||||
user_id, session_id = self.state.user_id, self.state.session_id
|
voice_state = await self.ext.voice.get_state(self.voice_key)
|
||||||
voice_state = await self.ext.voice.fetch_state(user_id, session_id)
|
|
||||||
|
|
||||||
func = self._move_voice if voice_state else self._create_voice
|
func = self._move_voice if voice_state else self._create_voice
|
||||||
await func(guild_id, channel_id, voice_state, data)
|
await func(guild_id, channel_id, voice_state, data)
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,16 @@ class VoiceManager:
|
||||||
# by this, so i'll just use dict().
|
# by this, so i'll just use dict().
|
||||||
return dict(self.states[channel_id])
|
return dict(self.states[channel_id])
|
||||||
|
|
||||||
|
async def get_state(self, voice_key: VoiceKey) -> VoiceState:
|
||||||
|
"""Get a single VoiceState for a user in a channel. Returns None
|
||||||
|
if no VoiceState is found."""
|
||||||
|
channel_id, user_id = voice_key
|
||||||
|
|
||||||
|
try:
|
||||||
|
return self.states[channel_id][user_id]
|
||||||
|
except KeyError:
|
||||||
|
return None
|
||||||
|
|
||||||
async def del_state(self, voice_key: VoiceKey):
|
async def del_state(self, voice_key: VoiceKey):
|
||||||
"""Delete a given voice state."""
|
"""Delete a given voice state."""
|
||||||
chan_id, user_id = voice_key
|
chan_id, user_id = voice_key
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue