Added .py

Sat, 08 Aug 2015 14:17:06 +0300

author
Teemu Piippo <tsapii@utu.fi>
date
Sat, 08 Aug 2015 14:17:06 +0300
changeset 148
7e225c2659b8
parent 147
4a72fb181a43
child 149
1759c15cd0ca

Added .py

mod_util.py file | annotate | diff | comparison | revisions
--- 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': '<link>',
 			'level': 'normal'
 		},
+
+		{
+			'name': 'py',
+			'description': 'Evaluates python',
+			'args': '<command...>',
+			'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

mercurial