# HG changeset patch # User Teemu Piippo # Date 1439032626 -10800 # Node ID 7e225c2659b8e548fb429c0aef6c44f8e44d3439 # Parent 4a72fb181a43fb6683ecd9fa1519ffce8dc0c3aa Added .py diff -r 4a72fb181a43 -r 7e225c2659b8 mod_util.py --- a/mod_util.py Sat Aug 08 14:00:40 2015 +0300 +++ b/mod_util.py Sat Aug 08 14:17:06 2015 +0300 @@ -35,6 +35,7 @@ import modulecore as ModuleCore import utility import calc +import urllib ModuleData = { 'commands': @@ -108,6 +109,13 @@ 'args': '', 'level': 'normal' }, + + { + 'name': 'py', + 'description': 'Evaluates python', + 'args': '', + 'level': 'normal' + } ] } @@ -236,3 +244,16 @@ def cmd_bitly (reply, args, **k): reply ('Result: %s' % utility.shorten_link (args['link'])) + +def cmd_py (reply, args, **rest): + url = 'http://eval.appspot.com/eval?statement=' + urllib.quote (args['command']) + result = utility.read_url (url).splitlines() + + # \x0f is the 'reset colors' code, prepended to all reply lines to prevent other bots from + # reacting to this .py call. + + if result[0] == 'Traceback (most recent call last):': + reply ('\x0f' + result[-1]) + else: + for line in result: + reply ('\x0f' + line) \ No newline at end of file