From 129d1b9256f7020515e6ccfd2dcdab26d0908eec Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 29 May 2019 15:05:56 +0100 Subject: [PATCH] blame: Move blame db information into the cfg 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 --- Servus-chiark.py | 22 ++++++++++------------ commands.py | 5 ++++- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Servus-chiark.py b/Servus-chiark.py index 828a17f..0f40c2d 100755 --- a/Servus-chiark.py +++ b/Servus-chiark.py @@ -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, diff --git a/commands.py b/commands.py index 9e90ad9..a849958 100755 --- a/commands.py +++ b/commands.py @@ -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?") -- 2.30.2