mirror of https://gitlab.com/litecord/litecord.git
voice.manager: add fetch_states() impl
- storage: follow the impl
This commit is contained in:
parent
75a52a5ac8
commit
22402fd4cb
|
|
@ -543,9 +543,9 @@ class Storage:
|
||||||
res = []
|
res = []
|
||||||
|
|
||||||
for channel_id in channel_ids:
|
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
|
# discord does NOT insert guild_id to voice states on the
|
||||||
# guild voice state list.
|
# guild voice state list.
|
||||||
|
|
|
||||||
|
|
@ -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 collections import defaultdict
|
||||||
from dataclasses import fields
|
from dataclasses import fields
|
||||||
|
|
||||||
|
|
@ -52,6 +52,15 @@ class VoiceManager:
|
||||||
"""Get the current amount of voice states in a channel."""
|
"""Get the current amount of voice states in a channel."""
|
||||||
return len(self.states[channel_id])
|
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):
|
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