From 6824443901f36036534ee10f505e4ca5091ca5fb Mon Sep 17 00:00:00 2001 From: Ryan Hitchman Date: Fri, 20 May 2011 00:13:11 -0600 Subject: [PATCH] add pre: search scene releases, urlhistory: don't alert quoted lines --- plugins/misc.py | 2 +- plugins/pre.py | 32 ++++++++++++++++++++++++++++++++ plugins/urlhistory.py | 10 ++++++++-- 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 plugins/pre.py diff --git a/plugins/misc.py b/plugins/misc.py index 4546f42..ce9908d 100644 --- a/plugins/misc.py +++ b/plugins/misc.py @@ -16,7 +16,7 @@ def get_version(): revnumber = len(stdout.splitlines()) shorthash = stdout.split(None, 1)[0] - + http.ua_skybot = 'Skybot/r%d %s (http://github.com/rmmh/skybot)' \ % (revnumber, shorthash) diff --git a/plugins/pre.py b/plugins/pre.py new file mode 100644 index 0000000..45c0115 --- /dev/null +++ b/plugins/pre.py @@ -0,0 +1,32 @@ +# searches scene releases using orlydb + +from util import hook, http + + +@hook.command +def predb(inp): + '.predb -- searches scene releases using orlydb.com' + + try: + h = http.get_html("http://orlydb.com/", q=inp) + except HTTPError: + return 'orlydb seems to be down' + + results = h.xpath("//div[@id='releases']/div/span[@class='release']/..") + + if not results: + return "zero results" + + result = results[0] + + date, time = result.xpath("span[@class='timestamp']/text()")[0].split() + section, = result.xpath("span[@class='section']//text()") + name, = result.xpath("span[@class='release']/text()") + + size = result.xpath("span[@class='inforight']//text()") + if size: + size = ' :: ' + size[0].split()[0] + else: + size = '' + + return '%s - %s - %s%s' % (date, section, name, size) diff --git a/plugins/urlhistory.py b/plugins/urlhistory.py index b850c02..d5470cd 100644 --- a/plugins/urlhistory.py +++ b/plugins/urlhistory.py @@ -4,7 +4,6 @@ import time from util import hook, urlnorm, timesince -url_re = r'([a-zA-Z]+://|www\.)[^ ]+' expiration_period = 60 * 60 * 24 # 1 day @@ -64,7 +63,7 @@ def format_reply(history): hour_span, nicklist(history), last) -@hook.regex(url_re) +@hook.regex(r'([a-zA-Z]+://|www\.)[^ ]+') def urlinput(match, nick='', chan='', db=None, bot=None): db_init(db) url = urlnorm.normalize(match.group().encode('utf-8')) @@ -72,5 +71,12 @@ def urlinput(match, nick='', chan='', db=None, bot=None): url = url.decode('utf-8') history = get_history(db, chan, url) insert_history(db, chan, url, nick) + + inp = match.string.lower() + + for name in dict(history): + if name.lower() in inp: # person was probably quoting a line + return # that had a link. don't remind them. + if nick not in dict(history): return format_reply(history)