Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions techsupport_bot/commands/duck.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand All @@ -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",
Expand All @@ -168,6 +174,12 @@ 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)
else:
use_channel = channel

self.cooldowns[guild.id] = {}

embed = discord.Embed(
Expand All @@ -177,7 +189,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
Expand All @@ -187,7 +199,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:
Expand All @@ -198,7 +210,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,
)
Expand All @@ -211,10 +223,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
Expand Down
Loading