chiark / gitweb /
Don't remark on URLs that are repeated after a short period
authorMatthew Vernon <matthewv@chiark.greenend.org.uk>
Wed, 7 Nov 2018 19:35:54 +0000 (19:35 +0000)
committerMatthew Vernon <matthewv@chiark.greenend.org.uk>
Wed, 7 Nov 2018 19:35:54 +0000 (19:35 +0000)
If a URL has been mentioned in the recent past, then it'll be
obviously visible in-channel, and it was probably a mistake
(e.g. mentioning a URL you meant to ~twit), so no need to comment on
it.

commands.py

index 6f5a4fb0fb659bfec794348f7f93444306ad9671..488711a254f67b03ff84f2410ce3d1574d8290ba 100755 (executable)
@@ -409,6 +409,8 @@ urlre = re.compile(r"((?:(?:http)|(?:nsfw))s?://[^ ]+)( |$)")
 hturlre= re.compile(r"(http)(s?://[^ ]+)( |$)")
 #matches \bre\:?\s+ before a regexp; (?i)==case insensitive match
 shibboleth = re.compile(r"(?i)\bre\:?\s+((?:(?:http)|(?:nsfw))s?://[^ ]+)( |$)")
 hturlre= re.compile(r"(http)(s?://[^ ]+)( |$)")
 #matches \bre\:?\s+ before a regexp; (?i)==case insensitive match
 shibboleth = re.compile(r"(?i)\bre\:?\s+((?:(?:http)|(?:nsfw))s?://[^ ]+)( |$)")
+#How long (in s) to wait since the most recent mention before commenting
+url_repeat_time = 300
 urlinfos = ["a new",
             "a fascinating",
             "an interesting",
 urlinfos = ["a new",
             "a fascinating",
             "an interesting",
@@ -455,7 +457,8 @@ def dourl(bot,conn,nick,command,urldb):
     T=urldb[urlstring]
     message="observes %s URL, first mentioned %s by %s" % \
              (T.urltype(),T.firstmen(),T.nick)
     T=urldb[urlstring]
     message="observes %s URL, first mentioned %s by %s" % \
              (T.urltype(),T.firstmen(),T.nick)
-    if shibboleth.search(command)==None:
+    if shibboleth.search(command)==None and \
+       time.time() - T.lastseen > url_repeat_time:
         conn.action(bot.channel, message)
     T.lastseen=time.time()
     T.count+=1
         conn.action(bot.channel, message)
     T.lastseen=time.time()
     T.count+=1