Skip to content

Commit 8fa6d45

Browse files
committed
💭auto threads improvements
1 parent 879eb43 commit 8fa6d45

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

cogs/mod/auto_threads.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from discord.ext import commands
33
from discord import app_commands
44
from settings import MEDIA_CHANNEL_ID, FB_IDEAS_CHANNEL_ID
5+
from re import sub
56

67
class AutoThreads(commands.Cog):
78
def __init__(self, bot):
@@ -24,7 +25,13 @@ async def auto_threads(self, msg):
2425
await msg.channel.send(f"{msg.author.mention} Обсуждайте в ветках!", delete_after=3)
2526

2627
async def create_auto_thread(msg):
27-
thread_name = msg.content[:97] if msg.content != "" else f"Обсуждение медиа {msg.author.display_name}"
28-
if len(msg.content) >= 100:
28+
content = sub(r"https?:\/\/\S+", "", msg.content)
29+
thread_name = content[:97]
30+
if len(thread_name) == 97:
2931
thread_name += "..."
30-
await msg.create_thread(name=thread_name)
32+
try:
33+
await msg.create_thread(name=thread_name)
34+
except discord.errors.HTTPException:
35+
channel_name = sub(r"[^\w-]*", "", msg.channel.name)
36+
await msg.create_thread(name=f"Обсуждение {channel_name} {msg.author.display_name}")
37+

0 commit comments

Comments
 (0)