chiark / gitweb /
new flirt from rjk
[irc.git] / Servus-chiark.py
index 3fcdc01c7d9a143a881f028e697f0bc2090ab8c4..02c44d3aa59abdca0ef33899bcda965b620b8915 100644 (file)
@@ -141,7 +141,12 @@ class game:
        losetime=time.time()+300000
 
 # initialise the urldb on startup
-c.urldb={}
+urldb={}
+lastexp=time.time()
+#expire urls if not asked about or seen for >71 hours
+expirelen=71*60*60
+#do an expiry run every hour
+expirevery=60*60
 
 # Command processing: whenever something is said that the bot can hear,
 # "command" is invoked and must decide what to do.  This configuration
@@ -163,7 +168,7 @@ commands = {"karma": (c.karmaq,karmadb),
            "die": quit,
            "define": c.defineq,
             "google": c.googleq,
-#          "url": urlq,
+           "url": (c.urlq,urldb),
            "units": c.unitq,
            "help": c.helpq,
 #          "game": (c.gameq,game),
@@ -178,6 +183,7 @@ triggers = ("!", "~") # what character should the bot be invoked by:
                       # eg !trout, ~trout etc.
 
 def command(bot, cmd, nick, conn, public):
+    global urldb,lastexp,expirelen,expirevery
     ours=0
     try:
            if public and cmd[0] in triggers:
@@ -189,9 +195,14 @@ def command(bot, cmd, nick, conn, public):
     except IndexError:
            command=""
 
-#    if public:
-#      if c.urlre.search(cmd):
-#        c.dourl(bot,conn,nick,cmd)
+    t=time.time()
+    if t - lastexp > expirevery:
+           c.urlexpire(urldb,expirelen)
+           lastexp=t
+
+    if public:
+      if c.urlre.search(cmd) and command.lower()!="url":
+        c.dourl(bot,conn,nick,cmd,urldb)
          
     # karma: up
     if command.endswith("++"):