Skip to content

Commit

Permalink
URL: Do not send "OLD!" messages whenever the link is quite fresh
Browse files Browse the repository at this point in the history
  • Loading branch information
nightmared committed Sep 16, 2018
1 parent bcfb9c7 commit b30a91a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
23 changes: 14 additions & 9 deletions url/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import re
from datetime import timedelta, datetime

import sqlalchemy.exc
from pipobot.lib.known_users import KnownUser
Expand Down Expand Up @@ -50,16 +51,20 @@ def check_repost(self, sender, urls):
if not any(i in url for i in self.repost_ignore):
res = self.bot.session.query(RepostUrl).filter(RepostUrl.url == url).first()
if res:
send.append('OLD! ')
first = KnownUser.get_antihl(res.jid, self.bot)
first_date = 'le ' + res.date.strftime('%x') + ' à ' + res.date.strftime('%X')
first_date = first_date.decode("utf-8")
if res.count == 1:
send.append(u'Ce lien a déjà été posté %s par %s sur %s…' % (first_date, first, res.chan))
else:
ret = u'Ce lien a déjà été posté %s fois depuis que %s l’a découvert, %s, sur %s…'
send.append(ret % (res.count, first, first_date, res.chan))
# Do not send a message if the link was shared less than a few minutes ago
if (datetime.now() - res.last_date) > timedelta(minutes=5):
send.append('OLD! ')
first = KnownUser.get_antihl(res.jid, self.bot)
first_date = 'le ' + res.date.strftime('%x') + ' à ' + res.date.strftime('%X')
first_date = first_date.decode("utf-8")
if res.count == 1:
send.append(u'Ce lien a déjà été posté %s par %s sur %s…' % (first_date, first, first.chan))
else:
ret = u'Ce lien a déjà été posté %s fois depuis que %s l’a découvert, %s, sur %s…'
send.append(ret % (res.count, first, first_date, res.chan))
res.count += 1
# Update the time someone posted the link
res.last_date = datetime.now()
else:
u = RepostUrl(url,
self.bot.occupants.pseudo_to_jid(sender),
Expand Down
2 changes: 2 additions & 0 deletions url/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class RepostUrl(Base):
url = Column(String(250), primary_key=True)
count = Column(Integer)
date = Column(DateTime)
last_date = Column(DateTime)
jid = Column(String(250))
chan = Column(String(250))

Expand All @@ -18,4 +19,5 @@ def __init__(self, url, jid, chan):
self.jid = jid
self.count = 1
self.date = datetime.datetime.now()
self.last_date = self.date
self.chan = chan

0 comments on commit b30a91a

Please sign in to comment.