Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Copyright (C) 2019 The Raphielscape Company LLC.
- #
- # Licensed under the Raphielscape Public License, Version 1.b (the "License");
- # you may not use this file except in compliance with the License.
- #
- """ Userbot module for changing your Telegram profile details. """
- import os
- from telethon.errors import ImageProcessFailedError, PhotoCropSizeSmallError
- from telethon.errors.rpcerrorlist import UsernameOccupiedError, PhotoExtInvalidError
- from telethon.tl.functions.account import (UpdateProfileRequest,
- UpdateUsernameRequest)
- from telethon.tl.functions.photos import (UploadProfilePhotoRequest,
- DeletePhotosRequest, GetUserPhotosRequest)
- from telethon.tl.types import MessageMediaPhoto, InputPhoto
- from userbot import bot, HELPER
- from userbot.events import register
- # ====================== CONSTANT ===============================
- INVALID_MEDIA = "```L'estensione dell'immagine è invalida.```"
- PP_CHANGED = "```Immagine cambiata. ✅```"
- PP_TOO_SMOL = "```Quest immagine è troppo piccola, usa un immagine più grande.```"
- PP_ERROR = "```Failure occured while processing image.```"
- BIO_SUCCESS = "```Bio cambiata!.```"
- NAME_OK = "```Il tuo nome è stato cambiato ✅.```"
- USERNAME_SUCCESS = "```Il tuo username è stato cambiato ✅.```"
- USERNAME_TAKEN = "```Quest username già è stato preso ❌.```"
- #===============================================================
- @register(outgoing=True, pattern="^.profilepic$")
- async def set_profilepic(propic):
- """ For .profilepic command, change your profile picture in Telegram. """
- if not propic.text[0].isalpha() and propic.text[0] not in ("/", "#", "@", "!"):
- replymsg = await propic.get_reply_message()
- photo = None
- if replymsg.media:
- if isinstance(replymsg.media, MessageMediaPhoto):
- photo = await bot.download_media(message=replymsg.photo)
- elif "image" in replymsg.media.document.mime_type.split('/'):
- photo = await bot.download_file(replymsg.media.document)
- else:
- await propic.edit(INVALID_MEDIA)
- if photo:
- try:
- await bot(UploadProfilePhotoRequest(
- await bot.upload_file(photo)
- ))
- os.remove(photo)
- await propic.edit(PP_CHANGED)
- except PhotoCropSizeSmallError:
- await propic.edit(PP_TOO_SMOL)
- except ImageProcessFailedError:
- await propic.edit(PP_ERROR)
- except PhotoExtInvalidError:
- await propic.edit(INVALID_MEDIA)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement