106 lines
3.6 KiB
Python
106 lines
3.6 KiB
Python
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")
|
|
warn("Master with no IRC instance defined")
|
|
|
|
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 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:
|
|
if main.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))
|
|
count.event(name, "nickhighlight")
|
|
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
|