monolith/modules/keyword.py

75 lines
2.6 KiB
Python

from core.main import *
from utils.logging.log import *
def sendMaster(data):
if config["Master"][0] in IRCPool.keys():
IRCPool[config["Master"][0]].msg(config["Master"][1], data)
else:
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))
if toSend:
sendMaster("MATCH %s %s (U:%s T:%s): (%s/%s) %s" % (actType, name, toSend[1], toSend[2], user, channel, toSend[0]))
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