forked from AbirHasan2005/PyroFilesStoreBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsave_media.py
131 lines (124 loc) · 5.73 KB
/
save_media.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# (c) @AbirHasan2005
import asyncio
from configs import Config
from pyrogram import Client
from pyrogram.types import (
Message,
InlineKeyboardMarkup,
InlineKeyboardButton
)
from pyrogram.errors import FloodWait
from handlers.helpers import str_to_b64
async def forward_to_channel(bot: Client, message: Message, editable: Message):
try:
__SENT = await message.forward(Config.DB_CHANNEL)
return __SENT
except FloodWait as sl:
if sl.value > 45:
await asyncio.sleep(sl.value)
await bot.send_message(
chat_id=int(Config.LOG_CHANNEL),
text=f"#FloodWait:\nGot FloodWait of `{str(sl.value)}s` from `{str(editable.chat.id)}` !!",
disable_web_page_preview=True,
reply_markup=InlineKeyboardMarkup(
[
[InlineKeyboardButton("Ban User", callback_data=f"ban_user_{str(editable.chat.id)}")]
]
)
)
return await forward_to_channel(bot, message, editable)
async def save_batch_media_in_channel(bot: Client, editable: Message, message_ids: list):
try:
message_ids_str = ""
for message in (await bot.get_messages(chat_id=editable.chat.id, message_ids=message_ids)):
sent_message = await forward_to_channel(bot, message, editable)
if sent_message is None:
continue
message_ids_str += f"{str(sent_message.id)} "
await asyncio.sleep(2)
SaveMessage = await bot.send_message(
chat_id=Config.DB_CHANNEL,
text=message_ids_str,
disable_web_page_preview=True,
reply_markup=InlineKeyboardMarkup([[
InlineKeyboardButton("Delete Batch", callback_data="closeMessage")
]])
)
share_link = f"https://t.me/{Config.BOT_USERNAME}?start=AbirHasan2005_{str_to_b64(str(SaveMessage.id))}"
await editable.edit(
f"**Batch Files Stored in my Database!**\n\nHere is the Permanent Link of your files: {share_link} \n\n"
f"Just Click the link to get your files!",
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton("Open Link", url=share_link)],
[InlineKeyboardButton("Bots Channel", url="https://t.me/Discovery_Updates"),
InlineKeyboardButton("Support Group", url="https://t.me/JoinOT")]]
),
disable_web_page_preview=True
)
await bot.send_message(
chat_id=int(Config.LOG_CHANNEL),
text=f"#BATCH_SAVE:\n\n[{editable.reply_to_message.from_user.first_name}](tg://user?id={editable.reply_to_message.from_user.id}) Got Batch Link!",
disable_web_page_preview=True,
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("Open Link", url=share_link)]])
)
except Exception as err:
await editable.edit(f"Something Went Wrong!\n\n**Error:** `{err}`")
await bot.send_message(
chat_id=int(Config.LOG_CHANNEL),
text=f"#ERROR_TRACEBACK:\nGot Error from `{str(editable.chat.id)}` !!\n\n**Traceback:** `{err}`",
disable_web_page_preview=True,
reply_markup=InlineKeyboardMarkup(
[
[InlineKeyboardButton("Ban User", callback_data=f"ban_user_{str(editable.chat.id)}")]
]
)
)
async def save_media_in_channel(bot: Client, editable: Message, message: Message):
try:
forwarded_msg = await message.forward(Config.DB_CHANNEL)
file_er_id = str(forwarded_msg.id)
await forwarded_msg.reply_text(
f"#PRIVATE_FILE:\n\n[{message.from_user.first_name}](tg://user?id={message.from_user.id}) Got File Link!",
disable_web_page_preview=True)
share_link = f"https://t.me/{Config.BOT_USERNAME}?start=AbirHasan2005_{str_to_b64(file_er_id)}"
await editable.edit(
"**Your File Stored in my Database!**\n\n"
f"Here is the Permanent Link of your file: {share_link} \n\n"
"Just Click the link to get your file!",
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton("Open Link", url=share_link)],
[InlineKeyboardButton("Bots Channel", url="https://t.me/Discovery_Updates"),
InlineKeyboardButton("Support Group", url="https://t.me/JoinOT")]]
),
disable_web_page_preview=True
)
except FloodWait as sl:
if sl.value > 45:
print(f"Sleep of {sl.value}s caused by FloodWait ...")
await asyncio.sleep(sl.value)
await bot.send_message(
chat_id=int(Config.LOG_CHANNEL),
text="#FloodWait:\n"
f"Got FloodWait of `{str(sl.value)}s` from `{str(editable.chat.id)}` !!",
disable_web_page_preview=True,
reply_markup=InlineKeyboardMarkup(
[
[InlineKeyboardButton("Ban User", callback_data=f"ban_user_{str(editable.chat.id)}")]
]
)
)
await save_media_in_channel(bot, editable, message)
except Exception as err:
await editable.edit(f"Something Went Wrong!\n\n**Error:** `{err}`")
await bot.send_message(
chat_id=int(Config.LOG_CHANNEL),
text="#ERROR_TRACEBACK:\n"
f"Got Error from `{str(editable.chat.id)}` !!\n\n"
f"**Traceback:** `{err}`",
disable_web_page_preview=True,
reply_markup=InlineKeyboardMarkup(
[
[InlineKeyboardButton("Ban User", callback_data=f"ban_user_{str(editable.chat.id)}")]
]
)
)