diff --git a/nightly/nightly/night.py b/nightly/nightly/night.py index c950864..c33ffc3 100644 --- a/nightly/nightly/night.py +++ b/nightly/nightly/night.py @@ -26,6 +26,12 @@ FORMATTED_CODE_REGEX = re.compile( # https://github.com/python-discord/bot-core/blob/main/pydis_core/utils/regex.py#L44C1-L49C2 RAW_CODE_REGEX = re.compile(r"^(?:[ \t]*\n)*" r"(?P.*?)" r"\s*$", flags=re.DOTALL) +async def threads(channel: discord.TextChannel): + for t in channel.threads: + yield t + async for t in channel.archived_threads(): + yield t + # https://github.com/python-discord/bot/blob/main/bot/exts/utils/snekbox/_cog.py#L97 class CodeblockConverter(commands.Converter): @@ -106,6 +112,10 @@ class Night(commands.Cog): if not isinstance(ctx.channel, discord.TextChannel): await ctx.reply("not available outside text channels") return + async for thread in threads(ctx.channel): + if thread.name == title: + await ctx.reply(f"exists: {thread.jump_url}") + return thread = await ctx.channel.create_thread(name=title, type=discord.ChannelType.public_thread) message = await thread.send(f"https://leetcode.com/problems/{name}/") if not ctx.bot_permissions.manage_messages: