Skip to content

Commit

Permalink
Add '.txt', '.html' support for telegraph paste (UsergeTeam#301)
Browse files Browse the repository at this point in the history
* Add '.txt', '.html' support for telegraph paste

* Pep8

* Added '.py' support🤫

* header mothod changrd for file paste

* Remove unwanted code🤫🤐
  • Loading branch information
jigarvarma2k20 authored Apr 23, 2021
1 parent 216cbf8 commit 1c4d1af
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions userge/plugins/utils/telegraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

@userge.on_cmd("telegraph", about={
'header': "Upload file to Telegra.ph's servers",
'types': ['.jpg', '.jpeg', '.png', '.gif', '.mp4', '.webp'],
'types': ['.jpg', '.jpeg', '.png', '.gif', '.mp4', '.webp', '.html', '.txt', '.py'],
'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):
Expand All @@ -34,20 +34,37 @@ async def telegraph_(message: Message):
or (replied.text)
or (replied.document
and replied.document.file_name.endswith(
('.jpg', '.jpeg', '.png', '.gif', '.mp4'))
('.jpg', '.jpeg', '.png', '.gif', '.mp4', '.html', '.txt', '.py'))
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]
if ((replied.text)
or (replied.document
and replied.document.file_name.endswith(
('.html', '.txt', '.py')))):
if replied.document:
dl_loc = await message.client.download_media(
message=message.reply_to_message,
file_name=Config.DOWN_PATH,
progress=progress,
progress_args=(message, "trying to download")
)
with open(dl_loc, "r") as jv:
text = jv.read()
header = message.input_str
if not header:
header = "Pasted content by @theuserge"
os.remove(dl_loc)
else:
text = content
header = "Pasted content by @theuserge"
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)
Expand Down

0 comments on commit 1c4d1af

Please sign in to comment.