Skip to content

Commit

Permalink
Attach photo Custom Name Updated.✅
Browse files Browse the repository at this point in the history
  • Loading branch information
Aluval authored Jul 23, 2024
1 parent b59a488 commit 0b8c397
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions main/rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,26 @@ async def set_photo(bot, msg):
if not reply or not reply.photo:
return await msg.reply_text("Please reply to a photo with the setphoto command")

# Extract custom name from the command
if len(msg.command) < 2:
return await msg.reply_text("Please provide a custom name for the photo.")

custom_name = msg.command[1] # The custom name is the second part of the command
user_id = msg.from_user.id
photo_file_id = reply.photo.file_id

try:
await db.save_attach_photo(user_id, photo_file_id)
await msg.reply_text("Photo saved successfully.")
# Download the photo file
photo_path = await bot.download_media(photo_file_id)

# Save the photo with the custom name
custom_photo_path = f"{custom_name}.jpg"
os.rename(photo_path, custom_photo_path)

# Save the custom photo path to the database
await db.save_attach_photo(user_id, custom_photo_path)
await msg.reply_text(f"Photo saved successfully with the name: {custom_name}.jpg")

except Exception as e:
await msg.reply_text(f"Error saving photo: {e}")

Expand Down Expand Up @@ -714,6 +728,7 @@ async def change_metadata(bot, msg: Message):


#attach photo

@Client.on_message(filters.command("attachphoto") & filters.chat(GROUP))
async def attach_photo(bot, msg: Message):
global PHOTO_ATTACH_ENABLED
Expand Down Expand Up @@ -751,18 +766,24 @@ async def attach_photo(bot, msg: Message):
return

# Retrieve attachment from the database
attachment_file_id = await db.get_attach_photo(msg.from_user.id)
if not attachment_file_id:
attachment_file_path = await db.get_attach_photo(msg.from_user.id)
if not attachment_file_path:
await safe_edit_message(sts, "Please send a photo to be attached using the `setphoto` command.")
os.remove(downloaded)
return

attachment_path = await bot.download_media(attachment_file_id)
# Ensure the attachment exists and download it if necessary
attachment_path = attachment_file_path
if not os.path.exists(attachment_path):
await safe_edit_message(sts, "Attachment not found.")
os.remove(downloaded)
return

output_file = output_filename

await safe_edit_message(sts, "💠 Adding photo attachment... ⚡")
try:
# Function to add photo attachment (assume it's defined elsewhere)
add_photo_attachment(downloaded, attachment_path, output_file)
except Exception as e:
await safe_edit_message(sts, f"Error adding photo attachment: {e}")
Expand Down Expand Up @@ -791,6 +812,7 @@ async def attach_photo(bot, msg: Message):
try:
# Upload to Google Drive if file size exceeds the limit
if filesize > FILE_SIZE_LIMIT:
# Function to upload to Google Drive (assume it's defined elsewhere)
file_link = await upload_to_google_drive(output_file, os.path.basename(output_file), sts)
button = [[InlineKeyboardButton("☁️ CloudUrl ☁️", url=f"{file_link}")]]
await msg.reply_text(
Expand Down Expand Up @@ -834,7 +856,6 @@ async def attach_photo(bot, msg: Message):




# Command handler
# Command handler for changing audio index
@Client.on_message(filters.command("changeindexaudio") & filters.chat(GROUP))
Expand Down

0 comments on commit 0b8c397

Please sign in to comment.