-
Notifications
You must be signed in to change notification settings - Fork 13
Conversation
Hi. Add yourself in the readme |
plugins/eval/eval.py
Outdated
eval_running_text = "**Eval Code:**\n```{code}```\n**Running...**" | ||
eval_success_text = "**Eval Code:**\n```{code}```\n**Success**" | ||
eval_error_text = "**Eval Code:**\n```{code}```\n**Error:**\n```{error}```" | ||
eval_result_text = "**Eval Code:**\n```{code}```\n**Result:**\n```{result}```" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like these to be UPPER_CASE
plugins/eval/eval.py
Outdated
def evalcode(client, message): | ||
code = " ".join(message.command[1:]) | ||
if code: | ||
m = client.send_message(message.chat.id, eval_running_text.replace('{code}', code), parse_mode="MARKDOWN") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use replace, use format instead.
Also, you could just use message.reply here
plugins/eval/eval.py
Outdated
else: | ||
client.edit_message_text(message.chat.id, m.message_id, | ||
eval_success_text.replace('{code}', code), | ||
parse_mode="MARKDOWN") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Markdown is enabled by default, there's no need for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are quite a few fixes needed to make this plugin nicer. Here's how I suggest it to be instead (there's still some redundant code because of message.edit() not being available (yet), but we can add it later):
from pyrogram import Client, Filters
RUNNING = "**Eval Code:**\n```{}```\n**Running...**"
ERROR = "**Eval Code:**\n```{}```\n**Error:**\n```{}```"
SUCCESS = "**Eval Code:**\n```{}```\n**Success**"
RESULT = "**Eval Code:**\n```{}```\n**Result:**\n```{}```"
@Client.on_message(Filters.command("eval", prefix="!"))
def eval_code(client, message):
code = " ".join(message.command[1:])
if code:
m = message.reply(RUNNING.format(code))
try:
result = eval(code)
except Exception as error:
client.edit_message_text(
m.chat.id,
m.message_id,
ERROR.format(code, error)
)
else:
if result is None:
client.edit_message_text(
m.chat.id,
m.message_id,
SUCCESS.format(code)
)
else:
client.edit_message_text(
m.chat.id,
m.message_id,
RESULT.format(code, result)
)
And here's how the plugin will look like as soon as from pyrogram import Client, Filters
RUNNING = "**Eval Code:**\n```{}```\n**Running...**"
ERROR = "**Eval Code:**\n```{}```\n**Error:**\n```{}```"
SUCCESS = "**Eval Code:**\n```{}```\n**Success**"
RESULT = "**Eval Code:**\n```{}```\n**Result:**\n```{}```"
@Client.on_message(Filters.command("eval", prefix="!"))
def eval_code(client, message):
code = " ".join(message.command[1:])
if code:
reply = message.reply(RUNNING.format(code))
try:
result = eval(code)
except Exception as error:
reply.edit(ERROR.format(code, error))
else:
if result is None:
reply.edit(SUCCESS.format(code))
else:
reply.edit(RESULT.format(code, result)) |
Wow |
No description provided.