check for existing leetcode thread

This commit is contained in:
AF 2024-05-14 09:32:57 +00:00
parent dfdf1217d2
commit c1a546c9e7
Signed by: alisa
SSH Key Fingerprint: SHA256:vNY4pdIZvO1FYJKHROkdHLtvyopizvZVAEwg9AF6h04

View File

@ -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<code>.*?)" 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: