Skip to content

Commit 80fb2db

Browse files
authored
Removed Some Codes
1 parent 1297644 commit 80fb2db

File tree

1 file changed

+18
-57
lines changed

1 file changed

+18
-57
lines changed

plugins/link_generator.py

Lines changed: 18 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,33 @@
1-
import re
21
from pyrogram import Client, filters
32
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
43
from bot import Bot
54
from config import ADMINS
6-
from helper_func import encode
5+
from helper_func import encode, get_message_id
76

87
@Bot.on_message(filters.private & filters.user(ADMINS) & filters.command('batch'))
98
async def batch(client: Client, message: Message):
109
while True:
1110
try:
12-
first_message = await client.ask(text = "Forward the First Message from DB Channel (with Quotes)..\nor Send the Post Link", chat_id = message.from_user.id, filters=(filters.forwarded | (filters.text & ~filters.forwarded)), timeout=30)
11+
first_message = await client.ask(text = "Forward the First Message from DB Channel (with Quotes)..\n\nor Send the Post Link", chat_id = message.from_user.id, filters=(filters.forwarded | (filters.text & ~filters.forwarded)), timeout=30)
1312
except:
1413
return
15-
if first_message.forward_from_chat:
16-
if first_message.forward_from_chat.id == client.db_channel.id:
17-
s_msg_id = first_message.forward_from_message_id
18-
break
19-
await first_message.reply_text("Forward from the Assigned Channel only...", quote = True)
20-
continue
21-
elif first_message.forward_sender_name:
22-
await second_message.reply_text("Forward from the Assigned Channel only...", quote = True)
23-
continue
24-
elif first_message.text:
25-
pattern = "https://t.me/(?:c/)?(.*)/(\d+)"
26-
matches = re.match(pattern,first_message.text)
27-
if not matches:
28-
await first_message.reply("This is not a Proper telegram post link", quote=True)
29-
continue
30-
channel_id = matches.group(1)
31-
f_msg_id = int(matches.group(2))
32-
if channel_id.isdigit():
33-
if f"-100{channel_id}" == str(client.db_channel.id):
34-
break
35-
else:
36-
if channel_id == client.db_channel.username:
37-
break
38-
await first_message.reply("Send the link of post from the db channel only", quote=True)
14+
f_msg_id = await get_message_id(client, first_message)
15+
if f_msg_id:
16+
break
17+
else:
18+
await f_msg_id.reply("<b>❌ Error\n\nthis Forwarded Post is not from my DB Channel or this Link is taken from DB Channel</b>" quote = True)
3919
continue
4020

4121
while True:
4222
try:
4323
second_message = await client.ask(text = "Forward the Last Message from DB Channel (with Quotes)..\nor Send the Post Link", chat_id = message.from_user.id, filters=(filters.forwarded | (filters.text & ~filters.forwarded)), timeout=30)
4424
except:
4525
return
46-
if second_message.forward_from_chat:
47-
if second_message.forward_from_chat.id == client.db_channel.id:
48-
s_msg_id = second_message.forward_from_message_id
49-
break
50-
await second_message.reply_text("Forward from the Assigned Channel only...", quote = True)
51-
continue
52-
elif second_message.forward_sender_name:
53-
await second_message.reply_text("Forward from the Assigned Channel only...", quote = True)
54-
continue
55-
elif second_message.text:
56-
pattern = "https://t.me/(?:c/)?(.*)/(\d+)"
57-
matches = re.match(pattern,second_message.text)
58-
if not matches:
59-
await second_message.reply("This is not a Proper telegram post link", quote=True)
60-
continue
61-
channel_id = matches.group(1)
62-
s_msg_id = int(matches.group(2))
63-
if channel_id.isdigit():
64-
if f"-100{channel_id}" == str(client.db_channel.id):
65-
break
66-
else:
67-
if channel_id == client.db_channel.username:
68-
break
69-
await second_message.reply("Send the link of post from the db channel only", quote=True)
26+
s_msg_id = await get_message_id(client, second_message)
27+
if s_msg_id:
28+
break
29+
else:
30+
await second_message.reply("<b>❌ Error\n\nthis Forwarded Post is not from my DB Channel or this Link is taken from DB Channel</b>" quote = True)
7031
continue
7132

7233

@@ -84,12 +45,12 @@ async def link_generator(client: Client, message: Message):
8445
channel_message = await client.ask(text = "Forward Message from the DB Channel (with Quotes)..", chat_id = message.from_user.id, filters=filters.forwarded, timeout=30)
8546
except:
8647
return
87-
if channel_message.forward_from_chat:
88-
if channel_message.forward_from_chat.id == client.db_channel.id:
89-
msg_id = channel_message.forward_from_message_id
90-
break
91-
await channel_message.reply_text("Forward from the Assigned Channel only...", quote = True)
92-
continue
48+
msg_id = await get_message_id(client, channel_message)
49+
if msg_id:
50+
break
51+
else:
52+
await channel_message.reply("<b>❌ Error\n\nthis Forwarded Post is not from my DB Channel or this Link is taken from DB Channel</b>" quote = True)
53+
9354

9455
base64_string = await encode(f"get-{msg_id * abs(client.db_channel.id)}")
9556
link = f"https://t.me/{client.username}?start={base64_string}"

0 commit comments

Comments
 (0)