def paste_command(c: Client, msg: Message): msg.edit_text("Pasting...") if msg.reply_to_message.document: path = "tmp/{}".format("".join( random.choices(string.ascii_letters, k=30))) msg.reply_to_message.download(file_name=path) try: text = open(path).read() except UnicodeDecodeError: msg.edit_text( "Please reply to a document or a message with some text") return 1 else: text = msg.reply_to_message.text or msg.reply_to_message.caption if not text: msg.edit_text("Please reply to a document or a message with some text") return 1 key = Nekobin.paste(text) msg.edit_text( f"{Emoji.GLOBE_WITH_MERIDIANS} Paste {Emoji.GLOBE_WITH_MERIDIANS}\n" f"\n" f"{Emoji.LINK} Url: https://nekobin.com/{key}\n" f"{Emoji.NEWSPAPER} Raw: https://nekobin.com/raw/{key} \n" f"\n", disable_web_page_preview=True, )
def eval_command(c, msg): if len(msg.command) < 2: msg.edit_text( "Please use: <code>/eval msg.reply(some python code)</code>\nNote: Client = c, Message = msg" ) return 0 code = msg.text.html[len("/eval "):] try: result = eval(code) except Exception as e: result = "".join(traceback.format_exception(e, e, sys.exc_info()[2])) try: if len(code + str(result)) > 2000: msg.edit_text("Uploading to nekobin...") msg.edit_text( "<b>Code:</b>\n{pasted}\n\n<b>Result:</b>\n{pasted}".format( pasted= 'Too long! <a href="https://nekobin.com/{url}">Pasted</a>'. format(url=Nekobin.paste("Code:\n{}\n\nResult:\n{}".format( str(code), str(result)))))) else: msg.edit_text( "<b>Code:</b>\n<code>{}</code>\n\n<b>Result:</b>\n<code>{}</code>" .format(html.escape(str(code)[:1000]), html.escape(str(result)[:2000])), parse_mode="html", ) except Exception as e: msg.edit_text(str(e))
def eval_command(c, msg): # TODO rewrite this mess if len(msg.command) < 2: msg.edit_text( "Please use: <code>/eval msg.reply(some python code)</code>\nNote: Client = c, Message = msg" ) return 0 code = msg.text.markdown[len("/eval "):] old_stdout = sys.stdout redirected_stdout = sys.stdout = io.StringIO() try: eval_result = eval(code) except Exception as e: eval_result = "" tb = "".join(traceback.format_exception( e, e, sys.exc_info()[2])).rstrip("\n ") else: tb = "" sys.stdout = old_stdout stdout_value = redirected_stdout.getvalue().rstrip("\n ") result = stdout_value + ("\n" + tb if tb else "") try: if len(code + str(result)) > 2000: msg.edit_text("Uploading to nekobin...") msg.edit_text( "<b>Code:</b>\n{pasted}\n\n<b>Eval Result:</b>\n{pasted}\n\n<b>Result:</b>\n{pasted}" .format( pasted= 'Too long! <a href="https://nekobin.com/{url}">Pasted</a>'. format(url=Nekobin.paste( "Code:\n{}\n\nEval Result:\n{}\n\nResult:\n{}".format( str(code), str(eval_result), str(result)))))) else: msg.edit_text( "<b>Code:</b>\n<code>{}</code>\n\n<b>Eval Result:</b>\n<code>{}</code>\n\n<b>Result:</b>\n<code>{}</code>" .format(html.escape(str(code)), html.escape(str(eval_result)), html.escape(str(result)))) except Exception as e: msg.edit_text(str(e))
import random import string from pyrogram import Client, Filters, Emoji, Message from main import prefixes from methods.Nekobin import Nekobin Nekobin = Nekobin() @Client.on_message( Filters.user("self") & Filters.command("paste", prefixes=prefixes) & Filters.reply) def paste_command(c: Client, msg: Message): msg.edit_text("Pasting...") if msg.reply_to_message.document: path = "tmp/{}".format("".join( random.choices(string.ascii_letters, k=30))) msg.reply_to_message.download(file_name=path) try: text = open(path).read() except UnicodeDecodeError: msg.edit_text( "Please reply to a document or a message with some text") return 1 else: text = msg.reply_to_message.text or msg.reply_to_message.caption