diff --git a/plugins/urlhistory.py b/plugins/urlhistory.py index abbcc07..ea1831a 100644 --- a/plugins/urlhistory.py +++ b/plugins/urlhistory.py @@ -8,6 +8,9 @@ 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")] @@ -27,13 +30,21 @@ def insert_history(db, chan, url, nick): db.commit() -def get_history(db, chan, url): +def get_history(db, chan, url, duration): db.execute("delete from urlhistory where time < ?", - (time.time() - expiration_period,)) + (time.time() - duration,)) 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): + return get_history(db, chan, url, expiration_period) + + +def get_recent_links_count(db, chan, url): + return len(get_history(db, chan, url, rate_limit_period)) + + def nicklist(nicks): nicks = sorted(dict(nicks), key=unicode.lower) if len(nicks) <= 2: @@ -78,6 +89,7 @@ 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): + if nick not in dict(history) and recent_history < rate_limit_count: return format_reply(history) diff --git a/plugins/youtube.py b/plugins/youtube.py index 99a5a21..1e7da2b 100644 --- a/plugins/youtube.py +++ b/plugins/youtube.py @@ -10,7 +10,7 @@ from urllib import quote_plus locale.setlocale(locale.LC_ALL, '') -youtube_re = re.compile(r'youtube.*?v=([-_a-z0-9]+)', flags=re.I) +youtube_re = re.compile(r'(?:youtube.*?(?:v=|/v/)|youtu\.be/|yooouuutuuube.*?id=)([-_a-z0-9]+)', flags=re.I) base_url = 'http://gdata.youtube.com/feeds/api/' url = base_url + 'videos/%s?v=2&alt=jsonc'