diff --git a/plugins/factoids.py b/plugins/factoids.py index cdd0a15..e3d2fbc 100755 --- a/plugins/factoids.py +++ b/plugins/factoids.py @@ -1,7 +1,5 @@ # Written by Scaevolus 2010 -from util import hook, http -from util.text import multiword_replace -from util.execute import eval_py +from util import hook, http, text, execute import string import sqlite3 import re @@ -137,7 +135,7 @@ def factoid(inp, say=None, db=None, bot=None, me=None, conn=None, input=None): code = data[4:].strip() variables = 'input="""%s"""; nick="%s"; chan="%s"; bot_nick="%s";' % (arguments.replace('"', '\\"'), input.nick, input.chan, input.conn.nick) - result = eval_py(variables + code) + result = execute.eval_py(variables + code) elif data.startswith(""): url = data[5:].strip() try: @@ -148,7 +146,7 @@ def factoid(inp, say=None, db=None, bot=None, me=None, conn=None, input=None): result = data # factoid postprocessors - result = multiword_replace(result, shortcodes) + result = text.multiword_replace(result, shortcodes) if result.startswith(""): result = result[5:].strip() diff --git a/plugins/steam.py b/plugins/steam.py index 97d7ad5..0622d46 100644 --- a/plugins/steam.py +++ b/plugins/steam.py @@ -3,9 +3,10 @@ import re # this is still beta code. some things will be improved later. -steamcalc_url = "http://steamcalculator.com/id/{}/{}" +# vari +steamcalc_url = "http://steamcalculator.com/id/{}" count_re = re.compile(r"Found (.*?) Games with a value of ") -region = "us" # if you change this shit breaks +value_re = re.compile(r'\$(\d+\.\d{2})') def db_init(db): @@ -24,7 +25,7 @@ def steamcalc(inp, db=None): return "Invalid Steam ID" uid = inp.strip().lower() - url = steamcalc_url.format(http.quote_plus(uid), region) + url = steamcalc_url.format(http.quote_plus(uid)) # get the web page try: @@ -38,7 +39,7 @@ def steamcalc(inp, db=None): count = int(count_re.findall(count_textual)[0]) value_textual = page.xpath("//div[@id='rightdetail']/h1/text()")[0] - value = float(value_textual[1:][:-4]) # todo: make this less shit + value = float(value_re.findall(value_textual)[0]) except IndexError: return "Could not get Steam game listing." @@ -53,7 +54,7 @@ def steamcalc(inp, db=None): except web.ShortenError as e: short_url = url - return u"Found {} games with a total value of ${:.2f} USD! - {}".format(count, value, short_url) + return u"\x02Games:\x02 {}, \x02Total Value:\x02 ${:.2f} USD - {}".format(count, value, short_url) @hook.command(autohelp=False) diff --git a/plugins/youtube.py b/plugins/youtube.py index 32bd6be..665ee8e 100755 --- a/plugins/youtube.py +++ b/plugins/youtube.py @@ -8,13 +8,13 @@ youtube_re = (r'(?:youtube.*?(?:v=|/v/)|youtu\.be/|yooouuutuuube.*?id=)' '([-_a-zA-Z0-9]+)', re.I) base_url = 'http://gdata.youtube.com/feeds/api/' -url = base_url + 'videos/%s?v=2&alt=jsonc' +api_url = base_url + 'videos/{}?v=2&alt=jsonc' search_api_url = base_url + 'videos?v=2&alt=jsonc&max-results=1' video_url = "http://youtu.be/%s" -def get_video_description(vid_id): - request = http.get_json(url % vid_id) +def get_video_description(video_id): + request = http.get_json(api_url.format(video_id)) if request.get('error'): return