Co-authored-by: Aditya <me@xditya.me> Co-authored-by: Danish <danish@ultroid.tech> Co-authored-by: Amit Sharma <48654350+buddhhu@users.noreply.github.com> Co-authored-by: sppidy <sppidy@users.noreply.github.com> Co-authored-by: Arnab Paryali <Arnabxd@users.noreply.github.com> Co-authored-by: divkix <divkix@users.noreply.github.com> Co-authored-by: hellboi_atul <hellboi-atul@users.noreply.github.com> Co-authored-by: Programming Error <error@notavailable.live> Co-authored-by: New-dev0 <New-dev0@users.noreply.github.com>
182 lines
5.3 KiB
Python
182 lines
5.3 KiB
Python
# Ultroid - UserBot
|
|
# Copyright (C) 2021 TeamUltroid
|
|
#
|
|
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
|
# PLease read the GNU Affero General Public License in
|
|
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
|
|
|
"""
|
|
✘ Commands Available -
|
|
|
|
• `{i}bash <cmds>`
|
|
Run linux commands on telegram.
|
|
|
|
• `{i}eval <cmds>`
|
|
Evaluate python commands on telegram.
|
|
Shortcuts:
|
|
client = bot = event.client
|
|
e = event
|
|
p = print
|
|
reply = await event.get_reply_message()
|
|
chat = event.chat_id
|
|
|
|
• `{i}sysinfo`
|
|
Shows System Info.
|
|
"""
|
|
import io
|
|
import sys
|
|
import traceback
|
|
from os import remove
|
|
|
|
from carbonnow import Carbon
|
|
|
|
from . import *
|
|
|
|
|
|
@ultroid_cmd(
|
|
pattern="sysinfo$",
|
|
)
|
|
async def _(e):
|
|
xx = await eor(e, "`Sending...`")
|
|
x, y = await bash("neofetch|sed 's/\x1B\\[[0-9;\\?]*[a-zA-Z]//g' >> neo.txt")
|
|
with open("neo.txt", "r") as neo:
|
|
p = (neo.read()).replace("\n\n", "")
|
|
ok = Carbon(base_url="https://carbonara.vercel.app/api/cook", code=p)
|
|
haa = await ok.save("neofetch")
|
|
await e.client.send_file(e.chat_id, haa)
|
|
await xx.delete()
|
|
remove("neofetch.jpg")
|
|
remove("neo.txt")
|
|
|
|
|
|
@ultroid_cmd(
|
|
pattern="bash",
|
|
)
|
|
async def _(event):
|
|
if not event.out and not is_fullsudo(event.sender_id):
|
|
return await eor(event, "`This Command Is Sudo Restricted.`")
|
|
if Redis("I_DEV") != "True":
|
|
await eor(
|
|
event,
|
|
f"Developer Restricted!\nIf you know what this does, and want to proceed\n\n `{HNDLR}setredis I_DEV True`\n\nThis Might Be Dangerous.",
|
|
)
|
|
return
|
|
xx = await eor(event, "`Processing...`")
|
|
try:
|
|
cmd = event.text.split(" ", maxsplit=1)[1]
|
|
except IndexError:
|
|
return await eod(xx, "`No cmd given`", time=10)
|
|
reply_to_id = event.message.id
|
|
if event.reply_to_msg_id:
|
|
reply_to_id = event.reply_to_msg_id
|
|
stdout, stderr = await bash(cmd)
|
|
OUT = f"**☞ BASH\n\n• COMMAND:**\n`{cmd}` \n\n"
|
|
if stderr:
|
|
OUT += f"**• ERROR:** \n`{stderr}`\n\n"
|
|
if stdout:
|
|
_o = stdout.split("\n")
|
|
o = "\n".join(_o)
|
|
OUT += f"**• OUTPUT:**\n`{o}`"
|
|
if not stderr and not stdout:
|
|
OUT += f"**• OUTPUT:**\n`Success`"
|
|
if len(OUT) > 4096:
|
|
ultd = OUT.replace("`", "").replace("*", "").replace("_", "")
|
|
with io.BytesIO(str.encode(ultd)) as out_file:
|
|
out_file.name = "bash.txt"
|
|
await event.client.send_file(
|
|
event.chat_id,
|
|
out_file,
|
|
force_document=True,
|
|
thumb="resources/extras/ultroid.jpg",
|
|
allow_cache=False,
|
|
caption=f"`{cmd}`",
|
|
reply_to=reply_to_id,
|
|
)
|
|
await xx.delete()
|
|
else:
|
|
await xx.edit(OUT)
|
|
|
|
|
|
p = print # ignore: pylint
|
|
|
|
|
|
@ultroid_cmd(
|
|
pattern="eval",
|
|
)
|
|
async def _(event):
|
|
if len(event.text) > 5:
|
|
if not event.text[5] == " ":
|
|
return
|
|
if not event.out and not is_fullsudo(event.sender_id):
|
|
return await eor(event, "`This Command Is Sudo Restricted.`")
|
|
if Redis("I_DEV") != "True":
|
|
await eor(
|
|
event,
|
|
f"Developer Restricted!\nIf you know what this does, and want to proceed\n\n {HNDLR}setredis I_DEV True\n\nThis Might Be Dangerous.",
|
|
)
|
|
return
|
|
xx = await eor(event, "`Processing ...`")
|
|
try:
|
|
cmd = event.text.split(" ", maxsplit=1)[1]
|
|
except IndexError:
|
|
return await eod(xx, "`Give some python cmd`", time=5)
|
|
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
|
|
reply_to_id = event.message.id
|
|
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 = (
|
|
"__►__ **EVALPy**\n```{}``` \n\n __►__ **OUTPUT**: \n```{}``` \n".format(
|
|
cmd,
|
|
evaluation,
|
|
)
|
|
)
|
|
if len(final_output) > 4096:
|
|
ultd = final_output.replace("`", "").replace("*", "").replace("_", "")
|
|
with io.BytesIO(str.encode(ultd)) as out_file:
|
|
out_file.name = "eval.txt"
|
|
await ultroid_bot.send_file(
|
|
event.chat_id,
|
|
out_file,
|
|
force_document=True,
|
|
thumb="resources/extras/ultroid.jpg",
|
|
allow_cache=False,
|
|
caption=f"```{cmd}```",
|
|
reply_to=reply_to_id,
|
|
)
|
|
await xx.delete()
|
|
else:
|
|
await xx.edit(final_output)
|
|
|
|
|
|
async def aexec(code, event):
|
|
exec(
|
|
f"async def __aexec(e, client): "
|
|
+ "\n message = event = e"
|
|
+ "\n reply = await event.get_reply_message()"
|
|
+ "\n chat = e.chat_id"
|
|
+ "".join(f"\n {l}" for l in code.split("\n")),
|
|
)
|
|
|
|
return await locals()["__aexec"](event, event.client)
|