fix(voice): Patch channel list and fix cache.
Accounts for stage channels in initialisation. Clears _sessions_ cache when refreshing guild. Restrict `untracked_channels` selector to exclude text.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import itertools
|
||||||
import datetime as dt
|
import datetime as dt
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
@@ -71,7 +72,7 @@ class VoiceTrackerCog(LionCog):
|
|||||||
locked=0,
|
locked=0,
|
||||||
actual=0,
|
actual=0,
|
||||||
channels=0,
|
channels=0,
|
||||||
cached=len(VoiceSession._sessions_),
|
cached=sum(len(gsessions) for gsessions in VoiceSession._sessions_.values()),
|
||||||
initial_event=self.initialised,
|
initial_event=self.initialised,
|
||||||
lock=self.tracking_lock
|
lock=self.tracking_lock
|
||||||
)
|
)
|
||||||
@@ -92,7 +93,7 @@ class VoiceTrackerCog(LionCog):
|
|||||||
data['channels'] = len(channels)
|
data['channels'] = len(channels)
|
||||||
|
|
||||||
for guild in self.bot.guilds:
|
for guild in self.bot.guilds:
|
||||||
for channel in guild.voice_channels:
|
for channel in itertools.chain(guild.voice_channels, guild.stage_channels):
|
||||||
if not self.is_untracked(channel):
|
if not self.is_untracked(channel):
|
||||||
for member in channel.members:
|
for member in channel.members:
|
||||||
if member.voice and not member.bot:
|
if member.voice and not member.bot:
|
||||||
@@ -143,7 +144,7 @@ class VoiceTrackerCog(LionCog):
|
|||||||
...
|
...
|
||||||
|
|
||||||
# ----- Cog API -----
|
# ----- Cog API -----
|
||||||
def get_session(self, guildid, userid, **kwargs) -> Optional[VoiceSession]:
|
def get_session(self, guildid, userid, **kwargs):
|
||||||
"""
|
"""
|
||||||
Get the VoiceSession for the given member.
|
Get the VoiceSession for the given member.
|
||||||
|
|
||||||
@@ -325,6 +326,8 @@ class VoiceTrackerCog(LionCog):
|
|||||||
active = self.active_sessions.pop(guild.id, {}).values()
|
active = self.active_sessions.pop(guild.id, {}).values()
|
||||||
for session in active:
|
for session in active:
|
||||||
session.cancel()
|
session.cancel()
|
||||||
|
# Clear registry
|
||||||
|
VoiceSession._sessions_.pop(guild.id, None)
|
||||||
|
|
||||||
# Update untracked channel information for this guild
|
# Update untracked channel information for this guild
|
||||||
self.untracked_channels.pop(guild.id, None)
|
self.untracked_channels.pop(guild.id, None)
|
||||||
@@ -332,7 +335,7 @@ class VoiceTrackerCog(LionCog):
|
|||||||
|
|
||||||
# Read tracked voice states
|
# Read tracked voice states
|
||||||
states = {}
|
states = {}
|
||||||
for channel in guild.voice_channels:
|
for channel in itertools.chain(guild.voice_channels, guild.stage_channels):
|
||||||
if not self.is_untracked(channel):
|
if not self.is_untracked(channel):
|
||||||
for member in channel.members:
|
for member in channel.members:
|
||||||
if member.voice and not member.bot:
|
if member.voice and not member.bot:
|
||||||
@@ -390,7 +393,7 @@ class VoiceTrackerCog(LionCog):
|
|||||||
# Read and save the tracked voice states of all visible voice channels
|
# Read and save the tracked voice states of all visible voice channels
|
||||||
states = {}
|
states = {}
|
||||||
for guild in self.bot.guilds:
|
for guild in self.bot.guilds:
|
||||||
for channel in guild.voice_channels:
|
for channel in itertools.chain(guild.voice_channels, guild.stage_channels):
|
||||||
if not self.is_untracked(channel):
|
if not self.is_untracked(channel):
|
||||||
for member in channel.members:
|
for member in channel.members:
|
||||||
if member.voice and not member.bot:
|
if member.voice and not member.bot:
|
||||||
|
|||||||
@@ -253,6 +253,8 @@ class VoiceSession:
|
|||||||
f"Expiring voice session for member <uid:{self.userid}> in guild <gid:{self.guildid}> "
|
f"Expiring voice session for member <uid:{self.userid}> in guild <gid:{self.guildid}> "
|
||||||
f"and channel <cid:{self.state.channelid}>."
|
f"and channel <cid:{self.state.channelid}>."
|
||||||
)
|
)
|
||||||
|
# TODO: Would be better not to close the session and wipe the state
|
||||||
|
# Instead start a new PENDING session.
|
||||||
await self.close()
|
await self.close()
|
||||||
|
|
||||||
async def update(self, new_state: Optional[TrackedVoiceState] = None, new_rate: Optional[int] = None):
|
async def update(self, new_state: Optional[TrackedVoiceState] = None, new_rate: Optional[int] = None):
|
||||||
|
|||||||
@@ -457,6 +457,9 @@ class VoiceTrackerConfigUI(ConfigUI):
|
|||||||
@select(
|
@select(
|
||||||
cls=ChannelSelect,
|
cls=ChannelSelect,
|
||||||
placeholder="UNTRACKED_CHANNELS_PLACEHOLDER",
|
placeholder="UNTRACKED_CHANNELS_PLACEHOLDER",
|
||||||
|
channel_types=[
|
||||||
|
discord.enums.ChannelType.voice, discord.enums.ChannelType.stage_voice, discord.enums.ChannelType.category
|
||||||
|
],
|
||||||
min_values=0, max_values=25
|
min_values=0, max_values=25
|
||||||
)
|
)
|
||||||
async def untracked_channels_menu(self, selection: discord.Interaction, selected):
|
async def untracked_channels_menu(self, selection: discord.Interaction, selected):
|
||||||
|
|||||||
Reference in New Issue
Block a user