Implement adding and removing keywords, and setting and viewing the keyword master (reporting target)
This commit is contained in:
parent
73e16aebae
commit
b8e9efa41e
|
@ -5,6 +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>]",
|
||||||
"join": "join <name> <channel> [<key>]",
|
"join": "join <name> <channel> [<key>]",
|
||||||
"enable": "enable <name",
|
"enable": "enable <name",
|
||||||
"disable": "disable <name>",
|
"disable": "disable <name>",
|
||||||
|
|
89
threshold
89
threshold
|
@ -242,6 +242,12 @@ class Helper(object):
|
||||||
else:
|
else:
|
||||||
error("Mandatory values missing from config")
|
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):
|
def getPool(self):
|
||||||
with open("pool.json", "r") as f:
|
with open("pool.json", "r") as f:
|
||||||
data = f.read()
|
data = f.read()
|
||||||
|
@ -308,9 +314,27 @@ class Helper(object):
|
||||||
d = connectProtocol(point, bot)
|
d = connectProtocol(point, bot)
|
||||||
return
|
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):
|
def parseCommand(self, addr, authed, data):
|
||||||
global pool
|
global pool
|
||||||
data = data.strip()
|
data = data.strip("\n")
|
||||||
spl = data.split()
|
spl = data.split()
|
||||||
obj = connections[addr]
|
obj = connections[addr]
|
||||||
|
|
||||||
|
@ -411,6 +435,7 @@ class Helper(object):
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
incUsage("join")
|
incUsage("join")
|
||||||
|
return
|
||||||
|
|
||||||
elif cmd == "part":
|
elif cmd == "part":
|
||||||
if length == 3:
|
if length == 3:
|
||||||
|
@ -425,6 +450,7 @@ class Helper(object):
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
incUsage("part")
|
incUsage("part")
|
||||||
|
return
|
||||||
|
|
||||||
elif cmd == "get":
|
elif cmd == "get":
|
||||||
if length == 3:
|
if length == 3:
|
||||||
|
@ -438,6 +464,66 @@ class Helper(object):
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
incUsage("get")
|
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":
|
elif cmd == "add":
|
||||||
if length == 6:
|
if length == 6:
|
||||||
|
@ -571,6 +657,7 @@ class Helper(object):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
incUsage("mod")
|
incUsage("mod")
|
||||||
|
return
|
||||||
|
|
||||||
else:
|
else:
|
||||||
incUsage(None)
|
incUsage(None)
|
||||||
|
|
Loading…
Reference in New Issue