|
|
|
@ -214,7 +214,7 @@ class Base(Protocol):
|
|
|
|
|
|
|
|
|
|
def dataReceived(self, data):
|
|
|
|
|
data = data.decode("utf-8", "replace")
|
|
|
|
|
log("Data received from %s:%s -- %s" % (self.addr.host, self.addr.port, repr(data)))
|
|
|
|
|
#log("Data received from %s:%s -- %s" % (self.addr.host, self.addr.port, repr(data)))
|
|
|
|
|
helper.parseCommand(self.addr, self.authed, data)
|
|
|
|
|
|
|
|
|
|
def connectionMade(self):
|
|
|
|
@ -309,13 +309,22 @@ class Helper(object):
|
|
|
|
|
|
|
|
|
|
def isKeyword(self, msg):
|
|
|
|
|
message = msg.lower()
|
|
|
|
|
toUndo = False
|
|
|
|
|
uniqueNum = 0
|
|
|
|
|
totalNum = 0
|
|
|
|
|
for i in config["Keywords"]:
|
|
|
|
|
if i in message:
|
|
|
|
|
if i in config["KeywordsExcept"].keys():
|
|
|
|
|
for x in config["KeywordsExcept"][i]:
|
|
|
|
|
if x in message:
|
|
|
|
|
toUndo = True
|
|
|
|
|
|
|
|
|
|
if toUndo == False:
|
|
|
|
|
totalNum += message.count(i)
|
|
|
|
|
message = message.replace(i, "{"+i+"}")
|
|
|
|
|
uniqueNum += 1
|
|
|
|
|
toUndo = False
|
|
|
|
|
|
|
|
|
|
if totalNum == 0:
|
|
|
|
|
return False
|
|
|
|
|
else:
|
|
|
|
@ -512,7 +521,7 @@ class Helper(object):
|
|
|
|
|
|
|
|
|
|
elif cmd == "key":
|
|
|
|
|
if data.startswith("key add"):
|
|
|
|
|
if not data == "key add " and not data == "key add":
|
|
|
|
|
if not data in ["key add ", "key add"] and data[3] == " ":
|
|
|
|
|
keywordsToAdd = data[8:]
|
|
|
|
|
keywords = keywordsToAdd.split(",")
|
|
|
|
|
for keyword in keywords:
|
|
|
|
@ -528,7 +537,7 @@ class Helper(object):
|
|
|
|
|
incUsage("key")
|
|
|
|
|
return
|
|
|
|
|
elif data.startswith("key del"):
|
|
|
|
|
if not data == "key del " and not data == "key del":
|
|
|
|
|
if not data in ["key del ", "key del"] and data[3] == " ":
|
|
|
|
|
keywordsToDel = data[8:]
|
|
|
|
|
keywords = keywordsToDel.split(",")
|
|
|
|
|
for keyword in keywords:
|
|
|
|
@ -541,13 +550,67 @@ class Helper(object):
|
|
|
|
|
else:
|
|
|
|
|
incUsage("key")
|
|
|
|
|
return
|
|
|
|
|
if length == 4:
|
|
|
|
|
if spl[1] == "except":
|
|
|
|
|
if not spl[2] in config["Keywords"]:
|
|
|
|
|
failure("No such keyword: %s" % spl[2])
|
|
|
|
|
return
|
|
|
|
|
if spl[2] in config["KeywordsExcept"].keys():
|
|
|
|
|
if spl[3] in config["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
|
|
|
|
|
config["KeywordsExcept"][spl[2]] = []
|
|
|
|
|
|
|
|
|
|
elif spl[1] == "show":
|
|
|
|
|
info(",".join(config["Keywords"]))
|
|
|
|
|
return
|
|
|
|
|
config["KeywordsExcept"][spl[2]].append(spl[3])
|
|
|
|
|
helper.saveConfig()
|
|
|
|
|
success("Successfully added exception %s for keyword %s" % (spl[3], spl[2]))
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
elif spl[1] == "unexcept":
|
|
|
|
|
if not spl[2] in config["KeywordsExcept"].keys():
|
|
|
|
|
failure("No such exception: %s" % spl[2])
|
|
|
|
|
return
|
|
|
|
|
if not spl[3] in config["KeywordsExcept"][spl[2]]:
|
|
|
|
|
failure("Exception %s has no attribute %s" % (spl[2], spl[3]))
|
|
|
|
|
return
|
|
|
|
|
config["KeywordsExcept"][spl[2]].remove(spl[3])
|
|
|
|
|
if config["KeywordsExcept"][spl[2]] == []:
|
|
|
|
|
del config["KeywordsExcept"][spl[2]]
|
|
|
|
|
helper.saveConfig()
|
|
|
|
|
success("Successfully removed exception %s for keyword %s" % (spl[3], spl[2]))
|
|
|
|
|
return
|
|
|
|
|
else:
|
|
|
|
|
incUsage("key")
|
|
|
|
|
return
|
|
|
|
|
if length == 3:
|
|
|
|
|
if spl[1] == "unexcept":
|
|
|
|
|
if not spl[2] in config["KeywordsExcept"].keys():
|
|
|
|
|
failure("No such exception: %s" % spl[2])
|
|
|
|
|
return
|
|
|
|
|
del config["KeywordsExcept"][spl[2]]
|
|
|
|
|
helper.saveConfig()
|
|
|
|
|
success("Successfully removed exception list of %s" % spl[2])
|
|
|
|
|
return
|
|
|
|
|
if length == 2:
|
|
|
|
|
if spl[1] == "show":
|
|
|
|
|
info(",".join(config["Keywords"]))
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
elif spl[1] == "showexcept":
|
|
|
|
|
exceptMap = []
|
|
|
|
|
for i in config["KeywordsExcept"].keys():
|
|
|
|
|
exceptMap.append("Key: %s" % i)
|
|
|
|
|
exceptMap.append("%s: %s" % (i, ",".join(config["KeywordsExcept"][i])))
|
|
|
|
|
exceptMap.append("\n")
|
|
|
|
|
info("\n".join(exceptMap))
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
elif spl[1] == "master":
|
|
|
|
|
if length == 4:
|
|
|
|
|
if length == 4:
|
|
|
|
|
if spl[1] == "master":
|
|
|
|
|
if not spl[2] in pool.keys():
|
|
|
|
|
failure("Name does not exist: %s" % spl[2])
|
|
|
|
|
return
|
|
|
|
@ -558,7 +621,8 @@ class Helper(object):
|
|
|
|
|
helper.saveConfig()
|
|
|
|
|
success("Master set to %s on %s" % (spl[3], spl[2]))
|
|
|
|
|
return
|
|
|
|
|
elif length == 2:
|
|
|
|
|
elif length == 2:
|
|
|
|
|
if spl[1] == "master":
|
|
|
|
|
info(" - ".join(config["Master"]))
|
|
|
|
|
return
|
|
|
|
|
else:
|
|
|
|
|