diff --git a/bot.py b/bot.py index 79771c4..f1f48bb 100644 --- a/bot.py +++ b/bot.py @@ -1,6 +1,7 @@ #@MxA_Bots | @iSmartBoi_Ujjwal import os +import time import asyncio import traceback from binascii import ( @@ -25,7 +26,7 @@ from configs import Config from handlers.database import db from handlers.add_user_to_db import add_user_to_database -from handlers.send_file import send_media_and_reply +from handlers.send_file import send_media from handlers.helpers import b64_to_str, str_to_b64 from handlers.check_user_status import handle_user_status from handlers.force_sub_handler import ( @@ -48,6 +49,7 @@ api_hash=Config.API_HASH ) +DELETE_TIME = 20 @Bot.on_message(filters.private) async def _(bot: Client, cmd: Message): @@ -98,18 +100,30 @@ async def start(bot: Client, cmd: Message): message_ids = [] if GetMessage.text: message_ids = GetMessage.text.split(" ") - _response_msg = await cmd.reply_text( - text=f"**Total Files:** `{len(message_ids)}`", - quote=True, - disable_web_page_preview=True - ) + #_response_msg = await cmd.reply_text( + #text=f"**Total Files:** `{len(message_ids)}`", + # quote=True, + # disable_web_page_preview=True + # ) + # else: + #message_ids.append(int(GetMessage.id)) + # for i in range(len(message_ids)): + #await send_media_and_reply(bot, user_id=cmd.from_user.id, file_id=int(message_ids[i])) + # except Exception as err: + # await cmd.reply_text('files will delete after few seconds') else: message_ids.append(int(GetMessage.id)) + files = reply_message.media + sent_messages = [] for i in range(len(message_ids)): - await send_media_and_reply(bot, user_id=cmd.from_user.id, file_id=int(message_ids[i])) - except Exception as err: - await cmd.reply_text(f"Something went wrong!\n\n**Error:** `{err}`") - + # for file in files: + sent_message = await message.send_media(bot, user_id=cmd.from_user.id, file_id=int(message_ids[i])) + sent_messages.append(sent_message) # for batch files + await asyncio.sleep(DELETE_TIME) # Wait for 20 seconds + for sent_message in sent_messages: + await sent_message.delete() # Delete all files + except: + pass @Bot.on_message((filters.document | filters.video | filters.audio) & ~filters.chat(Config.DB_CHANNEL)) async def main(bot: Client, message: Message): diff --git a/handlers/Ntg.txt b/handlers/Ntg.txt new file mode 100644 index 0000000..810e341 --- /dev/null +++ b/handlers/Ntg.txt @@ -0,0 +1,56 @@ +#@MxA_Bots | @iSmartBoi_Ujjwal + +import asyncio +from configs import Config +from pyrogram import Client +from pyrogram.types import Message +from pyrogram.errors import FloodWait +from handlers.helpers import str_to_b64 +import time + +async def reply_forward(message: Message, file_id: int): + try: + await message.reply_text( + f"**Files will be Deleted After few seconds ⏰**\n", + disable_web_page_preview=True, quote=True) + except FloodWait as e: + await asyncio.sleep(e.value) + await reply_forward(message, file_id) + + +async def media_forward(bot: Client, user_id: int, file_id: int): + try: + if Config.FORWARD_AS_COPY is True: + return await bot.copy_message(chat_id=user_id, from_chat_id=Config.DB_CHANNEL, + message_id=file_id) + elif Config.FORWARD_AS_COPY is False: + return await bot.forward_messages(chat_id=user_id, from_chat_id=Config.DB_CHANNEL, + message_ids=file_id) + except FloodWait as e: + await asyncio.sleep(e.value) + return media_forward(bot, user_id, file_id) + + +async def delete_file(file_id: int): + await asyncio.sleep(10) # wait for 20 seconds + # Delete the file using the file ID + # Code to delete the file goes here + + +async def send_media_and_reply(bot: Client, user_id: int, file_id: int): + sent_message = await media_forward(bot, user_id, file_id) + # await reply_forward(message=sent_message, file_id=file_id) + time.sleep(1) + return sent_message + #await sent_message.delete(delete_file(file_id=file_id)) # schedule the file deletion task + +#async def send_files(bot, user_id, file_ids): + #for file_id in file_ids: + # bot.send_chat_action(user_id=user_id, action=telegram.ChatAction.SEND_DOCUMENT) + # bot.send_document(user_id=user_id, document=file_id) + # Wait for 30 seconds before deleting files + # time.sleep(30) + + # # Delete all files after the last file has been sent + # for file_id in file_ids: + # bot.delete_message(user_id=user_id, message_id=file_id) diff --git a/handlers/send_file.py b/handlers/send_file.py index ef3b6db..4310c96 100644 --- a/handlers/send_file.py +++ b/handlers/send_file.py @@ -7,11 +7,12 @@ from pyrogram.errors import FloodWait from handlers.helpers import str_to_b64 - async def reply_forward(message: Message, file_id: int): try: await message.reply_text( - f"**Files will be Deleted After few seconds ⏰**\n", + f"**Files will be Deleted After 1 min**\n" + f"💡Forward it to saved massages or anywhere before downloading.😁\n" + f"😇Join @Movies_X_Animes", disable_web_page_preview=True, quote=True) except FloodWait as e: await asyncio.sleep(e.value) @@ -23,6 +24,7 @@ async def media_forward(bot: Client, user_id: int, file_id: int): if Config.FORWARD_AS_COPY is True: return await bot.copy_message(chat_id=user_id, from_chat_id=Config.DB_CHANNEL, message_id=file_id) + elif Config.FORWARD_AS_COPY is False: return await bot.forward_messages(chat_id=user_id, from_chat_id=Config.DB_CHANNEL, message_ids=file_id) @@ -31,14 +33,31 @@ async def media_forward(bot: Client, user_id: int, file_id: int): return media_forward(bot, user_id, file_id) -async def delete_file(file_id: int): - await asyncio.sleep(50) # wait for 50 seconds - # Delete the file using the file ID - # Code to delete the file goes here +# async def send_media_and_reply(bot: Client, user_id: int, file_id: int): + # sent_message = await media_forward(bot, user_id, file_id) + # await asyncio.sleep(1) + # return sent_message + # n = await reply_forward(message=sent_message, file_id=file_id) + # await asyncio.sleep(60) + # await sent_message.delete() + # await asyncio.sleep(0.5) + # await n.delete() + + +async def send_media(bot: Client, user_id: int, file_id: int): + new_message = await media_forward(bot, user_id, file_id) + await asyncio.sleep(1) + return new_message + + + + + + + + + + + -async def send_media_and_reply(bot: Client, user_id: int, file_id: int): - sent_message = await media_forward(bot, user_id, file_id) - await reply_forward(message=sent_message, file_id=file_id) - asyncio.create_task(delete_file(file_id)) # schedule the file deletion task - await asyncio.sleep(2)