import main import modules.keyword as keyword class Key: def __init__(self, *args): self.key(*args) def key(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if data.startswith("key add"): if not data in ["key add ", "key add"] and data[3] == " ": keywordsToAdd = data[8:] keywords = keywordsToAdd.split(",") for i in keywords: rtrn = keyword.addKeyword(i) if rtrn == "EXISTS": failure("Keyword already exists: %s" % i) elif rtrn == "ISIN": failure("Keyword already matched: %s" % i) elif rtrn == True: success("Keyword added: %s" % i) return else: incUsage("key") return elif data.startswith("key del"): if not data in ["key del ", "key del"] and data[3] == " ": keywordsToDel = data[8:] keywords = keywordsToDel.split(",") for i in keywords: rtrn = keyword.delKeyword(i) if rtrn == "NOKEY": failure("Keyword does not exist: %s" % i) elif rtrn == True: success("Keyword deleted: %s" % i) return else: incUsage("key") return if length == 4: if spl[1] == "except": if not spl[2] in main.keyconf["Keywords"]: failure("No such keyword: %s" % spl[2]) return if spl[2] in main.keyconf["KeywordsExcept"].keys(): if spl[3] in main.keyconf["KeywordsExcept"][spl[2]]: failure("Exception exists: %s" % spl[3]) return else: if not spl[2] in spl[3]: failure("Keyword %s not in exception %s. This won't work." % (spl[2], spl[3])) return main.keyconf["KeywordsExcept"][spl[2]] = [] main.keyconf["KeywordsExcept"][spl[2]].append(spl[3]) main.saveConf("keyconf") success("Successfully added exception %s for keyword %s" % (spl[3], spl[2])) return elif spl[1] == "master": if not spl[2] in main.pool.keys(): failure("Name does not exist: %s" % spl[2]) return if spl[2] in main.IRCPool.keys(): if not spl[3] in main.IRCPool[spl[2]].channels: info("Bot not on channel: %s" % spl[3]) main.config["Master"] = [spl[2], spl[3]] main.saveConf("config") success("Master set to %s on %s" % (spl[3], spl[2])) return elif spl[1] == "unexcept": if not spl[2] in main.keyconf["KeywordsExcept"].keys(): failure("No such exception: %s" % spl[2]) return if not spl[3] in main.keyconf["KeywordsExcept"][spl[2]]: failure("Exception %s has no attribute %s" % (spl[2], spl[3])) return main.keyconf["KeywordsExcept"][spl[2]].remove(spl[3]) if main.keyconf["KeywordsExcept"][spl[2]] == []: del main.keyconf["KeywordsExcept"][spl[2]] main.saveConf("keyconf") success("Successfully removed exception %s for keyword %s" % (spl[3], spl[2])) return else: incUsage("key") return elif length == 3: if spl[1] == "unexcept": if not spl[2] in main.keyconf["KeywordsExcept"].keys(): failure("No such exception: %s" % spl[2]) return del main.keyconf["KeywordsExcept"][spl[2]] main.saveConf("keyconf") success("Successfully removed exception list of %s" % spl[2]) return elif spl[1] == "monitor": if spl[2] == "on": if not obj.addr in main.MonitorPool: main.MonitorPool.append(obj.addr) success("Keyword monitoring enabled") if len(main.masterbuf) == 0: return rtrn = [] for i in range(len(main.masterbuf)): rtrn.append(main.masterbuf.pop(0)) main.saveConf("masterbuf") info("\n".join(rtrn)) return else: failure("Keyword monitoring is already enabled") return elif spl[2] == "off": if obj.addr in main.MonitorPool: main.MonitorPool.remove(obj.addr) success("Keyword monitoring disabled") return else: failure("Keyword monitoring is already disabled") return else: incUsage("key") return else: incUsage("key") return elif length == 2: if spl[1] == "list": info(",".join(main.keyconf["Keywords"])) return elif spl[1] == "listexcept": exceptMap = [] for i in main.keyconf["KeywordsExcept"].keys(): exceptMap.append("Key: %s" % i) exceptMap.append("%s: %s" % (i, ",".join(main.keyconf["KeywordsExcept"][i]))) exceptMap.append("\n") info("\n".join(exceptMap)) return elif spl[1] == "master": info(" - ".join([str(i) for i in main.config["Master"]])) return elif spl[1] == "monitor": if obj.addr in main.MonitorPool: info("Keyword monitoring is enabled on this connection") return else: info("Keyword monitoring is disabled on this connection") return else: incUsage("key") return else: incUsage("key") return else: incUsage(None)