From 520e1b91ab653a0f2eb8c4dda854795d95abd207 Mon Sep 17 00:00:00 2001 From: ajax146 <31014239+ajax146@users.noreply.github.com> Date: Wed, 15 Oct 2025 13:00:22 -0400 Subject: [PATCH 1/2] Make duck random channel in category --- techsupport_bot/commands/duck.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/techsupport_bot/commands/duck.py b/techsupport_bot/commands/duck.py index 8820e2ea..516f92f5 100644 --- a/techsupport_bot/commands/duck.py +++ b/techsupport_bot/commands/duck.py @@ -36,6 +36,13 @@ async def setup(bot: bot.TechSupportBot) -> None: description="The IDs of the channels the duck should appear in", default=[], ) + config.add( + key="use_category", + datatype="bool", + title="Whether to use the whole category for ducks", + description="Whether to use the whole category for ducks", + default=False, + ) config.add( key="min_wait", datatype="int", @@ -144,7 +151,7 @@ async def execute( self: Self, config: munch.Munch, guild: discord.Guild, - channel: discord.abc.Messageable, + channel: discord.TextChannel, banned_user: discord.User = None, ) -> None: """Sends a duck in the given channel @@ -153,12 +160,11 @@ async def execute( Args: config (munch.Munch): The config of the guild where the duck is going guild (discord.Guild): The guild where the duck is going - channel (discord.abc.Messageable): The channel to spawn the duck in + channel (discord.TextChannel): The channel to spawn the duck in banned_user (discord.User, optional): A user that is not allowed to claim the duck. Defaults to None. """ if not channel: - config = self.bot.guild_configs[str(guild.id)] log_channel = config.get("logging_channel") await self.bot.logger.send_log( message="Channel not found for Duckhunt loop - continuing", @@ -168,6 +174,10 @@ async def execute( ) return + if config.extensions.duck.use_category.value: + all_valid_channels = channel.category.text_channels + use_channel = random.choice(all_valid_channels) + self.cooldowns[guild.id] = {} embed = discord.Embed( @@ -177,7 +187,7 @@ async def execute( embed.set_image(url=self.DUCK_PIC_URL) embed.color = discord.Color.green() - duck_message = await channel.send(embed=embed) + duck_message = await use_channel.send(embed=embed) start_time = duck_message.created_at response_message = None @@ -187,7 +197,7 @@ async def execute( timeout=config.extensions.duck.timeout.value, # can't pull the config in a non-coroutine check=functools.partial( - self.message_check, config, channel, duck_message, banned_user + self.message_check, config, use_channel, duck_message, banned_user ), ) except asyncio.TimeoutError: @@ -198,7 +208,7 @@ async def execute( await self.bot.logger.send_log( message="Exception thrown waiting for duckhunt input", level=LogLevel.ERROR, - context=LogContext(guild=guild, channel=channel), + context=LogContext(guild=guild, channel=use_channel), channel=log_channel, exception=exception, ) @@ -211,10 +221,10 @@ async def execute( "befriended" if response_message.content.lower() == "bef" else "killed" ) await self.handle_winner( - response_message.author, guild, action, raw_duration, channel + response_message.author, guild, action, raw_duration, use_channel ) else: - await self.got_away(channel) + await self.got_away(use_channel) async def got_away(self: Self, channel: discord.TextChannel) -> None: """Sends a message telling everyone the duck got away From a950efe2824cd1f791a9d7231812141420876696 Mon Sep 17 00:00:00 2001 From: ajax146 <31014239+ajax146@users.noreply.github.com> Date: Wed, 15 Oct 2025 13:04:07 -0400 Subject: [PATCH 2/2] Fix small bug when not using category mode --- techsupport_bot/commands/duck.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/techsupport_bot/commands/duck.py b/techsupport_bot/commands/duck.py index 516f92f5..92fe6698 100644 --- a/techsupport_bot/commands/duck.py +++ b/techsupport_bot/commands/duck.py @@ -177,6 +177,8 @@ async def execute( if config.extensions.duck.use_category.value: all_valid_channels = channel.category.text_channels use_channel = random.choice(all_valid_channels) + else: + use_channel = channel self.cooldowns[guild.id] = {}