Implement keyword exceptions
This commit is contained in:
parent
d9e142758c
commit
2e552f8d2e
|
@ -13,5 +13,6 @@
|
||||||
"authtype": null
|
"authtype": null
|
||||||
},
|
},
|
||||||
"Keywords": [],
|
"Keywords": [],
|
||||||
|
"KeywordsExcept": {},
|
||||||
"Master": []
|
"Master": []
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
"del": "del <name>",
|
"del": "del <name>",
|
||||||
"mod": "mod <name> [<key>] [<value>]",
|
"mod": "mod <name> [<key>] [<value>]",
|
||||||
"get": "get <name> <variable>",
|
"get": "get <name> <variable>",
|
||||||
"key": "key <master|show|add|del> {[<name>] [<target>]} [<key>]",
|
"key": "key <master|show|add|del|except|unexcept|showexcept> [<name>] [<target>] [<key>]",
|
||||||
"join": "join <name> <channel> [<key>]",
|
"join": "join <name> <channel> [<key>]",
|
||||||
"enable": "enable <name",
|
"enable": "enable <name",
|
||||||
"disable": "disable <name>",
|
"disable": "disable <name>",
|
||||||
|
|
82
threshold
82
threshold
|
@ -214,7 +214,7 @@ class Base(Protocol):
|
||||||
|
|
||||||
def dataReceived(self, data):
|
def dataReceived(self, data):
|
||||||
data = data.decode("utf-8", "replace")
|
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)
|
helper.parseCommand(self.addr, self.authed, data)
|
||||||
|
|
||||||
def connectionMade(self):
|
def connectionMade(self):
|
||||||
|
@ -309,13 +309,22 @@ class Helper(object):
|
||||||
|
|
||||||
def isKeyword(self, msg):
|
def isKeyword(self, msg):
|
||||||
message = msg.lower()
|
message = msg.lower()
|
||||||
|
toUndo = False
|
||||||
uniqueNum = 0
|
uniqueNum = 0
|
||||||
totalNum = 0
|
totalNum = 0
|
||||||
for i in config["Keywords"]:
|
for i in config["Keywords"]:
|
||||||
if i in message:
|
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)
|
totalNum += message.count(i)
|
||||||
message = message.replace(i, "{"+i+"}")
|
message = message.replace(i, "{"+i+"}")
|
||||||
uniqueNum += 1
|
uniqueNum += 1
|
||||||
|
toUndo = False
|
||||||
|
|
||||||
if totalNum == 0:
|
if totalNum == 0:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
|
@ -512,7 +521,7 @@ class Helper(object):
|
||||||
|
|
||||||
elif cmd == "key":
|
elif cmd == "key":
|
||||||
if data.startswith("key add"):
|
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:]
|
keywordsToAdd = data[8:]
|
||||||
keywords = keywordsToAdd.split(",")
|
keywords = keywordsToAdd.split(",")
|
||||||
for keyword in keywords:
|
for keyword in keywords:
|
||||||
|
@ -528,7 +537,7 @@ class Helper(object):
|
||||||
incUsage("key")
|
incUsage("key")
|
||||||
return
|
return
|
||||||
elif data.startswith("key del"):
|
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:]
|
keywordsToDel = data[8:]
|
||||||
keywords = keywordsToDel.split(",")
|
keywords = keywordsToDel.split(",")
|
||||||
for keyword in keywords:
|
for keyword in keywords:
|
||||||
|
@ -541,13 +550,67 @@ class Helper(object):
|
||||||
else:
|
else:
|
||||||
incUsage("key")
|
incUsage("key")
|
||||||
return
|
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":
|
config["KeywordsExcept"][spl[2]].append(spl[3])
|
||||||
info(",".join(config["Keywords"]))
|
helper.saveConfig()
|
||||||
return
|
success("Successfully added exception %s for keyword %s" % (spl[3], spl[2]))
|
||||||
|
return
|
||||||
|
|
||||||
elif spl[1] == "master":
|
elif spl[1] == "unexcept":
|
||||||
if length == 4:
|
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
|
||||||
|
|
||||||
|
if length == 4:
|
||||||
|
if spl[1] == "master":
|
||||||
if not spl[2] in pool.keys():
|
if not spl[2] in pool.keys():
|
||||||
failure("Name does not exist: %s" % spl[2])
|
failure("Name does not exist: %s" % spl[2])
|
||||||
return
|
return
|
||||||
|
@ -558,7 +621,8 @@ class Helper(object):
|
||||||
helper.saveConfig()
|
helper.saveConfig()
|
||||||
success("Master set to %s on %s" % (spl[3], spl[2]))
|
success("Master set to %s on %s" % (spl[3], spl[2]))
|
||||||
return
|
return
|
||||||
elif length == 2:
|
elif length == 2:
|
||||||
|
if spl[1] == "master":
|
||||||
info(" - ".join(config["Master"]))
|
info(" - ".join(config["Master"]))
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue