Skip to content

Commit

Permalink
Update pixelateTG.py
Browse files Browse the repository at this point in the history
  • Loading branch information
arbadacarbaYK authored May 30, 2024
1 parent 9f6f808 commit 58f5877
Showing 1 changed file with 48 additions and 48 deletions.
96 changes: 48 additions & 48 deletions pixelateTG.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,62 +103,62 @@ def process_gif(gif_path, session_id, user_id, bot):
return processed_gif_path



def pixelate_faces(update: Update, context: CallbackContext) -> None:
session_id = str(uuid4())
user_data = context.user_data

if update.message.photo or (update.message.document and update.message.document.mime_type == 'image/gif'):
file_id = None
if update.message.photo:
file_id = update.message.photo[-1].file_id
elif update.message.document.mime_type == 'image/gif':
file_id = update.message.document.file_id

if file_id:
file = context.bot.get_file(file_id)
file_name = file.file_path.split('/')[-1]
if file_name.endswith('.gif'):
# Download the GIF file
gif_path = f"downloads/{file_name}"
file.download(gif_path)

# Process the GIF
processed_gif_path = process_gif(gif_path, session_id, update.message.from_user.id, context.bot)
context.bot.send_animation(chat_id=update.message.from_user.id, animation=open(processed_gif_path, 'rb'))

# Clean up temporary files
os.remove(gif_path)
else:
# Process the image
photo_path = f"downloads/{file_name}"
file.download(photo_path)

image = cv2.imread(photo_path)
faces = detect_heads(image)

if not faces:
update.message.reply_text('No faces detected in the image.')
return

keyboard = [
[InlineKeyboardButton("🤡 Clowns", callback_data=f'clowns_overlay_{session_id}'),
InlineKeyboardButton("😂 Liotta", callback_data=f'liotta_overlay_{session_id}'),
InlineKeyboardButton("☠️ Skull", callback_data=f'skull_overlay_{session_id}')],
[InlineKeyboardButton("🐈‍⬛ Cats", callback_data=f'cats_overlay_{session_id}'),
InlineKeyboardButton("🐸 Pepe", callback_data=f'pepe_overlay_{session_id}'),
InlineKeyboardButton("🏆 Chad", callback_data=f'chad_overlay_{session_id}')],
[InlineKeyboardButton("⚔️ Pixel", callback_data=f'pixelate_{session_id}'),
InlineKeyboardButton("CLOSE ME", callback_data=f'cancel_{session_id}')]
]
reply_markup = InlineKeyboardMarkup(keyboard)
user_data[session_id] = {'photo_path': photo_path, 'user_id': update.message.from_user.id}

update.message.reply_text('Press buttons until happy', reply_markup=reply_markup)
update.message.delete()
if update.message.photo:
file_id = update.message.photo[-1].file_id
file = context.bot.get_file(file_id)
file_name = file.file_path.split('/')[-1]

# Process the image
photo_path = f"downloads/{file_name}"
file.download(photo_path)

image = cv2.imread(photo_path)
faces = detect_heads(image)

if not faces:
update.message.reply_text('No faces detected in the image.')
return

keyboard = [
[InlineKeyboardButton("🤡 Clowns", callback_data=f'clowns_overlay_{session_id}'),
InlineKeyboardButton("😂 Liotta", callback_data=f'liotta_overlay_{session_id}'),
InlineKeyboardButton("☠️ Skull", callback_data=f'skull_overlay_{session_id}')],
[InlineKeyboardButton("🐈‍⬛ Cats", callback_data=f'cats_overlay_{session_id}'),
InlineKeyboardButton("🐸 Pepe", callback_data=f'pepe_overlay_{session_id}'),
InlineKeyboardButton("🏆 Chad", callback_data=f'chad_overlay_{session_id}')],
[InlineKeyboardButton("⚔️ Pixel", callback_data=f'pixelate_{session_id}'),
InlineKeyboardButton("CLOSE ME", callback_data=f'cancel_{session_id}')]
]
reply_markup = InlineKeyboardMarkup(keyboard)
user_data[session_id] = {'photo_path': photo_path, 'user_id': update.message.from_user.id}

update.message.reply_text('Press buttons until happy', reply_markup=reply_markup)
update.message.delete()
elif update.message.document and update.message.document.mime_type == 'image/gif':
file_id = update.message.document.file_id
file = context.bot.get_file(file_id)
file_name = file.file_path.split('/')[-1]

# Download the GIF file
gif_path = f"downloads/{file_name}"
file.download(gif_path)

# Process the GIF
processed_gif_path = process_gif(gif_path, session_id, update.message.from_user.id, context.bot)
context.bot.send_animation(chat_id=update.message.from_user.id, animation=open(processed_gif_path, 'rb'))

# Clean up temporary files
os.remove(gif_path)
else:
update.message.reply_text('Please send either a photo or a GIF.')



def pixelate_command(update: Update, context: CallbackContext) -> None:
if update.message.reply_to_message and update.message.reply_to_message.photo:
session_id = str(uuid4())
Expand Down

0 comments on commit 58f5877

Please sign in to comment.