Separate out everything into files and implement a modules system to segment commands
This commit is contained in:
74
modules/keyword.py
Normal file
74
modules/keyword.py
Normal file
@@ -0,0 +1,74 @@
|
||||
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
|
||||
31
modules/userinfo.py
Normal file
31
modules/userinfo.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from core.main import *
|
||||
#from utils.logging.log import *
|
||||
|
||||
def setWho(network, newObjects):
|
||||
network = "".join([x for x in network if not x in numbers])
|
||||
if not network in wholist.keys():
|
||||
wholist[network] = {}
|
||||
for i in newObjects.keys():
|
||||
wholist[network][i] = newObjects[i]
|
||||
|
||||
return
|
||||
|
||||
def setWhoSingle(network, nick, ident, host):
|
||||
network = "".join([x for x in network if not x in numbers])
|
||||
|
||||
if network in wholist.keys():
|
||||
if nick in wholist[network].keys():
|
||||
wholist[network][nick][1] = ident
|
||||
wholist[network][nick][2] = host
|
||||
else:
|
||||
wholist[network][nick] = [nick, ident, host, None, None, None]
|
||||
|
||||
def getWho(nick):
|
||||
result = {}
|
||||
for i in wholist.keys():
|
||||
for x in wholist[i].keys():
|
||||
if nick.lower() == x.lower():
|
||||
if not i in result.keys():
|
||||
result[i] = []
|
||||
result[i].append(wholist[i][x])
|
||||
return result
|
||||
Reference in New Issue
Block a user