add pre: search scene releases, urlhistory: don't alert quoted lines

This commit is contained in:
Ryan Hitchman 2011-05-20 00:13:11 -06:00
parent 543ff44995
commit 6824443901
3 changed files with 41 additions and 3 deletions

View File

@ -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)

32
plugins/pre.py Normal file
View File

@ -0,0 +1,32 @@
# searches scene releases using orlydb
from util import hook, http
@hook.command
def predb(inp):
'.predb <query> -- 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)

View File

@ -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)