Skip to content

Commit

Permalink
Added telegram sticker support in telegraph.py (#295)
Browse files Browse the repository at this point in the history
* Added telegram sticker support in telegraph.py

* Change img save location
  • Loading branch information
Jigarvarma2005 committed Apr 3, 2021
1 parent bcbe185 commit edd90c2
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions userge/plugins/utils/telegraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# All rights reserved.

import os

from PIL import Image
from telegraph import upload_file

from userge import userge, Message, Config
Expand All @@ -18,7 +18,7 @@

@userge.on_cmd("telegraph", about={
'header': "Upload file to Telegra.ph's servers",
'types': ['.jpg', '.jpeg', '.png', '.gif', '.mp4'],
'types': ['.jpg', '.jpeg', '.png', '.gif', '.mp4', '.webp'],
'usage': "reply {tr}telegraph to supported media : limit 5MB"})
async def telegraph_(message: Message):
replied = message.reply_to_message
Expand All @@ -29,6 +29,7 @@ async def telegraph_(message: Message):
or (replied.animation and replied.animation.file_size <= _T_LIMIT)
or (replied.video and replied.video.file_name.endswith('.mp4')
and replied.video.file_size <= _T_LIMIT)
or (replied.sticker)
or (replied.document
and replied.document.file_name.endswith(
('.jpg', '.jpeg', '.png', '.gif', '.mp4'))
Expand All @@ -42,6 +43,11 @@ async def telegraph_(message: Message):
progress=progress,
progress_args=(message, "trying to download")
)
if replied.sticker:
img = Image.open(dl_loc).convert('RGB')
img.save(f'{Config.DOWN_PATH}/userge.png', 'png')
os.remove(dl_loc)
dl_loc = f'{Config.DOWN_PATH}/userge.png'
await message.edit("`uploading to telegraph...`")
try:
response = upload_file(dl_loc)
Expand Down

0 comments on commit edd90c2

Please sign in to comment.