This repository has been archived on 2023-04-13. You can view files and clone it, but cannot push or open issues or pull requests.
CloudBot/plugins/pyexec.py

24 lines
525 B
Python
Raw Normal View History

2011-11-20 10:23:31 +01:00
import re
from util import hook, http
re_lineends = re.compile(r'[\r\n]*')
@hook.command
def python(inp):
2012-05-16 05:07:27 +02:00
"python <prog> -- Executes <prog> as Python code."
2011-11-20 10:23:31 +01:00
inp = inp.replace("~n", "\n")
res = http.get("http://eval.appspot.com/eval", statement=inp).splitlines()
if len(res) == 0:
return
res[0] = re_lineends.split(res[0])[0]
if not res[0] == 'Traceback (most recent call last):':
return res[0].decode('utf8', 'ignore')
else:
return res[-1].decode('utf8', 'ignore')