revert urlhistory to non-broken version

This commit is contained in:
Ryan Hitchman 2010-03-06 12:42:59 -07:00
parent b1d5753304
commit 5200749c66
1 changed files with 4 additions and 16 deletions

View File

@ -8,9 +8,6 @@ url_re = re.compile(r'([a-zA-Z]+://|www\.)[^ ]*')
expiration_period = 60 * 60 * 24 # 1 day
rate_limit_period = 60 * 3 # 3 minutes
rate_limit_count = 3
ignored_urls = [urlnorm.normalize("http://google.com")]
@ -30,21 +27,13 @@ def insert_history(db, chan, url, nick):
db.commit()
def get_history_duration(db, chan, url, duration):
def get_history(db, chan, url):
db.execute("delete from urlhistory where time < ?",
(time.time() - expiration_period,))
return db.execute("select nick, time from urlhistory where "
"chan=? and url=? order by time desc", (chan, url)).fetchall()
def get_history(db, chan, url):
db.execute("delete from urlhistory where time < ?",
(time.time() - duration,))
return get_history_duration(db, chan, url, expiration_period)
def get_recent_links_count(db, chan, url):
return len(get_history_duration(db, chan, url, rate_limit_period))
def nicklist(nicks):
nicks = sorted(dict(nicks), key=unicode.lower)
if len(nicks) <= 2:
@ -89,7 +78,6 @@ def urlinput(inp, nick='', chan='', server='', reply=None, bot=None):
url = urlnorm.normalize(m.group(0))
if url not in ignored_urls:
history = get_history(db, chan, url)
recent_history = get_recent_links_count(db, chan, url)
insert_history(db, chan, url, nick)
if nick not in dict(history) and recent_history < rate_limit_count:
if nick not in dict(history):
return format_reply(history)