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") 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 main.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: msgLower = message.lower() nickLower = nickname.lower() if nickLower in msgLower: # Someone has said the bot's nickname msgLower = msgLower.replace(nickLower, "{"+nickLower+"}") count.event(name, "nickhighlight") if main.config["Notifications"]["Highlight"]: sendMaster("NICK %s %s (T:%s): (%s/%s) %s" % (actType, name, msgLower.count(nickLower), user, channel, msgLower)) if not channel == None: chanLower = channel.lower() if nickLower == chanLower: # I received a message directed only at me ZNCAlreadySent = False if main.config["Notifications"]["Query"]: if user == main.config["Tweaks"]["ZNC"]["Prefix"] + "status!znc@znc.in": if main.config["Compat"]["ZNC"]: sendMaster("ZNC %s %s: %s" % (actType, name, msgLower)) ZNCAlreadySent = True else: sendMaster("QUERY %s %s: (%s) %s" % (actType, name, user, msgLower)) else: sendMaster("QUERY %s %s: (%s) %s" % (actType, name, user, msgLower)) if not ZNCAlreadySent == True: if main.config["Compat"]["ZNC"]: if user == main.config["Tweaks"]["ZNC"]["Prefix"] + "status!znc@znc.in": sendMaster("ZNC %s %s: %s" % (actType, name, msgLower)) 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