Skip to content

Commit

Permalink
Create account_profile.py
Browse files Browse the repository at this point in the history
  • Loading branch information
xditya authored May 21, 2020
1 parent 060a4bc commit edcb9ce
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions userbot/plugins/account_profile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""COMMAND : .pbio, .ppic, .pname"""

import os
from telethon import events
from telethon.tl import functions
from userbot.utils import admin_cmd


@borg.on(admin_cmd("pbio (.*)")) # pylint:disable=E0602
async def _(event):
if event.fwd_from:
return
bio = event.pattern_match.group(1)
try:
await borg(functions.account.UpdateProfileRequest( # pylint:disable=E0602
about=bio
))
await event.edit("Succesfully changed my profile bio")
except Exception as e: # pylint:disable=C0103,W0703
await event.edit(str(e))


@borg.on(admin_cmd("pname ((.|\n)*)")) # pylint:disable=E0602,W0703
async def _(event):
if event.fwd_from:
return
names = event.pattern_match.group(1)
first_name = names
last_name = ""
if "\\n" in names:
first_name, last_name = names.split("\\n", 1)
try:
await borg(functions.account.UpdateProfileRequest( # pylint:disable=E0602
first_name=first_name,
last_name=last_name
))
await event.edit("My name was changed successfully")
except Exception as e: # pylint:disable=C0103,W0703
await event.edit(str(e))


@borg.on(admin_cmd("ppic")) # pylint:disable=E0602
async def _(event):
if event.fwd_from:
return
reply_message = await event.get_reply_message()
await event.edit("Downloading Profile Picture to my local ...")
if not os.path.isdir(Config.TMP_DOWNLOAD_DIRECTORY): # pylint:disable=E0602
os.makedirs(Config.TMP_DOWNLOAD_DIRECTORY) # pylint:disable=E0602
photo = None
try:
photo = await borg.download_media( # pylint:disable=E0602
reply_message,
Config.TMP_DOWNLOAD_DIRECTORY # pylint:disable=E0602
)
except Exception as e: # pylint:disable=C0103,W0703
await event.edit(str(e))
else:
if photo:
await event.edit("now, Uploading to @Telegram ...")
file = await borg.upload_file(photo) # pylint:disable=E0602
try:
await borg(functions.photos.UploadProfilePhotoRequest( # pylint:disable=E0602
file
))
except Exception as e: # pylint:disable=C0103,W0703
await event.edit(str(e))
else:
await event.edit("My profile picture was succesfully changed")
try:
os.remove(photo)
except Exception as e: # pylint:disable=C0103,W0703
logger.warn(str(e)) # pylint:disable=E0602

0 comments on commit edcb9ce

Please sign in to comment.