chiark / gitweb /
blame: Move blame db information into the cfg
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 29 May 2019 14:05:56 +0000 (15:05 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 30 May 2019 09:56:56 +0000 (10:56 +0100)
These should never have been separate.

We abolish the ad-hoc tbdb, fbdbk etc. variables.  Instead, we put
this all in the cfg.  It is OK to extend the cfg since the code does
not destructure it but instead always indexes it.  So bot instances
without blame will not mind.

blameq needs to fish it out again for the benefit of the open-coded
conditions on "#trouts" etc.  I'm not fixing that right now.

The deleted lines like this
  tbdb,tbdbk=loadblame("trouts")
have different variable names than the inserted lines like this
  tdb,tdbk = cfgs[0][7]
because, unaccountably, the global variable names are different to
the local variables inside blameq.

No functional change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Servus-chiark.py
commands.py

index 828a17f2a5b465c32e2b0753dcf97f55435b2847..0f40c2d044186102464562617c081ed7b172f4d7 100755 (executable)
@@ -72,11 +72,6 @@ def loadblame(filename):
     keys=bdb.keys()
     return bdb,keys
     
-#set up blame dbs for trouts/flirts/slashes
-tbdb,tbdbk=loadblame("trouts")
-fbdb,fbdbk=loadblame("flirts")
-sbdb,sbdbk=loadblame("slashes")
-
 # load a file full of flirts or trouts
 def __load(filename):
     try:
@@ -95,7 +90,9 @@ troutcfg = (
        "Who do you wish me to trout?",
        "Fish stocks exhausted.",
        fish,
-       0.1)
+       0.1,
+       loadblame("trouts"),
+       )
 
 flirtcfg = (
        __load("flirts"),
@@ -104,7 +101,9 @@ flirtcfg = (
        "Who do you wish me to flirt with?",
        "My libido is over-used!",
        fish,
-       0.1)
+       0.1,
+       loadblame("flirts"),
+       )
 
 slashcfg= ( 
        __load("slashes"),
@@ -113,7 +112,9 @@ slashcfg= (
        "Who do you want to slash?",
        "I have writer's block!",
        fish,
-       0.1)
+       0.1,
+       loadblame("slashes")
+       )
 
 # Hacky command to output the current fishpond state
 def fishq(bot, cmd, nick, conn, public,f):
@@ -222,10 +223,7 @@ commands = {"karma": (c.karmaq,karmadb),
            "nws": (c.nsfwq,urldb),
            "units": c.unitq,
            "currency":c.currencyq,
-            "blame": (c.blameq,fish,
-                      troutcfg,tbdb,tbdbk,
-                      flirtcfg,fbdb,fbdbk,
-                      slashcfg,sbdb,sbdbk),
+            "blame": (c.blameq,fish, [troutcfg,flirtcfg,slashcfg]),
            "help": c.helpq,
             "say": c.sayq,
             "do": c.doq, 
index 9e90ad9b17f8bd18b7c616d98e69d3c97672219e..a8499587f222c016b408000b72059b5e7314f431 100755 (executable)
@@ -314,7 +314,10 @@ def __getall(tdb,tdbk,fdb,fdbk,sdb,sdbk,what):
     sans=__getcommits(sdb,sdbk,what)
     return tans+fans+sans
 
-def blameq(bot,cmd,nick,conn,public,fish,tcfg,tdb,tdbk,fcfg,fdb,fdbk,scfg,sdb,sdbk):
+def blameq(bot,cmd,nick,conn,public,fish,cfgs):
+    tdb,tdbk = cfgs[0][7] # urgh, magic, to support magic knowledge below
+    fdb,fdbk = cfgs[1][7]
+    sdb,sdbk = cfgs[2][7]
     clist=cmd.split()
     if len(clist) < 2:
        bot.automsg(public,nick,"Who or what do you want to blame?")