Skip to content

Commit

Permalink
added rextester
Browse files Browse the repository at this point in the history
  • Loading branch information
xditya committed Jan 11, 2021
1 parent c7155ca commit 87208b6
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pytz
qrcode
regex
requests>=2.18.4
rextester_py
search-engine-parser>=0.4.2
selenium
spamwatch
Expand Down
58 changes: 58 additions & 0 deletions telebot/plugins/rextester.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# TeleBot - UserBot
# Copyright (C) 2020 TeleBot

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.

# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

# by @its_xditya

from rextester_py import rexec
from . import CMD_HELP

@telebot.on(admin_cmd(pattern="rex"))
async def _(event):
if event.fwd_from:
return
await event.edit("Processing ...")
evtxt = event.text.split(" ", maxsplit=1)[1]
try:
lang = evtxt.split("//", maxsplit=1)[0]
cmd = evtxt.split("//", maxsplit=1)[1]
except:
return await event.edit(f"Syntax - \n`{Var.CMD_HNDLR}rex language//code`\nLanguages can be found [here](https://github.com/nitanmarcel/rextester_py#languages).")

try:
res = rexec(lang, cmd, None).results
err = rexec(lang, cmd, None).errors
wrns = rexec(lang, cmd, None).warnings
# statt = rexec(lang, cmd, None).stats
except Exception as e:
if str(e) == "Unknown language":
return await event.edit("**ERROR**:\n`Unknown Language!!\nCheck available languages `[here](https://github.com/nitanmarcel/rextester_py#languages)")
return await event.edit(f"**ERROR:**\n`{str(e)}`")
out = f"**- Rextester**\n\n**Language:** `{lang}`\n**Code:** `{cmd}`\n\n**Output:** `{res}`\n\n"
if err is not None:
out += f"**Error:** `{err}`\n\n"
if wrns is not None:
out += f"**Warnings:** `{wrns}`\n\n"
# reducing time taken...
# out += f"**Stats:** `{statt}`"

await event.edit(out)

CMD_HELP.update(
{
"rextester": ".rex <language>//<codes>\
\nUse - Run codes of any language inside telegram. Available languages can be found [here](https://github.com/nitanmarcel/rextester_py#languages)."
}
)

0 comments on commit 87208b6

Please sign in to comment.