Added early untested version of new python exec code - this probably will not work.

This commit is contained in:
Luke Rogers 2012-08-28 11:29:08 +12:00
parent bc847f3fb8
commit 3fa8d5d312
2 changed files with 34 additions and 18 deletions

View file

@ -1,6 +1,7 @@
# Written by Scaevolus 2010 # Written by Scaevolus 2010
from util import hook, http from util import hook, http
from util.text import multiword_replace from util.text import multiword_replace
from util.eval import execute_eval
import string import string
import sqlite3 import sqlite3
import re import re
@ -17,23 +18,6 @@ shortcodes = {
'[/i]': '\x16'} '[/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): def db_init(db):
db.execute("create table if not exists mem(word, data, nick," db.execute("create table if not exists mem(word, data, nick,"
" primary key(word))") " 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 data:
# if the factoid starts with <py>, its a dynamic one # if the factoid starts with <py>, its a dynamic one
if data.startswith("<py>"): 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: else:
result = data result = data

28
plugins/util/exec.py Normal file
View 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