diff --git a/litecord/storage.py b/litecord/storage.py index 3911312..0d56c28 100644 --- a/litecord/storage.py +++ b/litecord/storage.py @@ -543,9 +543,9 @@ class Storage: res = [] for channel_id in channel_ids: - states = await self.app.voice.fetch_states(channel_id, user_id) + states = await self.app.voice.fetch_states(channel_id) - jsonified = [s.as_json_for(user_id) for s in states] + jsonified = [s.as_json_for(user_id) for s in states.values()] # discord does NOT insert guild_id to voice states on the # guild voice state list. diff --git a/litecord/voice/manager.py b/litecord/voice/manager.py index 3b0c77c..569f607 100644 --- a/litecord/voice/manager.py +++ b/litecord/voice/manager.py @@ -17,7 +17,7 @@ along with this program. If not, see . """ -from typing import Tuple +from typing import Tuple, Dict from collections import defaultdict from dataclasses import fields @@ -52,6 +52,15 @@ class VoiceManager: """Get the current amount of voice states in a channel.""" return len(self.states[channel_id]) + async def fetch_states(self, channel_id: int) -> Dict[int, VoiceState]: + """Fetch the states of the given channel.""" + # NOTE: maybe we *could* optimize by just returning a reference to the + # states dict instead of calling dict()... + + # however I'm really worried about state inconsistencies caused + # by this, so i'll just use dict(). + return dict(self.states[channel_id]) + async def del_state(self, voice_key: VoiceKey): """Delete a given voice state.""" chan_id, user_id = voice_key