voice.manager: add fetch_states() impl

- storage: follow the impl
This commit is contained in:
Luna 2019-03-01 18:29:41 -03:00
parent 75a52a5ac8
commit 22402fd4cb
2 changed files with 12 additions and 3 deletions

View File

@ -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.

View File

@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
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