This repository has been archived by the owner on Sep 1, 2022. It is now read-only.
forked from Mahesh0253/Media-Search-bot
-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
246 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import logging | ||
import asyncio | ||
from pyrogram import Client, filters | ||
from pyrogram.errors import FloodWait | ||
from info import USERBOT_STRING_SESSION, API_ID, API_HASH, ADMINS, id_pattern | ||
from utils import save_file | ||
|
||
logger = logging.getLogger(__name__) | ||
lock = asyncio.Lock() | ||
|
||
|
||
@Client.on_message(filters.command(['index', 'indexfiles']) & filters.user(ADMINS)) | ||
async def index_files(bot, message): | ||
"""Save channel or group files with the help of user bot""" | ||
|
||
if not USERBOT_STRING_SESSION: | ||
await message.reply('Set `USERBOT_STRING_SESSION` in info.py file or in environment variables.') | ||
elif len(message.command) == 1: | ||
await message.reply('Please specify channel username or id in command.\n\n' | ||
'Example: `/index -10012345678`') | ||
elif lock.locked(): | ||
await message.reply('Wait until previous process complete.') | ||
else: | ||
msg = await message.reply('Processing...⏳') | ||
raw_data = message.command[1:] | ||
user_bot = Client(USERBOT_STRING_SESSION, API_ID, API_HASH) | ||
chats = [int(chat) if id_pattern.search(chat) else chat for chat in raw_data] | ||
total_files = 0 | ||
|
||
async with lock: | ||
try: | ||
async with user_bot: | ||
for chat in chats: | ||
|
||
async for user_message in user_bot.iter_history(chat): | ||
try: | ||
message = await bot.get_messages( | ||
chat, | ||
user_message.message_id, | ||
replies=0, | ||
) | ||
except FloodWait as e: | ||
await asyncio.sleep(e.x) | ||
message = await bot.get_messages( | ||
chat, | ||
user_message.message_id, | ||
replies=0, | ||
) | ||
|
||
for file_type in ("document", "video", "audio"): | ||
media = getattr(message, file_type, None) | ||
if media is not None: | ||
break | ||
else: | ||
continue | ||
media.file_type = file_type | ||
media.caption = message.caption | ||
await save_file(media) | ||
total_files += 1 | ||
except Exception as e: | ||
logger.exception(e) | ||
await msg.edit(f'Error: {e}') | ||
else: | ||
await msg.edit(f'Total {total_files} checked!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
https://github.com/Mahesh0253/pyrogram/archive/beta.zip | ||
tgcrypto | ||
umongo==2.3.0 | ||
motor==2.3.0 | ||
dnspython | ||
https://github.com/Mahesh0253/pyrogram/archive/inline.zip | ||
tgcrypto==1.2.2 | ||
umongo[motor]==3.0.0 | ||
dnspython==2.1.0 |
Oops, something went wrong.