text: """Evaluate Python Code inside Telegram
  Syntax: .eval PythonCode"""
  # This Source Code Form is subject to the terms of the Mozilla Public
  # License, v. 2.0. If a copy of the MPL was not distributed with this
  # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  
  import asyncio
  import inspect
  import io
  import sys
  import traceback
  
  from telethon import errors, events, functions, types
  
  from uniborg.util import admin_cmd
  
  from sample_config import Config
  
  
  @borg.on(admin_cmd(pattern="eval"))
  async def _(event):
      if event.fwd_from or event.via_bot_id:
          return
      await event.edit("Processing ...")
      cmd = event.text.split(" ", maxsplit=1)[1]
      reply_to_id = event.message.id
      if event.reply_to_msg_id:
          reply_to_id = event.reply_to_msg_id
  
      old_stderr = sys.stderr
      old_stdout = sys.stdout
      redirected_output = sys.stdout = io.StringIO()
      redirected_error = sys.stderr = io.StringIO()
      stdout, stderr, exc = None, None, None
  
      try:
          await aexec(cmd, event)
      except Exception:
          exc = traceback.format_exc()
  
      stdout = redirected_output.getvalue()
      stderr = redirected_error.getvalue()
      sys.stdout = old_stdout
      sys.stderr = old_stderr
  
      evaluation = ""
      if exc:
          evaluation = exc
      elif stderr:
          evaluation = stderr
      elif stdout:
          evaluation = stdout
      else:
          evaluation = "Success"
  
      final_output = "**EVAL**: `{}` \n\n **OUTPUT**: \n`{}` \n".format(cmd, evaluation)
  
      if len(final_output) > Config.MAX_MESSAGE_SIZE_LIMIT:
          with io.BytesIO(str.encode(final_output)) as out_file:
              out_file.name = "eval.text"
              await borg.send_file(
                  event.chat_id,
                  out_file,
                  force_document=True,
                  allow_cache=False,
                  caption=cmd,
                  reply_to=reply_to_id
              )
              await event.delete()
      else:
          await event.edit(final_output)
  
  
  async def aexec(code, event):
      exec(
          f'async def __aexec(event): ' +
          ''.join(f'\n {l}' for l in code.split('\n'))
      )
      return await locals()['__aexec'](event)
  