8000 added eval plugin · pyrogram/plugins@98cc90a · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Dec 22, 2021. It is now read-only.

Commit 98cc90a

Browse files
committed
added eval plugin
1 parent 1572c0b commit 98cc90a

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

plugins/eval/eval.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# MIT License
2+
#
3+
# Copyright (c) 2018 Furoin <https://github.com/furoin>
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
from pyrogram import Client, Filters
24+
25+
eval_running_text = "**Eval Code:**\n```{code}```\n**Running...**"
26+
eval_success_text = "**Eval Code:**\n```{code}```\n**Success**"
27+
eval_error_text = "**Eval Code:**\n```{code}```\n**Error:**\n```{error}```"
28+
eval_result_text = "**Eval Code:**\n```{code}```\n**Result:**\n```{result}```"
29+
30+
31+
@Client.on_message(Filters.command("eval", prefix="!"))
32+
def evalcode(client, message):
33+
code = " ".join(message.command[1:])
34+
if code:
35+
m = client.send_message(message.chat.id, eval_running_text.replace('{code}', code), parse_mode="MARKDOWN")
36+
try:
37+
result = eval(code)
38+
39+
except Exception as e:
40+
client.edit_message_text(message.chat.id, m.message_id,
41+
eval_error_text.replace('{code}', code).replace('{error}', str(e)),
42+
parse_mode="MARKDOWN")
43+
else:
44+
if result:
45+
client.edit_message_text(message.chat.id, m.message_id,
46+
eval_result_text.replace('{code}', code).replace('{result}', str(result)),
47+
parse_mode="MARKDOWN")
48+
49+
else:
50+
client.edit_message_text(message.chat.id, m.message_id,
51+
eval_success_text.replace('{code}', code),
52+
parse_mode="MARKDOWN")

0 commit comments

Comments
 (0)
0