Skip to content
This repository has been archived by the owner on May 15, 2021. It is now read-only.

Commit

Permalink
improved no format
Browse files Browse the repository at this point in the history
  • Loading branch information
code-rgb committed Nov 22, 2020
1 parent 8001fad commit 082cb58
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions userge/plugins/bot/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,31 +134,41 @@ async def down_image(message):
about={
"header": "decompile a message",
"description": "reply to a message to get it without any text formatting",
"flags": {"-alt": "for MissRose bot supported format"},
},
)
async def noformat_message(message: Message):
reply = message.reply_to_message
msg_text = None
medias = None
buttons = ""
medias = get_file_id_and_ref(reply)
if reply.text:
msg_text = reply.text.html
elif reply.media:
medias = get_file_id_and_ref(reply)
elif medias[0]:
msg_text = reply.caption.html if reply.caption else None
else:
return await message.err("reply to valid message", del_in=5)
return await message.err("Now Supported!, reply to a supported media type or text", del_in=5)

if '-alt' in message.flags:
lbr_ = '('
rbr_ = ')'
else:
lbr_ = '['
rbr_ = ']'

if reply.reply_markup:
for row in reply.reply_markup.inline_keyboard:
firstbtn = True
for btn in row:
if btn.url:
if firstbtn:
buttons += f"[{btn.text}][buttonurl:{btn.url}]"
buttons += f"[{btn.text}]{lbr_}buttonurl:{btn.url}{rbr_}"
firstbtn = False
else:
buttons += f"[{btn.text}][buttonurl:{btn.url}:same]"
if medias:
buttons += f"[{btn.text}]{lbr_}buttonurl:{btn.url}:same{rbr_}"

if medias[0]:
await message.delete()
await message.client.send_cached_media(
chat_id=message.chat.id,
file_id=medias[0],
Expand All @@ -168,4 +178,4 @@ async def noformat_message(message: Message):
parse_mode=None,
)
else:
await message.reply(f"{msg_text}{buttons}", parse_mode=None)
await message.edit(f"{msg_text}{buttons}", parse_mode=None)

0 comments on commit 082cb58

Please sign in to comment.