Skip to content

Commit

Permalink
Add .telepaste in telegraph.py to paste text content into telegraph (U…
Browse files Browse the repository at this point in the history
…sergeTeam#298)

* Add  .telepaste in telegraph.py to paste text content into telegraph

* Fixed typo

* Fixed no inpute error

* Fixed typo error

* merged .telepaste into .telegraph

* disable_web_page_preview=True

* nothing....🙈

* new method + removed unwanted codes😅

* fixed pep8

* disable_web_page_preview=True

* fixed blocking main thread

Co-authored-by: rking32 <[email protected]>
  • Loading branch information
jigarvarma2k20 and rking32 authored Apr 10, 2021
1 parent 619b426 commit 177647a
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions userge/plugins/utils/telegraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import os
from PIL import Image
from telegraph import upload_file

from userge import userge, Message, Config
from userge.utils import post_to_telegraph
from userge import userge, Message, Config, pool
from userge.utils import progress

_T_LIMIT = 5242880
Expand All @@ -19,24 +19,39 @@
@userge.on_cmd("telegraph", about={
'header': "Upload file to Telegra.ph's servers",
'types': ['.jpg', '.jpeg', '.png', '.gif', '.mp4', '.webp'],
'usage': "reply {tr}telegraph to supported media : limit 5MB"})
'usage': "reply {tr}telegraph to media or text : limit 5MB for media",
'examples': "reply {tr}telegraph to `header|content`\n(You can use html code)"})
async def telegraph_(message: Message):
replied = message.reply_to_message
if not replied:
await message.err("reply to supported media")
await message.err("reply to media or text")
return
if not ((replied.photo and replied.photo.file_size <= _T_LIMIT)
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.text)
or (replied.document
and replied.document.file_name.endswith(
('.jpg', '.jpeg', '.png', '.gif', '.mp4'))
and replied.document.file_size <= _T_LIMIT)):
await message.err("not supported!")
return
await message.edit("`processing...`")
if replied.text:
content = message.reply_to_message.text
if "|" in content:
content = content.split("|", maxsplit=1)
header = content[0]
text = content[1]
else:
text = content
header = "Pasted content by @theuserge"
t_url = await pool.run_in_thread(post_to_telegraph)(header, text)
jv_text = f"**[Here Your Telegra.ph Link!]({t_url})**"
await message.edit(text=jv_text, disable_web_page_preview=True)
return
dl_loc = await message.client.download_media(
message=message.reply_to_message,
file_name=Config.DOWN_PATH,
Expand Down

0 comments on commit 177647a

Please sign in to comment.