SHARE
TWEET

Untitled

a guest Feb 16th, 2020 105 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Copyright (C) 2019 The Raphielscape Company LLC.
  2. #
  3. # Licensed under the Raphielscape Public License, Version 1.b (the "License");
  4. # you may not use this file except in compliance with the License.
  5. #
  6. """ Userbot module for changing your Telegram profile details. """
  7.  
  8. import os
  9. from telethon.errors import ImageProcessFailedError, PhotoCropSizeSmallError
  10. from telethon.errors.rpcerrorlist import UsernameOccupiedError, PhotoExtInvalidError
  11. from telethon.tl.functions.account import (UpdateProfileRequest,
  12.                                            UpdateUsernameRequest)
  13. from telethon.tl.functions.photos import (UploadProfilePhotoRequest,
  14.                                           DeletePhotosRequest, GetUserPhotosRequest)
  15. from telethon.tl.types import MessageMediaPhoto, InputPhoto
  16.  
  17. from userbot import bot, HELPER
  18. from userbot.events import register
  19.  
  20.  
  21. # ====================== CONSTANT ===============================
  22. INVALID_MEDIA = "```L'estensione dell'immagine è invalida.```"
  23. PP_CHANGED = "```Immagine cambiata. ✅```"
  24. PP_TOO_SMOL = "```Quest immagine è troppo piccola, usa un immagine più grande.```"
  25. PP_ERROR = "```Failure occured while processing image.```"
  26.  
  27. BIO_SUCCESS = "```Bio cambiata!.```"
  28.  
  29. NAME_OK = "```Il tuo nome è stato cambiato ✅.```"
  30. USERNAME_SUCCESS = "```Il tuo username è stato cambiato ✅.```"
  31. USERNAME_TAKEN = "```Quest username già è stato preso ❌.```"
  32. #===============================================================
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44. @register(outgoing=True, pattern="^.profilepic$")
  45. async def set_profilepic(propic):
  46.     """ For .profilepic command, change your profile picture in Telegram. """
  47.     if not propic.text[0].isalpha() and propic.text[0] not in ("/", "#", "@", "!"):
  48.         replymsg = await propic.get_reply_message()
  49.         photo = None
  50.         if replymsg.media:
  51.             if isinstance(replymsg.media, MessageMediaPhoto):
  52.                 photo = await bot.download_media(message=replymsg.photo)
  53.             elif "image" in replymsg.media.document.mime_type.split('/'):
  54.                 photo = await bot.download_file(replymsg.media.document)
  55.             else:
  56.                 await propic.edit(INVALID_MEDIA)
  57.  
  58.         if photo:
  59.             try:
  60.                 await bot(UploadProfilePhotoRequest(
  61.                     await bot.upload_file(photo)
  62.                     ))
  63.                 os.remove(photo)
  64.                 await propic.edit(PP_CHANGED)
  65.             except PhotoCropSizeSmallError:
  66.                 await propic.edit(PP_TOO_SMOL)
  67.             except ImageProcessFailedError:
  68.                 await propic.edit(PP_ERROR)
  69.             except PhotoExtInvalidError:
  70.                 await propic.edit(INVALID_MEDIA)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top