diff --git a/helper/database.py b/helper/database.py index fe4e122..b5320ad 100644 --- a/helper/database.py +++ b/helper/database.py @@ -11,11 +11,9 @@ def insert(chat_id): user_id = int(chat_id) user_det = {"_id":user_id,"file_id":None , "date":0} try: - dbcol.insert_one(user_det) + dbcol.insert_one(user_det) except: - value = 'new' - return value - pass + return 'new' def addthumb(chat_id, file_id): dbcol.update_one({"_id":chat_id},{"$set":{"file_id":file_id}}) @@ -24,18 +22,13 @@ def delthumb(chat_id): dbcol.update_one({"_id":chat_id},{"$set":{"file_id":None}}) def find(chat_id): - id = {"_id":chat_id} - x = dbcol.find(id) - for i in x: - lgcd = i["file_id"] - return lgcd + id = {"_id":chat_id} + x = dbcol.find(id) + for i in x: + return i["file_id"] def getid(): - values = [] - for key in dbcol.find(): - id = key["_id"] - values.append((id)) - return values + return [key["_id"] for key in dbcol.find()] def find_one(id): return dbcol.find_one({"_id":id}) diff --git a/plugins/broadcast.py b/plugins/broadcast.py index 3866153..7f59b72 100644 --- a/plugins/broadcast.py +++ b/plugins/broadcast.py @@ -9,22 +9,22 @@ @Client.on_message(filters.private & filters.user(ADMIN) & filters.command(["broadcast"])) async def broadcast(bot, message): - if (message.reply_to_message): - ms = await message.reply_text("Geting All ids from database ...........") - ids = getid() - tot = len(ids) - success = 0 - failed = 0 - await ms.edit(f"Starting Broadcast .... \n Sending Message To {tot} Users") - for id in ids: - try: - time.sleep(1) - await message.reply_to_message.copy(id) - success += 1 - except: - failed += 1 - pass - try: - await ms.edit( f"Message sent to {success} chat(s). {failed} chat(s) failed on receiving message. \nTotal - {tot}" ) - except FloodWait as e: - await asyncio.sleep(t.x) + if not message.reply_to_message: + return + ms = await message.reply_text("Geting All ids from database ...........") + ids = getid() + tot = len(ids) + success = 0 + failed = 0 + await ms.edit(f"Starting Broadcast .... \n Sending Message To {tot} Users") + for id in ids: + try: + time.sleep(1) + await message.reply_to_message.copy(id) + success += 1 + except: + failed += 1 + try: + await ms.edit( f"Message sent to {success} chat(s). {failed} chat(s) failed on receiving message. \nTotal - {tot}" ) + except FloodWait as e: + await asyncio.sleep(t.x) diff --git a/plugins/cb_data.py b/plugins/cb_data.py index 97e249b..e5077bb 100644 --- a/plugins/cb_data.py +++ b/plugins/cb_data.py @@ -25,160 +25,153 @@ async def rename(bot,update): @Client.on_callback_query(filters.regex("doc")) async def doc(bot,update): - new_name = update.message.text - name = new_name.split(":-") - new_filename = name[1] - file_path = f"downloads/{new_filename}" - file = update.message.reply_to_message - ms = await update.message.edit("``` Trying To Download...```") - c_time = time.time() - try: - path = await bot.download_media(message = file, progress=progress_for_pyrogram,progress_args=( "``` Trying To Download...```", ms, c_time )) - except Exception as e: - await ms.edit(e) - return - - splitpath = path.split("/downloads/") - dow_file_name = splitpath[1] - old_file_name =f"downloads/{dow_file_name}" - os.rename(old_file_name,file_path) - user_id = int(update.message.chat.id) - thumb = find(user_id) - if thumb: - ph_path = await bot.download_media(thumb) - Image.open(ph_path).convert("RGB").save(ph_path) - img = Image.open(ph_path) - img.resize((320, 320)) - img.save(ph_path, "JPEG") - c_time = time.time() - await ms.edit("```Trying To Upload```") - c_time = time.time() - try: - await bot.send_document(update.message.chat.id,document = file_path,thumb=ph_path,caption = f"**{new_filename}**",progress=progress_for_pyrogram,progress_args=( "```Trying To Uploading```", ms, c_time )) - await ms.delete() - os.remove(file_path) - os.remove(ph_path) - except Exception as e: - await ms.edit(e) - os.remove(file_path) - os.remove(ph_path) - - else: - await ms.edit("```Trying To Upload```") - c_time = time.time() - try: - await bot.send_document(update.message.chat.id,document = file_path,caption = f"**{new_filename}**",progress=progress_for_pyrogram,progress_args=( "```Trying To Uploading```", ms, c_time )) - await ms.delete() - os.remove(file_path) - except Exception as e: - await ms.edit(e) - os.remove(file_path) + new_name = update.message.text + name = new_name.split(":-") + new_filename = name[1] + file_path = f"downloads/{new_filename}" + file = update.message.reply_to_message + ms = await update.message.edit("``` Trying To Download...```") + c_time = time.time() + try: + path = await bot.download_media(message = file, progress=progress_for_pyrogram,progress_args=( "``` Trying To Download...```", ms, c_time )) + except Exception as e: + await ms.edit(e) + return + + splitpath = path.split("/downloads/") + dow_file_name = splitpath[1] + old_file_name =f"downloads/{dow_file_name}" + os.rename(old_file_name,file_path) + user_id = int(update.message.chat.id) + if thumb := find(user_id): + ph_path = await bot.download_media(thumb) + Image.open(ph_path).convert("RGB").save(ph_path) + img = Image.open(ph_path) + img.resize((320, 320)) + img.save(ph_path, "JPEG") + c_time = time.time() + await ms.edit("```Trying To Upload```") + c_time = time.time() + try: + await bot.send_document(update.message.chat.id,document = file_path,thumb=ph_path,caption = f"**{new_filename}**",progress=progress_for_pyrogram,progress_args=( "```Trying To Uploading```", ms, c_time )) + await ms.delete() + os.remove(file_path) + os.remove(ph_path) + except Exception as e: + await ms.edit(e) + os.remove(file_path) + os.remove(ph_path) + + else: + await ms.edit("```Trying To Upload```") + c_time = time.time() + try: + await bot.send_document(update.message.chat.id,document = file_path,caption = f"**{new_filename}**",progress=progress_for_pyrogram,progress_args=( "```Trying To Uploading```", ms, c_time )) + await ms.delete() + os.remove(file_path) + except Exception as e: + await ms.edit(e) + os.remove(file_path) @Client.on_callback_query(filters.regex("vid")) async def vid(bot,update): - new_name = update.message.text - name = new_name.split(":-") - new_filename = name[1] - file_path = f"downloads/{new_filename}" - file = update.message.reply_to_message - ms = await update.message.edit("``` Trying To Download...```") - c_time = time.time() - try: - path = await bot.download_media(message = file, progress=progress_for_pyrogram,progress_args=( "``` Trying To Download...```", ms, c_time )) - except Exception as e: - await ms.edit(e) - return - - splitpath = path.split("/downloads/") - dow_file_name = splitpath[1] - old_file_name =f"downloads/{dow_file_name}" - os.rename(old_file_name,file_path) - duration = 0 - metadata = extractMetadata(createParser(file_path)) - if metadata.has("duration"): - duration = metadata.get('duration').seconds - user_id = int(update.message.chat.id) - thumb = find(user_id) - if thumb: - ph_path = await bot.download_media(thumb) - Image.open(ph_path).convert("RGB").save(ph_path) - img = Image.open(ph_path) - img.resize((320, 320)) - img.save(ph_path, "JPEG") - c_time = time.time() - await ms.edit("```Trying To Upload```") - c_time = time.time() - try: - await bot.send_video(update.message.chat.id,video = file_path,caption = f"**{new_filename}**",thumb=ph_path,duration =duration, progress=progress_for_pyrogram,progress_args=( "```Trying To Uploading```", ms, c_time )) - await ms.delete() - os.remove(file_path) - os.remove(ph_path) - except Exception as e: - await ms.edit(e) - os.remove(file_path) - os.remove(ph_path) - - else: - await ms.edit("```Trying To Upload```") - c_time = time.time() - try: - await bot.send_video(update.message.chat.id,video = file_path,caption = f"**{new_filename}**",duration = duration, progress=progress_for_pyrogram,progress_args=( "```Trying To Uploading```", ms, c_time )) - await ms.delete() - os.remove(file_path) - except Exception as e: - await ms.edit(e) - os.remove(file_path) + new_name = update.message.text + name = new_name.split(":-") + new_filename = name[1] + file_path = f"downloads/{new_filename}" + file = update.message.reply_to_message + ms = await update.message.edit("``` Trying To Download...```") + c_time = time.time() + try: + path = await bot.download_media(message = file, progress=progress_for_pyrogram,progress_args=( "``` Trying To Download...```", ms, c_time )) + except Exception as e: + await ms.edit(e) + return + + splitpath = path.split("/downloads/") + dow_file_name = splitpath[1] + old_file_name =f"downloads/{dow_file_name}" + os.rename(old_file_name,file_path) + metadata = extractMetadata(createParser(file_path)) + duration = metadata.get('duration').seconds if metadata.has("duration") else 0 + user_id = int(update.message.chat.id) + if thumb := find(user_id): + ph_path = await bot.download_media(thumb) + Image.open(ph_path).convert("RGB").save(ph_path) + img = Image.open(ph_path) + img.resize((320, 320)) + img.save(ph_path, "JPEG") + c_time = time.time() + await ms.edit("```Trying To Upload```") + c_time = time.time() + try: + await bot.send_video(update.message.chat.id,video = file_path,caption = f"**{new_filename}**",thumb=ph_path,duration =duration, progress=progress_for_pyrogram,progress_args=( "```Trying To Uploading```", ms, c_time )) + await ms.delete() + os.remove(file_path) + os.remove(ph_path) + except Exception as e: + await ms.edit(e) + os.remove(file_path) + os.remove(ph_path) + + else: + await ms.edit("```Trying To Upload```") + c_time = time.time() + try: + await bot.send_video(update.message.chat.id,video = file_path,caption = f"**{new_filename}**",duration = duration, progress=progress_for_pyrogram,progress_args=( "```Trying To Uploading```", ms, c_time )) + await ms.delete() + os.remove(file_path) + except Exception as e: + await ms.edit(e) + os.remove(file_path) @Client.on_callback_query(filters.regex("aud")) async def aud(bot,update): - new_name = update.message.text - name = new_name.split(":-") - new_filename = name[1] - file_path = f"downloads/{new_filename}" - file = update.message.reply_to_message - ms = await update.message.edit("``` Trying To Download...```") - c_time = time.time() - try: - path = await bot.download_media(message = file , progress=progress_for_pyrogram,progress_args=( "``` Trying To Download...```", ms, c_time )) - except Exception as e: - await ms.edit(e) - return - splitpath = path.split("/downloads/") - dow_file_name = splitpath[1] - old_file_name =f"downloads/{dow_file_name}" - os.rename(old_file_name,file_path) - duration = 0 - metadata = extractMetadata(createParser(file_path)) - if metadata.has("duration"): - duration = metadata.get('duration').seconds - user_id = int(update.message.chat.id) - thumb = find(user_id) - if thumb: - ph_path = await bot.download_media(thumb) - Image.open(ph_path).convert("RGB").save(ph_path) - img = Image.open(ph_path) - img.resize((320, 320)) - img.save(ph_path, "JPEG") - await ms.edit("```Trying To Upload```") - c_time = time.time() - try: - await bot.send_audio(update.message.chat.id,audio = file_path,caption = f"**{new_filename}**",thumb=ph_path,duration =duration, progress=progress_for_pyrogram,progress_args=( "```Trying To Uploading```", ms, c_time )) - await ms.delete() - os.remove(file_path) - os.remove(ph_path) - except Exception as e: - await ms.edit(e) - os.remove(file_path) - os.remove(ph_path) - else: - await ms.edit("```Trying To Upload```") - c_time = time.time() - try: - await bot.send_audio(update.message.chat.id,audio = file_path,caption = f"**{new_filename}**",duration = duration, progress=progress_for_pyrogram,progress_args=( "```Trying To Uploading```", ms, c_time )) - await ms.delete() - os.remove(file_path) - except Exception as e: - await ms.edit(e) - os.remove(file_path) + new_name = update.message.text + name = new_name.split(":-") + new_filename = name[1] + file_path = f"downloads/{new_filename}" + file = update.message.reply_to_message + ms = await update.message.edit("``` Trying To Download...```") + c_time = time.time() + try: + path = await bot.download_media(message = file , progress=progress_for_pyrogram,progress_args=( "``` Trying To Download...```", ms, c_time )) + except Exception as e: + await ms.edit(e) + return + splitpath = path.split("/downloads/") + dow_file_name = splitpath[1] + old_file_name =f"downloads/{dow_file_name}" + os.rename(old_file_name,file_path) + metadata = extractMetadata(createParser(file_path)) + duration = metadata.get('duration').seconds if metadata.has("duration") else 0 + user_id = int(update.message.chat.id) + if thumb := find(user_id): + ph_path = await bot.download_media(thumb) + Image.open(ph_path).convert("RGB").save(ph_path) + img = Image.open(ph_path) + img.resize((320, 320)) + img.save(ph_path, "JPEG") + await ms.edit("```Trying To Upload```") + c_time = time.time() + try: + await bot.send_audio(update.message.chat.id,audio = file_path,caption = f"**{new_filename}**",thumb=ph_path,duration =duration, progress=progress_for_pyrogram,progress_args=( "```Trying To Uploading```", ms, c_time )) + await ms.delete() + os.remove(file_path) + os.remove(ph_path) + except Exception as e: + await ms.edit(e) + os.remove(file_path) + os.remove(ph_path) + else: + await ms.edit("```Trying To Upload```") + c_time = time.time() + try: + await bot.send_audio(update.message.chat.id,audio = file_path,caption = f"**{new_filename}**",duration = duration, progress=progress_for_pyrogram,progress_args=( "```Trying To Uploading```", ms, c_time )) + await ms.delete() + os.remove(file_path) + except Exception as e: + await ms.edit(e) + os.remove(file_path) diff --git a/plugins/start.py b/plugins/start.py index 8c8d530..17eeb75 100644 --- a/plugins/start.py +++ b/plugins/start.py @@ -36,32 +36,32 @@ async def start(client,message): @Client.on_message(filters.private &( filters.document | filters.audio | filters.video )) async def send_doc(client,message): - update_channel = CHANNEL - user_id = message.from_user.id - if update_channel : - try: - await client.get_chat_member(update_channel, user_id) - except UserNotParticipant: - await message.reply_text("**__You are not subscribed my channel__** ",reply_to_message_id = message.message_id, reply_markup = InlineKeyboardMarkup([ [ InlineKeyboardButton("Support 🇮🇳" ,url=f"https://t.me/{update_channel}") ] ])) - return - date = message.date - _used_date = find_one(user_id) - used_date = _used_date["date"] - c_time = time.time() - LIMIT = 240 - then = used_date+ LIMIT - left = round(then - c_time) - conversion = datetime.timedelta(seconds=left) - ltime = str(conversion) - if left > 0: - await app.send_chat_action(message.chat.id, "typing") - await message.reply_text(f"```Sorry Dude am not only for YOU \n Flood control is active so please wait for {ltime}```",reply_to_message_id = message.message_id) - else: - - media = await client.get_messages(message.chat.id,message.message_id) - file = media.document or media.video or media.audio - dcid = FileId.decode(file.file_id).dc_id - filename = file.file_name - filesize = humanize.naturalsize(file.file_size) - fileid = file.file_id - await message.reply_text(f"""__What do you want me to do with this file?__\n**File Name** :- {filename}\n**File Size** :- {filesize}\n**Dc ID** :- {dcid} """,reply_to_message_id = message.message_id,reply_markup = InlineKeyboardMarkup([[ InlineKeyboardButton("📝 Rename ",callback_data = "rename"),InlineKeyboardButton("Cancel✖️",callback_data = "cancel") ]])) + update_channel = CHANNEL + user_id = message.from_user.id + if update_channel : + try: + await client.get_chat_member(update_channel, user_id) + except UserNotParticipant: + await message.reply_text("**__You are not subscribed my channel__** ",reply_to_message_id = message.message_id, reply_markup = InlineKeyboardMarkup([ [ InlineKeyboardButton("Support 🇮🇳" ,url=f"https://t.me/{update_channel}") ] ])) + return + date = message.date + _used_date = find_one(user_id) + used_date = _used_date["date"] + c_time = time.time() + LIMIT = 240 + then = used_date+ LIMIT + left = round(then - c_time) + conversion = datetime.timedelta(seconds=left) + if left > 0: + await app.send_chat_action(message.chat.id, "typing") + ltime = str(conversion) + await message.reply_text(f"```Sorry Dude am not only for YOU \n Flood control is active so please wait for {ltime}```",reply_to_message_id = message.message_id) + else: + + media = await client.get_messages(message.chat.id,message.message_id) + file = media.document or media.video or media.audio + dcid = FileId.decode(file.file_id).dc_id + filename = file.file_name + filesize = humanize.naturalsize(file.file_size) + fileid = file.file_id + await message.reply_text(f"""__What do you want me to do with this file?__\n**File Name** :- {filename}\n**File Size** :- {filesize}\n**Dc ID** :- {dcid} """,reply_to_message_id = message.message_id,reply_markup = InlineKeyboardMarkup([[ InlineKeyboardButton("📝 Rename ",callback_data = "rename"),InlineKeyboardButton("Cancel✖️",callback_data = "cancel") ]]))