X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~matthewv/git?p=irc.git;a=blobdiff_plain;f=Servus-chiark.py;h=02c44d3aa59abdca0ef33899bcda965b620b8915;hp=3fcdc01c7d9a143a881f028e697f0bc2090ab8c4;hb=823ebc496a9c9ed68a3e7f79af777ab19b72b778;hpb=872a59e169c32d0fbf12e347d2c3ac02a2e55b83 diff --git a/Servus-chiark.py b/Servus-chiark.py index 3fcdc01..02c44d3 100644 --- a/Servus-chiark.py +++ b/Servus-chiark.py @@ -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("++"):