monolith/modules/keyword.py

102 lines
3.3 KiB
Python
Raw Normal View History

from core.main import *
from utils.logging.log import *
import modules.counters as count
def sendMaster(data):
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
if config["Master"][0] in IRCPool.keys():
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")
else:
if not hasMonitors:
masterbuf.append(data)
saveConf("masterbuf")
warn("Master with no IRC instance defined")
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))
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 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