|
|
|
@ -242,6 +242,12 @@ class Helper(object):
|
|
|
|
|
else:
|
|
|
|
|
error("Mandatory values missing from config")
|
|
|
|
|
|
|
|
|
|
def saveConfig(self):
|
|
|
|
|
global config
|
|
|
|
|
with open("config.json", "w") as f:
|
|
|
|
|
dump(config, f, indent=4)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
def getPool(self):
|
|
|
|
|
with open("pool.json", "r") as f:
|
|
|
|
|
data = f.read()
|
|
|
|
@ -308,9 +314,27 @@ class Helper(object):
|
|
|
|
|
d = connectProtocol(point, bot)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
def addKeyword(self, keyword):
|
|
|
|
|
if keyword in config["Keywords"]:
|
|
|
|
|
return "EXISTS"
|
|
|
|
|
else:
|
|
|
|
|
for i in config["Keywords"]:
|
|
|
|
|
if i in keyword or keyword in i:
|
|
|
|
|
return "ISIN"
|
|
|
|
|
config["Keywords"].append(keyword)
|
|
|
|
|
helper.saveConfig()
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def delKeyword(self, keyword):
|
|
|
|
|
if not keyword in config["Keywords"]:
|
|
|
|
|
return "NOKEY"
|
|
|
|
|
config["Keywords"].remove(keyword)
|
|
|
|
|
helper.saveConfig()
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def parseCommand(self, addr, authed, data):
|
|
|
|
|
global pool
|
|
|
|
|
data = data.strip()
|
|
|
|
|
data = data.strip("\n")
|
|
|
|
|
spl = data.split()
|
|
|
|
|
obj = connections[addr]
|
|
|
|
|
|
|
|
|
@ -411,6 +435,7 @@ class Helper(object):
|
|
|
|
|
return
|
|
|
|
|
else:
|
|
|
|
|
incUsage("join")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
elif cmd == "part":
|
|
|
|
|
if length == 3:
|
|
|
|
@ -425,6 +450,7 @@ class Helper(object):
|
|
|
|
|
return
|
|
|
|
|
else:
|
|
|
|
|
incUsage("part")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
elif cmd == "get":
|
|
|
|
|
if length == 3:
|
|
|
|
@ -438,6 +464,66 @@ class Helper(object):
|
|
|
|
|
return
|
|
|
|
|
else:
|
|
|
|
|
incUsage("get")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
elif cmd == "key":
|
|
|
|
|
if data.startswith("key add"):
|
|
|
|
|
if not data == "key add " and not data == "key add":
|
|
|
|
|
keywordsToAdd = data[8:]
|
|
|
|
|
keywords = keywordsToAdd.split(",")
|
|
|
|
|
for keyword in keywords:
|
|
|
|
|
rtrn = self.addKeyword(keyword)
|
|
|
|
|
if rtrn == "EXISTS":
|
|
|
|
|
failure("Keyword already exists: %s" % keyword)
|
|
|
|
|
elif rtrn == "ISIN":
|
|
|
|
|
failure("Keyword already matched: %s" % keyword)
|
|
|
|
|
elif rtrn == True:
|
|
|
|
|
success("Keyword added: %s" % keyword)
|
|
|
|
|
return
|
|
|
|
|
else:
|
|
|
|
|
incUsage("key")
|
|
|
|
|
return
|
|
|
|
|
elif data.startswith("key del"):
|
|
|
|
|
if not data == "key del " and not data == "key del":
|
|
|
|
|
keywordsToDel = data[8:]
|
|
|
|
|
keywords = keywordsToDel.split(",")
|
|
|
|
|
for keyword in keywords:
|
|
|
|
|
rtrn = self.delKeyword(keyword)
|
|
|
|
|
if rtrn == "NOKEY":
|
|
|
|
|
failure("Keyword does not exist: %s" % keyword)
|
|
|
|
|
elif rtrn == True:
|
|
|
|
|
success("Keyword deleted: %s" % keyword)
|
|
|
|
|
return
|
|
|
|
|
else:
|
|
|
|
|
incUsage("key")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
elif spl[1] == "show":
|
|
|
|
|
info(", ".join(config["Keywords"]))
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
elif spl[1] == "master":
|
|
|
|
|
if length == 4:
|
|
|
|
|
if not spl[2] in pool.keys():
|
|
|
|
|
failure("Name does not exist: %s" % spl[2])
|
|
|
|
|
return
|
|
|
|
|
if spl[2] in IRCPool.keys():
|
|
|
|
|
if not spl[3] in IRCPool[spl[2]].channels:
|
|
|
|
|
info("Bot not on channel: %s" % spl[3])
|
|
|
|
|
config["Master"] = [spl[2], spl[3]]
|
|
|
|
|
helper.saveConfig()
|
|
|
|
|
success("Master set to %s on %s" % (spl[3], spl[2]))
|
|
|
|
|
return
|
|
|
|
|
elif length == 2:
|
|
|
|
|
info(" - ".join(config["Master"]))
|
|
|
|
|
return
|
|
|
|
|
else:
|
|
|
|
|
incUsage("key")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
incUsage("key")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
elif cmd == "add":
|
|
|
|
|
if length == 6:
|
|
|
|
@ -571,6 +657,7 @@ class Helper(object):
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
incUsage("mod")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
incUsage(None)
|
|
|
|
|