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 25, 2024
1 parent 3ae9672 commit 8725944
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions pixelateTG.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,10 @@ def pixelate_faces(update: Update, context: CallbackContext) -> None:

context.user_data[session_id]['photo_path'] = photo_path
context.user_data[session_id]['user_id'] = update.message.from_user.id
# Delete the original picture from the chat
update.message.delete()

# Schedule a cleanup for this session after 5 minutes
Timer(SESSION_TIMEOUT, clean_up_sessions, [context]).start()



def process_image(photo_path, user_id, file_id, bot):
image = cv2.imread(photo_path)
faces = detect_heads(image)
Expand Down Expand Up @@ -138,7 +134,8 @@ def apply_overlay(photo_path, user_id, bot, overlay_name):
num_cats = len([name for name in os.listdir() if name.startswith('cat_')])
overlay = cv2.imread(f'cat_{random.randint(1, num_cats)}.png', cv2.IMREAD_UNCHANGED)
elif overlay_name == 'pepe':
num_pepes = len([name for name in os.listdir() if name.startswith('pepe_')])
num_pepes = len([name for name in os.listdir() if
overlay_name.startswith('pepe_')])
overlay = cv2.imread(f'pepe_{random.randint(1, num_pepes)}.png', cv2.IMREAD_UNCHANGED)
elif overlay_name == 'chad':
num_chads = len([name for name in os.listdir() if name.startswith('chad_')])
Expand Down Expand Up @@ -168,6 +165,7 @@ def button_callback(update: Update, context: CallbackContext) -> None:

if query.data.startswith('cancel'):
del context.user_data[session_id] # Delete session data
query.message.reply_text('Operation canceled') # Inform the user
query.message.delete() # Remove the message containing the keyboard
return

Expand All @@ -194,8 +192,6 @@ def button_callback(update: Update, context: CallbackContext) -> None:
query.edit_message_reply_markup(reply_markup=query.message.reply_markup)
return # Exit the function here to prevent further execution



def clean_up_sessions(context: CallbackContext) -> None:
current_time = time.time()
user_data = context.user_data
Expand Down

0 comments on commit 8725944

Please sign in to comment.