Aayco

Send Story

Mar 9th, 2025
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.43 KB | None | 0 0
  1. @client.on(events.NewMessage(pattern=r'^[\/^]up (.+)'))
  2. async def handle_upload(event):
  3.    me = await client.get_me()
  4.    if event.sender_id != me.id:
  5.       return
  6.    else:
  7.       caption = event.pattern_match.group(1)
  8.       if event.is_reply:
  9.          reply_message = await event.get_reply_message()
  10.          if reply_message and reply_message.media:
  11.             media_path = await reply_message.download_media()
  12.             processed_path = preprocess_image(media_path)
  13.             if not processed_path:
  14.                 await event.reply("❌ Failed to process the image.")
  15.                 return
  16.             # print(f"Processed Image Path: {processed_path}")
  17.             # print(f"Processed Image Size: {os.path.getsize(processed_path)} bytes")
  18.             media = await client.upload_file(processed_path)
  19.             # print(f"Media uploaded: {media}")
  20.             # print(f"Media file ID: {media.file_id}")
  21.             # print(f"Media file name: {media.name}")
  22.             # print(f"File Size: {media.size} bytes")
  23.             # print(f"Type of uploaded media: {type(media)}")
  24.             await client(functions.stories.SendStoryRequest(
  25.                 peer='me',
  26.                 media=types.InputMediaUploadedPhoto(file=media),
  27.                 caption=f"{caption}",
  28.                 privacy_rules=[types.InputPrivacyValueAllowAll()],
  29.                 random_id=random.randint(1, 2**63 - 1),
  30.                 period=86400
  31.             ))
Advertisement
Add Comment
Please, Sign In to add comment