Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @client.on(events.NewMessage(pattern=r'^[\/^]up (.+)'))
- async def handle_upload(event):
- me = await client.get_me()
- if event.sender_id != me.id:
- return
- else:
- caption = event.pattern_match.group(1)
- if event.is_reply:
- reply_message = await event.get_reply_message()
- if reply_message and reply_message.media:
- media_path = await reply_message.download_media()
- processed_path = preprocess_image(media_path)
- if not processed_path:
- await event.reply("❌ Failed to process the image.")
- return
- # print(f"Processed Image Path: {processed_path}")
- # print(f"Processed Image Size: {os.path.getsize(processed_path)} bytes")
- media = await client.upload_file(processed_path)
- # print(f"Media uploaded: {media}")
- # print(f"Media file ID: {media.file_id}")
- # print(f"Media file name: {media.name}")
- # print(f"File Size: {media.size} bytes")
- # print(f"Type of uploaded media: {type(media)}")
- await client(functions.stories.SendStoryRequest(
- peer='me',
- media=types.InputMediaUploadedPhoto(file=media),
- caption=f"{caption}",
- privacy_rules=[types.InputPrivacyValueAllowAll()],
- random_id=random.randint(1, 2**63 - 1),
- period=86400
- ))
Advertisement
Add Comment
Please, Sign In to add comment