Update plugins/factoids.py

This commit is contained in:
Luke Rogers 2012-09-10 12:12:45 +12:00
parent 8980610aa9
commit 8c33af02ae

View file

@ -132,16 +132,22 @@ def factoid(inp, say=None, db=None, bot=None, me=None, conn=None, input=None):
data = get_memory(db, factoid_id) data = get_memory(db, factoid_id)
if data: if data:
# if the factoid starts with <py>, its a dynamic one # factoid preprocessors
if data.startswith("<py>"): if data.startswith("<py>"):
data = data[4:].strip() code = data[4:].strip()
variables = 'input="""%s"""; nick="%s"; chan="%s"; bot_nick="%s";' % (arguments.replace('"', '\\"'), variables = 'input="""%s"""; nick="%s"; chan="%s"; bot_nick="%s";' % (arguments.replace('"', '\\"'),
input.nick, input.chan, input.conn.nick) input.nick, input.chan, input.conn.nick)
result = eval_py(variables + data) result = eval_py(variables + code)
elif data.startswith("<url>"):
url = data[5:].strip()
try:
result = http.get(url)
except http.HttpError:
result = "Could not fetch URL."
else: else:
result = data result = data
# factoid postprocessors
result = multiword_replace(result, shortcodes) result = multiword_replace(result, shortcodes)
if result.startswith("<act>"): if result.startswith("<act>"):