Refactor random voice channel connection logic to use dynamic weights based on member count
This commit is contained in:
parent
3f6e41b0c0
commit
f4a16f88a9
1 changed files with 3 additions and 4 deletions
|
@ -58,13 +58,12 @@ class VoiceBot:
|
||||||
activity = discord.CustomActivity(status)
|
activity = discord.CustomActivity(status)
|
||||||
await self.bot.change_presence(activity=activity)
|
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.")
|
logger.info("Random connect.")
|
||||||
voice_chan = random.choices(
|
voice_chan = random.choices(
|
||||||
guild.voice_channels,
|
guild.voice_channels,
|
||||||
weights=[
|
weights=weights,
|
||||||
10 * len(vc.members) + 1 for vc in guild.voice_channels
|
|
||||||
],
|
|
||||||
)[0]
|
)[0]
|
||||||
await self.connect_voice(voice_chan)
|
await self.connect_voice(voice_chan)
|
||||||
if not voice_chan.status and self.aibot is not None:
|
if not voice_chan.status and self.aibot is not None:
|
||||||
|
|
Loading…
Add table
Reference in a new issue