Added early untested version of new python exec code - this probably will not work.
This commit is contained in:
parent
bc847f3fb8
commit
3fa8d5d312
2 changed files with 34 additions and 18 deletions
|
@ -1,6 +1,7 @@
|
|||
# Written by Scaevolus 2010
|
||||
from util import hook, http
|
||||
from util.text import multiword_replace
|
||||
from util.eval import execute_eval
|
||||
import string
|
||||
import sqlite3
|
||||
import re
|
||||
|
@ -17,23 +18,6 @@ shortcodes = {
|
|||
'[/i]': '\x16'}
|
||||
|
||||
|
||||
def python(data, args, input):
|
||||
# this is all shit, replacement code is in the works
|
||||
variables = "input='%s'; nick='%s'; chan='%s'; bot_nick='%s';" % (args,
|
||||
input.nick, input.chan, input.conn.nick)
|
||||
statement = variables + data
|
||||
data = data[4:].strip()
|
||||
req = http.get("http://eval.appspot.com/eval", statement=statement).splitlines()
|
||||
if len(req) == 0:
|
||||
return "Failed to recieve response from remote Python API.."
|
||||
req[0] = re_lineends.split(req[0])[0]
|
||||
if not req[0] == 'Traceback (most recent call last):':
|
||||
result = req[0].decode('utf8', 'ignore')
|
||||
else:
|
||||
result = req[-1].decode('utf8', 'ignore')
|
||||
return result
|
||||
|
||||
|
||||
def db_init(db):
|
||||
db.execute("create table if not exists mem(word, data, nick,"
|
||||
" primary key(word))")
|
||||
|
@ -151,7 +135,11 @@ def factoid(inp, say=None, db=None, bot=None, me=None, conn=None, input=None):
|
|||
if data:
|
||||
# if the factoid starts with <py>, its a dynamic one
|
||||
if data.startswith("<py>"):
|
||||
result = python(data[4:].strip(), arguments, input)
|
||||
data = data[4:].strip()
|
||||
variables = "input='%s'; nick='%s'; chan='%s'; bot_nick='%s';" % (args,
|
||||
input.nick, input.chan, input.conn.nick)
|
||||
result = execute_eval(variables + data)
|
||||
|
||||
else:
|
||||
result = data
|
||||
|
||||
|
|
28
plugins/util/exec.py
Normal file
28
plugins/util/exec.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
import http
|
||||
import json, urllib2, sys
|
||||
|
||||
|
||||
def haste(data):
|
||||
URL = "http://paste.dmptr.com"
|
||||
request = urllib2.Request(URL + "/documents", data)
|
||||
response = urllib2.urlopen(request)
|
||||
return("%s/%s" % (URL, json.loads(response.read())['key']))
|
||||
|
||||
|
||||
def execute_eval(code, paste_multiline=True):
|
||||
while True:
|
||||
output = http.get("http://eval.appspot.com/eval", statement=code).rstrip('\n')
|
||||
if output:
|
||||
break
|
||||
else:
|
||||
pass
|
||||
|
||||
if "Traceback (most recent call last):" in output:
|
||||
status = "Python error: "
|
||||
else:
|
||||
status = "Code executed sucessfully: "
|
||||
|
||||
if "\n" in output and paste_multiline:
|
||||
return status + haste(output)
|
||||
else:
|
||||
return output
|
Reference in a new issue