Skip to content

Commit f5ec22a

Browse files
committed
↪ forward support for медиа
1 parent 8402e58 commit f5ec22a

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

cogs/mod/auto_threads.py

+28-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import discord
22
from discord.ext import commands
3-
from discord import app_commands
3+
44
from settings import MEDIA_CHANNEL_ID, FB_IDEAS_CHANNEL_ID
5+
from asyncio import sleep
56
from re import sub
67

8+
79
class AutoThreads(commands.Cog):
810
def __init__(self, bot):
911
self.bot = bot
12+
self.waiting_for_forward_comment = False
1013

1114
@commands.Cog.listener("on_message")
1215
async def auto_threads(self, msg):
@@ -15,17 +18,35 @@ async def auto_threads(self, msg):
1518
if msg.author.bot:
1619
return
1720
if msg.channel.id == FB_IDEAS_CHANNEL_ID and "https://discord.com/channels/1138536747932864532" in msg.content:
18-
print("hi")
1921
await create_auto_thread(msg)
20-
elif msg.channel.id == MEDIA_CHANNEL_ID and (msg.attachments != [] or "https://" in msg.content or "http://" in msg.content):
21-
print(msg.channel.id == MEDIA_CHANNEL_ID)
22-
await create_auto_thread(msg)
22+
if msg.channel.id == MEDIA_CHANNEL_ID:
23+
if (msg.attachments != [] or "https://" in msg.content or "http://" in msg.content):
24+
await create_auto_thread(msg)
25+
elif msg.flags.forwarded:
26+
self.waiting_for_forward_comment = True
27+
await self.handle_forward(msg)
28+
elif not self.waiting_for_forward_comment:
29+
await msg.delete()
30+
await msg.channel.send(f"{msg.author.mention} Обсуждайте в ветках!", delete_after=3)
2331
else:
2432
await msg.delete()
2533
await msg.channel.send(f"{msg.author.mention} Обсуждайте в ветках!", delete_after=3)
2634

27-
async def create_auto_thread(msg):
28-
content = sub(r"https?:\/\/\S+", "", msg.content)
35+
async def handle_forward(self, msg):
36+
end_msg = msg
37+
msg_content = msg.message_snapshots[0].content
38+
await sleep(0.7)
39+
self.waiting_for_forward_comment = False
40+
if msg.channel.last_message_id != msg.id:
41+
end_msg = await msg.channel.fetch_message(msg.channel.last_message_id)
42+
if not msg_content:
43+
msg_content = end_msg.content
44+
await create_auto_thread(end_msg, msg_content)
45+
46+
47+
async def create_auto_thread(msg, msg_content=None):
48+
msg_content = msg_content if msg_content else msg.content
49+
content = sub(r"https?:\/\/\S+", "", msg_content)
2950
thread_name = content[:97]
3051
if len(thread_name) == 97:
3152
thread_name += "..."
@@ -34,4 +55,3 @@ async def create_auto_thread(msg):
3455
except discord.errors.HTTPException:
3556
channel_name = sub(r"[^\w-]*", "", msg.channel.name)
3657
await msg.create_thread(name=f"Обсуждение {channel_name} {msg.author.display_name}")
37-

utils/__init__.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from utils.fake_user import fake_send
2+
from utils.general import handle_errors
3+
from utils.msg_utils import get_msg_by_id_arg, split_msg, user_from_embed, Emojis
4+
from utils.pack_generator import Templates, PGenerator, Modals
5+
from utils.packmcmeta import update_mcmeta_info, get_mcmeta_ver
6+
from utils.shortcuts import no_color, no_ping
7+
from utils.time import get_secs
8+
from utils.tree_gen import generate_tree
9+
from utils.users_db import DB
10+
from utils.validator import validate, is_valid_image, all_valid, closest_match

utils/msg_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async def get_msg_by_id_arg(self, ctx, bot, arg:str):
1313
except Exception as e:
1414
return e
1515

16-
# Thx bing/copilot 😘
16+
1717
def split_msg(s):
1818
MAX_LENGTH = 2000
1919
blocks = split(r'(```.*?```)', s, flags=DOTALL)

0 commit comments

Comments
 (0)