150 lines
6.6 KiB
Python
150 lines
6.6 KiB
Python
|
from core.main import *
|
||
|
import modules.keyword as keyword
|
||
|
|
||
|
class Key:
|
||
|
def __init__(self, register):
|
||
|
register("key", self.key)
|
||
|
|
||
|
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 keyconf["Keywords"]:
|
||
|
failure("No such keyword: %s" % spl[2])
|
||
|
return
|
||
|
if spl[2] in keyconf["KeywordsExcept"].keys():
|
||
|
if spl[3] in 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
|
||
|
keyconf["KeywordsExcept"][spl[2]] = []
|
||
|
|
||
|
keyconf["KeywordsExcept"][spl[2]].append(spl[3])
|
||
|
saveConf("keyconf")
|
||
|
success("Successfully added exception %s for keyword %s" % (spl[3], spl[2]))
|
||
|
return
|
||
|
elif spl[1] == "master":
|
||
|
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]]
|
||
|
saveConf("config")
|
||
|
success("Master set to %s on %s" % (spl[3], spl[2]))
|
||
|
return
|
||
|
elif spl[1] == "unexcept":
|
||
|
if not spl[2] in keyconf["KeywordsExcept"].keys():
|
||
|
failure("No such exception: %s" % spl[2])
|
||
|
return
|
||
|
if not spl[3] in keyconf["KeywordsExcept"][spl[2]]:
|
||
|
failure("Exception %s has no attribute %s" % (spl[2], spl[3]))
|
||
|
return
|
||
|
keyconf["KeywordsExcept"][spl[2]].remove(spl[3])
|
||
|
if keyconf["KeywordsExcept"][spl[2]] == []:
|
||
|
del keyconf["KeywordsExcept"][spl[2]]
|
||
|
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 keyconf["KeywordsExcept"].keys():
|
||
|
failure("No such exception: %s" % spl[2])
|
||
|
return
|
||
|
del keyconf["KeywordsExcept"][spl[2]]
|
||
|
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 MonitorPool:
|
||
|
MonitorPool.append(obj.addr)
|
||
|
success("Keyword monitoring enabled")
|
||
|
return
|
||
|
else:
|
||
|
failure("Keyword monitoring is already enabled")
|
||
|
return
|
||
|
elif spl[2] == "off":
|
||
|
if obj.addr in MonitorPool:
|
||
|
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] == "show":
|
||
|
info(",".join(keyconf["Keywords"]))
|
||
|
return
|
||
|
|
||
|
elif spl[1] == "showexcept":
|
||
|
exceptMap = []
|
||
|
for i in keyconf["KeywordsExcept"].keys():
|
||
|
exceptMap.append("Key: %s" % i)
|
||
|
exceptMap.append("%s: %s" % (i, ",".join(keyconf["KeywordsExcept"][i])))
|
||
|
exceptMap.append("\n")
|
||
|
info("\n".join(exceptMap))
|
||
|
return
|
||
|
elif spl[1] == "master":
|
||
|
info(" - ".join(config["Master"]))
|
||
|
return
|
||
|
elif spl[1] == "monitor":
|
||
|
if obj.addr in 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)
|