Merge pull request #129 from nasonfish/patch-2

Make <url> a Factoid post-processor. Now we can make our own web server api things and use them without having to make a plugin
This commit is contained in:
Luke Rogers 2013-09-02 20:53:43 -07:00
commit 4e0a0b9d6d

View file

@ -136,12 +136,6 @@ def factoid(inp, say=None, db=None, bot=None, me=None, conn=None, input=None):
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 = execute.eval_py(variables + code) result = execute.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
@ -151,6 +145,12 @@ def factoid(inp, say=None, db=None, bot=None, me=None, conn=None, input=None):
if result.startswith("<act>"): if result.startswith("<act>"):
result = result[5:].strip() result = result[5:].strip()
me(result) me(result)
elif result.startswith("<url>"):
url = result[5:].strip()
try:
say(http.get(url))
except http.HttpError:
say("Could not fetch URL.")
else: else:
if prefix_on: if prefix_on:
say("\x02[%s]:\x02 %s" % (factoid_id, result)) say("\x02[%s]:\x02 %s" % (factoid_id, result))