client: guard join_channel and send_text against stale ids
join_channel raises ValueError on missing channel instead of KeyError. send_text handles missing channel_id gracefully.
This commit is contained in:
@@ -229,7 +229,12 @@ class MumbleClient:
|
|||||||
def send_text(self, message: str):
|
def send_text(self, message: str):
|
||||||
"""Send a text message to the current channel."""
|
"""Send a text message to the current channel."""
|
||||||
if self._mumble and self._connected:
|
if self._mumble and self._connected:
|
||||||
ch = self._mumble.channels[self._mumble.users.myself["channel_id"]]
|
try:
|
||||||
|
cid = self._mumble.users.myself["channel_id"]
|
||||||
|
ch = self._mumble.channels[cid]
|
||||||
|
except (KeyError, AttributeError):
|
||||||
|
log.warning("send_text: channel unavailable")
|
||||||
|
return
|
||||||
ch.send_text_message(message)
|
ch.send_text_message(message)
|
||||||
|
|
||||||
def send_audio(self, pcm_data: bytes):
|
def send_audio(self, pcm_data: bytes):
|
||||||
@@ -238,9 +243,16 @@ class MumbleClient:
|
|||||||
self._mumble.sound_output.add_sound(pcm_data)
|
self._mumble.sound_output.add_sound(pcm_data)
|
||||||
|
|
||||||
def join_channel(self, channel_id: int):
|
def join_channel(self, channel_id: int):
|
||||||
"""Move to a different channel."""
|
"""Move to a different channel.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
ValueError: If the channel no longer exists on the server.
|
||||||
|
"""
|
||||||
if self._mumble and self._connected:
|
if self._mumble and self._connected:
|
||||||
self._mumble.channels[channel_id].move_in()
|
ch = self._mumble.channels.get(channel_id)
|
||||||
|
if ch is None:
|
||||||
|
raise ValueError(f"channel {channel_id} not found")
|
||||||
|
ch.move_in()
|
||||||
|
|
||||||
def set_self_deaf(self, deaf: bool):
|
def set_self_deaf(self, deaf: bool):
|
||||||
"""Toggle self-deafen on the server."""
|
"""Toggle self-deafen on the server."""
|
||||||
|
|||||||
Reference in New Issue
Block a user