From f4a16f88a95f0095cb4c5d72be9b658eb40f499d Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" <git@edgarpierre.fr> Date: Mon, 24 Mar 2025 10:50:05 +0100 Subject: [PATCH] Refactor random voice channel connection logic to use dynamic weights based on member count --- botbotbot/voice.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/botbotbot/voice.py b/botbotbot/voice.py index 6cad996..e234108 100644 --- a/botbotbot/voice.py +++ b/botbotbot/voice.py @@ -58,13 +58,12 @@ class VoiceBot: activity = discord.CustomActivity(status) await self.bot.change_presence(activity=activity) - if random.random() < 50 / 100: + weights = [10 * len(vc.members) + 1 for vc in guild.voice_channels] + if random.random() < sum(weights) / 100: logger.info("Random connect.") voice_chan = random.choices( guild.voice_channels, - weights=[ - 10 * len(vc.members) + 1 for vc in guild.voice_channels - ], + weights=weights, )[0] await self.connect_voice(voice_chan) if not voice_chan.status and self.aibot is not None: