forked from xditya/TeleBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |