2018-02-23 22:05:40 +00:00
|
|
|
from core.main import *
|
|
|
|
from utils.logging.log import *
|
2018-03-04 17:25:57 +00:00
|
|
|
import modules.counters as count
|
2018-02-23 22:05:40 +00:00
|
|
|
|
|
|
|
def sendMaster(data):
|
2018-03-04 17:25:57 +00:00
|
|
|
if not len(MonitorPool) == 0:
|
|
|
|
hasMonitors = True
|
|
|
|
else:
|
|
|
|
hasMonitors = False
|
|
|
|
|
|
|
|
if config["Master"] == [None, None]:
|
|
|
|
if hasMonitors:
|
|
|
|
for i in MonitorPool:
|
|
|
|
connections[i].send(data)
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
masterbuf.append(data)
|
|
|
|
saveConf("masterbuf")
|
|
|
|
return
|
|
|
|
|
2018-02-23 22:05:40 +00:00
|
|
|
if config["Master"][0] in IRCPool.keys():
|
2018-03-04 17:25:57 +00:00
|
|
|
if config["Master"][1] in IRCPool[config["Master"][0]].channels:
|
|
|
|
IRCPool[config["Master"][0]].msg(config["Master"][1], data)
|
|
|
|
else:
|
|
|
|
if not hasMonitors:
|
|
|
|
masterbuf.append(data)
|
|
|
|
saveConf("masterbuf")
|
2018-02-23 22:05:40 +00:00
|
|
|
else:
|
2018-03-04 17:25:57 +00:00
|
|
|
if not hasMonitors:
|
|
|
|
masterbuf.append(data)
|
|
|
|
saveConf("masterbuf")
|
2018-02-23 22:05:40 +00:00
|
|
|
warn("Master with no IRC instance defined")
|
2018-03-04 17:25:57 +00:00
|
|
|
|
2018-02-23 22:05:40 +00:00
|
|
|
for i in MonitorPool:
|
|
|
|
connections[i].send(data)
|
|
|
|
|
|
|
|
def isKeyword(msg):
|
|
|
|
message = msg.lower()
|
|
|
|
messageDuplicate = message
|
|
|
|
toUndo = False
|
|
|
|
uniqueNum = 0
|
|
|
|
totalNum = 0
|
|
|
|
for i in keyconf["Keywords"]:
|
|
|
|
if i in message:
|
|
|
|
if i in keyconf["KeywordsExcept"].keys():
|
|
|
|
for x in keyconf["KeywordsExcept"][i]:
|
|
|
|
if x in message:
|
|
|
|
toUndo = True
|
|
|
|
messageDuplicate = messageDuplicate.replace(x, "\0\r\n\n\0")
|
|
|
|
for y in 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):
|
|
|
|
toSend = isKeyword(message)
|
|
|
|
if name == config["Master"][0] and channel == config["Master"][1]:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
if config["HighlightNotifications"]:
|
|
|
|
msgLower = message.lower()
|
|
|
|
nickLower = nickname.lower()
|
|
|
|
if nickLower in msgLower:
|
|
|
|
msgLower = msgLower.replace(nickLower, "{"+nickLower+"}")
|
|
|
|
sendMaster("NICK %s %s (T:%s): (%s/%s) %s" % (actType, name, msgLower.count(nickLower), user, channel, msgLower))
|
2018-03-04 17:25:57 +00:00
|
|
|
count.event(name, "nickhighlight")
|
2018-02-23 22:05:40 +00:00
|
|
|
if toSend:
|
|
|
|
sendMaster("MATCH %s %s (U:%s T:%s): (%s/%s) %s" % (actType, name, toSend[1], toSend[2], user, channel, toSend[0]))
|
2018-03-04 17:25:57 +00:00
|
|
|
count.event(name, "keymatch")
|
2018-02-23 22:05:40 +00:00
|
|
|
|
|
|
|
def addKeyword(keyword):
|
|
|
|
if keyword in keyconf["Keywords"]:
|
|
|
|
return "EXISTS"
|
|
|
|
else:
|
|
|
|
for i in keyconf["Keywords"]:
|
|
|
|
if i in keyword or keyword in i:
|
|
|
|
return "ISIN"
|
|
|
|
keyconf["Keywords"].append(keyword)
|
|
|
|
saveConf("keyconf")
|
|
|
|
return True
|
|
|
|
|
|
|
|
def delKeyword(keyword):
|
|
|
|
if not keyword in keyconf["Keywords"]:
|
|
|
|
return "NOKEY"
|
|
|
|
keyconf["Keywords"].remove(keyword)
|
|
|
|
saveConf("keyconf")
|
|
|
|
return True
|