From 22402fd4cb02601e4fec9dc42a937cb7f86d6069 Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 1 Mar 2019 18:29:41 -0300 Subject: [PATCH] voice.manager: add fetch_states() impl - storage: follow the impl --- litecord/storage.py | 4 ++-- litecord/voice/manager.py | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) 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