Files
Ultroid-fork/plugins/evaljs.py
1Danish-00 386eff647c v0.0.9 18/07/2021
Co-authored-by: New-dev0 <New-dev0@users.noreply.github.com>
Co-authored-by: Aditya <me@xditya.me>
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>
2021-07-18 17:47:15 +05:30

80 lines
2.5 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}evaljs <javaScriptCommands>`
Evaluate JavaScript code and upload.
"""
# Inbuilt
import os
import time
from threading import Thread
from . import *
# Ultroid
async def evalJs(
event,
startTime: float,
command: str = "",
):
scriptFile = open(
"./src/ecmaHelper/evalJs.run.js",
"w",
encoding="utf-8",
)
scriptFile.write(str(command))
scriptFile.close()
os.system(f"node ./src/ecmaHelper/eval.d.js")
if os.path.exists("./src/ecmaHelper/evalJs.result.d.txt"):
await event.client.send_file(
event.chat_id,
"./src/ecmaHelper/evalJs.result.d.txt",
force_document=True,
caption=f"**☞ evalJS\n\n• Command:**\n`{command}` \n\n**• TimeTaken:**\n`{time.time() - startTime:.2f}s` \n\n**• Result:**\n`[Info]: Uploaded File For Better Visualisation Of Indents.`",
)
else:
await event.client.send_file(
event.chat_id,
"./src/ecmaHelper/evalJs.result.d.txt",
force_document=True,
caption=f"**☞ evalJS\n\n• Command:**\n`{command}` \n\n**• TimeTaken:**\n`{time.time() - startTime:.2f}` \n\n**• Result:**\n`[Warning]: Unexpected Error Occured !`",
)
await event.delete()
file = open("./src/ecmaHelper/evalJs.result.d.txt", encoding="utf-8", mode="w")
file.write("'use-strict';\n")
file.close()
# The Command Is `.evaljs`
@ultroid_cmd(
pattern="evaljs",
)
async def evaluateJs(event):
start = time.time()
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":
return 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.",
)
xx = await eor(event, "`Running Thread ...`")
try:
cmd = event.text.split(" ", maxsplit=1)[1]
except IndexError:
return await eod(xx, "`Give some JS command`", time=5)
if cmd and cmd != "":
Thread(
target=await evalJs(
xx,
command=cmd,
startTime=start,
)
).start()