Skip to content

Commit

Permalink
'Refactored by Sourcery'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sourcery AI committed Jun 24, 2022
1 parent 1d37af8 commit 4308db7
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 211 deletions.
21 changes: 7 additions & 14 deletions helper/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}})
Expand All @@ -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})
38 changes: 19 additions & 19 deletions plugins/broadcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
291 changes: 142 additions & 149 deletions plugins/cb_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading

0 comments on commit 4308db7

Please sign in to comment.