forked from UsergeTeam/Userge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
229 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from .utils import logging | ||
from .utils import Config, logging | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import io | ||
import os | ||
import sys | ||
import traceback | ||
from pyrogram import Message | ||
from userge import userge, Config | ||
|
||
log = userge.getLogger(__name__) | ||
|
||
|
||
@userge.on_cmd("eval") | ||
async def eval_(_, message: Message): | ||
await message.edit("Processing ...") | ||
cmd = message.text.split(" ", maxsplit=1)[1] | ||
reply_to_id = message.message_id | ||
|
||
if message.reply_to_message: | ||
reply_to_id = message.reply_to_message.message_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, userge, message) | ||
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.strip()) | ||
|
||
if len(final_output) > Config.MAX_MESSAGE_LENGTH: | ||
with open("eval.text", "w+", encoding="utf8") as out_file: | ||
out_file.write(str(final_output)) | ||
|
||
await userge.send_document( | ||
chat_id=message.chat.id, | ||
document="eval.text", | ||
caption=cmd, | ||
disable_notification=True, | ||
reply_to_message_id=reply_to_id | ||
) | ||
|
||
os.remove("eval.text") | ||
await message.delete() | ||
|
||
else: | ||
await message.edit(final_output) | ||
|
||
|
||
async def aexec(code, userge, message): | ||
exec( | ||
f'async def __aexec(userge, message): ' + | ||
''.join(f'\n {l}' for l in code.split('\n')) | ||
) | ||
return await locals()['__aexec'](userge, message) | ||
|
||
|
||
userge.add_help( | ||
command="eval", | ||
about="run eval" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import asyncio | ||
import os | ||
import time | ||
from pyrogram import Message | ||
from userge import userge, Config | ||
|
||
log = userge.getLogger(__name__) | ||
|
||
|
||
@userge.on_cmd("exec") | ||
async def exec_(_, message: Message): | ||
cmd = message.text.split(" ", maxsplit=1)[1] | ||
reply_to_id = message.message_id | ||
|
||
if message.reply_to_message: | ||
reply_to_id = message.reply_to_message.message_id | ||
|
||
process = await asyncio.create_subprocess_shell( | ||
cmd, | ||
stdout=asyncio.subprocess.PIPE, | ||
stderr=asyncio.subprocess.PIPE | ||
) | ||
stdout, stderr = await process.communicate() | ||
|
||
e = stderr.decode() or "No Error" | ||
o = stdout.decode() | ||
|
||
if o: | ||
_o = o.split("\n") | ||
o = "`\n".join(_o) | ||
else: | ||
o = "**Tip**: \n`If you want to see the results of your code, I suggest printing them to stdout.`" | ||
|
||
OUTPUT = f"**QUERY:**\n__Command:__\n`{cmd}` \n__PID:__\n`{process.pid}`\n\n**stderr:** \n`{e}`\n**Output:**\n{o}" | ||
|
||
if len(OUTPUT) > Config.MAX_MESSAGE_LENGTH: | ||
with open("exec.text", "w+", encoding="utf8") as out_file: | ||
out_file.write(str(OUTPUT)) | ||
|
||
await userge.send_document( | ||
chat_id=message.chat.id, | ||
document="exec.text", | ||
caption=cmd, | ||
disable_notification=True, | ||
reply_to_message_id=reply_to_id | ||
) | ||
|
||
os.remove("exec.text") | ||
await message.delete() | ||
|
||
else: | ||
await message.edit(OUTPUT) | ||
|
||
|
||
userge.add_help( | ||
command="exec", | ||
about="run exec" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import os | ||
from pyrogram import Message | ||
from userge import userge | ||
|
||
log = userge.getLogger(__name__) | ||
|
||
|
||
@userge.on_cmd("json") | ||
async def jsonify(_, message: Message): | ||
the_real_message = None | ||
reply_to_id = None | ||
|
||
if message.reply_to_message: | ||
reply_to_id = message.reply_to_message.message_id | ||
the_real_message = message.reply_to_message | ||
else: | ||
the_real_message = message | ||
reply_to_id = message.message_id | ||
|
||
try: | ||
await message.edit(the_real_message) | ||
except Exception as e: | ||
with open("json.text", "w+", encoding="utf8") as out_file: | ||
out_file.write(str(the_real_message)) | ||
await userge.send_document( | ||
chat_id=message.chat.id, | ||
document="json.text", | ||
caption=str(e), | ||
disable_notification=True, | ||
reply_to_message_id=reply_to_id | ||
) | ||
os.remove("json.text") | ||
await message.delete() | ||
|
||
|
||
userge.add_help( | ||
command="json", | ||
about="replied msg to json" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import os | ||
from pyrogram import Message | ||
from userge import userge | ||
|
||
log = userge.getLogger(__name__) | ||
|
||
|
||
@userge.on_cmd("whois") | ||
async def who_is(_, message: Message): | ||
from_user = None | ||
if " " in message.text: | ||
recvd_command, user_id = message.text.split(" ") | ||
try: | ||
user_id = int(user_id) | ||
from_user = await userge.get_users(user_id) | ||
except Exception as e: | ||
await message.edit(str(e)) | ||
return | ||
elif message.reply_to_message: | ||
from_user = message.reply_to_message.from_user | ||
else: | ||
await message.edit("no valid user_id / message specified") | ||
return | ||
if from_user is not None: | ||
message_out_str = "" | ||
message_out_str += f"ID: `{from_user.id}`\n" | ||
message_out_str += f"First Name: <a href='tg://user?id={from_user.id}'>{from_user.first_name}</a>\n" | ||
message_out_str += f"Last Name: {from_user.last_name}" | ||
chat_photo = from_user.photo | ||
local_user_photo = await userge.download_media( | ||
message=chat_photo.big_file_id | ||
) | ||
await message.reply_photo( | ||
photo=local_user_photo, | ||
quote=True, | ||
caption=message_out_str, | ||
parse_mode="html", | ||
# ttl_seconds=, | ||
disable_notification=True | ||
) | ||
os.remove(local_user_photo) | ||
await message.delete() | ||
|
||
|
||
userge.add_help( | ||
command="whois", | ||
about="to get user details" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters