From 3eb4e2dcb2f317f2ac905dc37314f9a7c0d0f250 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Mon, 25 Dec 2017 22:27:09 +0000 Subject: [PATCH] Implement writing and loading the wholist from a file --- threshold | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/threshold b/threshold index 574c5ec..f36ac69 100755 --- a/threshold +++ b/threshold @@ -321,6 +321,7 @@ class Helper(object): wholist[network] = {} for i in newObjects.keys(): wholist[network][i] = newObjects[i] + return def setWhoSingle(self, network, nick, ident, host): @@ -344,22 +345,13 @@ class Helper(object): result[i].append(wholist[i][x]) return result - def saveConfig(self): - global config - with open("config.json", "w") as f: - dump(config, f, indent=4) - return - def getKeywordConfig(self): with open("keyword.json", "r") as f: - keyconf = load(f) - return keyconf + return load(f) - def saveKeywordConfig(self): - global keyconf - with open("keyword.json", "w") as f: - dump(keyconf, f, indent=4) - return + def getWholist(self): + with open("wholist.json", "r") as f: + return load(f) def getPool(self): with open("pool.json", "r") as f: @@ -370,6 +362,24 @@ class Helper(object): else: return {} + def saveConfig(self): + global config + with open("config.json", "w") as f: + dump(config, f, indent=4) + return + + def saveKeywordConfig(self): + global keyconf + with open("keyword.json", "w") as f: + dump(keyconf, f, indent=4) + return + + def saveWholist(self): + global wholist + with open("wholist.json", "w") as f: + dump(wholist, f, indent=4) + return + def savePool(self): global pool with open("pool.json", "w") as f: @@ -540,6 +550,11 @@ class Helper(object): log("Keyword configuration rehashed") success("Keyword configuration rehashed successfully") + elif cmd == "savewho": + self.saveWholist() + success("Saved WHO info to file") + return + elif cmd == "dist": if config["DistEnabled"]: rtrn = run(["./dist.sh"], shell=True, stdout=PIPE) @@ -1018,6 +1033,8 @@ if __name__ == "__main__": pool = helper.getPool() help = helper.getHelp() + wholist = helper.getWholist() + for i in pool.keys(): if pool[i]["enabled"] == True: helper.addBot(i)