Remove keyword system, implement ZNC notifications to relay, remove exact from cast fields and fix security bug in relay
parent
0637f762ea
commit
68c6aa969d
@ -1,155 +0,0 @@
|
|||||||
import main
|
|
||||||
import modules.keyword as keyword
|
|
||||||
|
|
||||||
class Key:
|
|
||||||
def __init__(self, *args):
|
|
||||||
self.key(*args)
|
|
||||||
|
|
||||||
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 main.keyconf["Keywords"]:
|
|
||||||
failure("No such keyword: %s" % spl[2])
|
|
||||||
return
|
|
||||||
if spl[2] in main.keyconf["KeywordsExcept"].keys():
|
|
||||||
if spl[3] in main.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
|
|
||||||
main.keyconf["KeywordsExcept"][spl[2]] = []
|
|
||||||
|
|
||||||
main.keyconf["KeywordsExcept"][spl[2]].append(spl[3])
|
|
||||||
main.saveConf("keyconf")
|
|
||||||
success("Successfully added exception %s for keyword %s" % (spl[3], spl[2]))
|
|
||||||
return
|
|
||||||
elif spl[1] == "master":
|
|
||||||
if not spl[2] in main.pool.keys():
|
|
||||||
failure("Name does not exist: %s" % spl[2])
|
|
||||||
return
|
|
||||||
if spl[2] in main.IRCPool.keys():
|
|
||||||
if not spl[3] in main.IRCPool[spl[2]].channels:
|
|
||||||
info("Bot not on channel: %s" % spl[3])
|
|
||||||
main.config["Master"] = [spl[2], spl[3]]
|
|
||||||
main.saveConf("config")
|
|
||||||
success("Master set to %s on %s" % (spl[3], spl[2]))
|
|
||||||
return
|
|
||||||
elif spl[1] == "unexcept":
|
|
||||||
if not spl[2] in main.keyconf["KeywordsExcept"].keys():
|
|
||||||
failure("No such exception: %s" % spl[2])
|
|
||||||
return
|
|
||||||
if not spl[3] in main.keyconf["KeywordsExcept"][spl[2]]:
|
|
||||||
failure("Exception %s has no attribute %s" % (spl[2], spl[3]))
|
|
||||||
return
|
|
||||||
main.keyconf["KeywordsExcept"][spl[2]].remove(spl[3])
|
|
||||||
if main.keyconf["KeywordsExcept"][spl[2]] == []:
|
|
||||||
del main.keyconf["KeywordsExcept"][spl[2]]
|
|
||||||
main.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 main.keyconf["KeywordsExcept"].keys():
|
|
||||||
failure("No such exception: %s" % spl[2])
|
|
||||||
return
|
|
||||||
del main.keyconf["KeywordsExcept"][spl[2]]
|
|
||||||
main.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 main.MonitorPool:
|
|
||||||
main.MonitorPool.append(obj.addr)
|
|
||||||
success("Keyword monitoring enabled")
|
|
||||||
if len(main.masterbuf) == 0:
|
|
||||||
return
|
|
||||||
rtrn = []
|
|
||||||
for i in range(len(main.masterbuf)):
|
|
||||||
rtrn.append(main.masterbuf.pop(0))
|
|
||||||
main.saveConf("masterbuf")
|
|
||||||
info("\n".join(rtrn))
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
failure("Keyword monitoring is already enabled")
|
|
||||||
return
|
|
||||||
elif spl[2] == "off":
|
|
||||||
if obj.addr in main.MonitorPool:
|
|
||||||
main.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] == "list":
|
|
||||||
info(",".join(main.keyconf["Keywords"]))
|
|
||||||
return
|
|
||||||
|
|
||||||
elif spl[1] == "listexcept":
|
|
||||||
exceptMap = []
|
|
||||||
for i in main.keyconf["KeywordsExcept"].keys():
|
|
||||||
exceptMap.append("Key: %s" % i)
|
|
||||||
exceptMap.append("%s: %s" % (i, ",".join(main.keyconf["KeywordsExcept"][i])))
|
|
||||||
exceptMap.append("\n")
|
|
||||||
info("\n".join(exceptMap))
|
|
||||||
return
|
|
||||||
elif spl[1] == "master":
|
|
||||||
info(" - ".join([str(i) for i in main.config["Master"]]))
|
|
||||||
return
|
|
||||||
elif spl[1] == "monitor":
|
|
||||||
if obj.addr in main.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)
|
|
@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"Keywords": [
|
|
||||||
"example"
|
|
||||||
],
|
|
||||||
"KeywordsExcept": {}
|
|
||||||
}
|
|
@ -1,121 +0,0 @@
|
|||||||
import main
|
|
||||||
from utils.logging.log import *
|
|
||||||
import modules.counters as count
|
|
||||||
|
|
||||||
def sendMaster(data):
|
|
||||||
if not len(main.MonitorPool) == 0:
|
|
||||||
hasMonitors = True
|
|
||||||
else:
|
|
||||||
hasMonitors = False
|
|
||||||
|
|
||||||
if main.config["Master"] == [None, None]:
|
|
||||||
if hasMonitors:
|
|
||||||
for i in main.MonitorPool:
|
|
||||||
main.connections[i].send(data)
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
main.masterbuf.append(data)
|
|
||||||
main.saveConf("masterbuf")
|
|
||||||
return
|
|
||||||
|
|
||||||
if main.config["Master"][0] in main.IRCPool.keys():
|
|
||||||
if main.config["Master"][1] in main.IRCPool[main.config["Master"][0]].channels:
|
|
||||||
main.IRCPool[main.config["Master"][0]].msg(main.config["Master"][1], data)
|
|
||||||
else:
|
|
||||||
if not hasMonitors:
|
|
||||||
main.masterbuf.append(data)
|
|
||||||
main.saveConf("masterbuf")
|
|
||||||
else:
|
|
||||||
if not hasMonitors:
|
|
||||||
main.masterbuf.append(data)
|
|
||||||
main.saveConf("masterbuf")
|
|
||||||
|
|
||||||
for i in main.MonitorPool:
|
|
||||||
main.connections[i].send(data)
|
|
||||||
|
|
||||||
def isKeyword(msg):
|
|
||||||
if msg == None:
|
|
||||||
return
|
|
||||||
message = msg.lower()
|
|
||||||
messageDuplicate = message
|
|
||||||
toUndo = False
|
|
||||||
uniqueNum = 0
|
|
||||||
totalNum = 0
|
|
||||||
for i in main.keyconf["Keywords"]:
|
|
||||||
if i in message:
|
|
||||||
if i in main.keyconf["KeywordsExcept"].keys():
|
|
||||||
for x in main.keyconf["KeywordsExcept"][i]:
|
|
||||||
if x in message:
|
|
||||||
toUndo = True
|
|
||||||
messageDuplicate = messageDuplicate.replace(x, "\0\r\n\n\0")
|
|
||||||
for y in main.keyconf["Keywords"]:
|
|
||||||
if i in messageDuplicate:
|
|
||||||
totalNum += messageDuplicate.count(i)
|
|
||||||
message = messageDuplicate.replace(i, "{"+i+"}")
|
|
||||||
message = message.replace("\0\r\n\n\0", x)
|
|
||||||
uniqueNum += 1
|
|
||||||
|
|
||||||
if toUndo == False:
|
|
||||||
totalNum += message.count(i)
|
|
||||||
message = message.replace(i, "{"+i+"}")
|
|
||||||
uniqueNum += 1
|
|
||||||
|
|
||||||
toUndo = False
|
|
||||||
|
|
||||||
if totalNum == 0:
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return [message, uniqueNum, totalNum]
|
|
||||||
|
|
||||||
def actKeyword(user, channel, message, nickname, actType, name):
|
|
||||||
if message == None:
|
|
||||||
return
|
|
||||||
toSend = isKeyword(message)
|
|
||||||
if name == main.config["Master"][0] and channel == main.config["Master"][1]:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
msgLower = message.lower()
|
|
||||||
nickLower = nickname.lower()
|
|
||||||
if nickLower in msgLower: # Someone has said the bot's nickname
|
|
||||||
msgLower = msgLower.replace(nickLower, "{"+nickLower+"}")
|
|
||||||
count.event(name, "nickhighlight")
|
|
||||||
if main.config["Notifications"]["Highlight"]:
|
|
||||||
sendMaster("NICK %s %s (T:%s): (%s/%s) %s" % (actType, name, msgLower.count(nickLower), user, channel, msgLower))
|
|
||||||
if not channel == None:
|
|
||||||
chanLower = channel.lower()
|
|
||||||
if nickLower == chanLower: # I received a message directed only at me
|
|
||||||
ZNCAlreadySent = False
|
|
||||||
if main.config["Notifications"]["Query"]:
|
|
||||||
if user == main.config["Tweaks"]["ZNC"]["Prefix"] + "status!znc@znc.in":
|
|
||||||
if main.config["Compat"]["ZNC"]:
|
|
||||||
sendMaster("ZNC %s %s: %s" % (actType, name, msgLower))
|
|
||||||
ZNCAlreadySent = True
|
|
||||||
else:
|
|
||||||
sendMaster("QUERY %s %s: (%s) %s" % (actType, name, user, msgLower))
|
|
||||||
else:
|
|
||||||
sendMaster("QUERY %s %s: (%s) %s" % (actType, name, user, msgLower))
|
|
||||||
if not ZNCAlreadySent == True:
|
|
||||||
if main.config["Compat"]["ZNC"]:
|
|
||||||
if user == main.config["Tweaks"]["ZNC"]["Prefix"] + "status!znc@znc.in":
|
|
||||||
sendMaster("ZNC %s %s: %s" % (actType, name, msgLower))
|
|
||||||
if toSend:
|
|
||||||
sendMaster("MATCH %s %s (U:%s T:%s): (%s/%s) %s" % (actType, name, toSend[1], toSend[2], user, channel, toSend[0]))
|
|
||||||
count.event(name, "keymatch")
|
|
||||||
|
|
||||||
def addKeyword(keyword):
|
|
||||||
if keyword in main.keyconf["Keywords"]:
|
|
||||||
return "EXISTS"
|
|
||||||
else:
|
|
||||||
for i in main.keyconf["Keywords"]:
|
|
||||||
if i in keyword or keyword in i:
|
|
||||||
return "ISIN"
|
|
||||||
main.keyconf["Keywords"].append(keyword)
|
|
||||||
main.saveConf("keyconf")
|
|
||||||
return True
|
|
||||||
|
|
||||||
def delKeyword(keyword):
|
|
||||||
if not keyword in main.keyconf["Keywords"]:
|
|
||||||
return "NOKEY"
|
|
||||||
main.keyconf["Keywords"].remove(keyword)
|
|
||||||
main.saveConf("keyconf")
|
|
||||||
return True
|
|
Loading…
Reference in New Issue