Implement monitoring system for flexible metadata matching
This commit is contained in:
@@ -89,7 +89,7 @@ def actKeyword(user, channel, message, nickname, actType, name):
|
||||
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/%s) %s" % (actType, name, user, channel, msgLower))
|
||||
sendMaster("ZNC %s %s: %s" % (actType, name, msgLower))
|
||||
ZNCAlreadySent = True
|
||||
else:
|
||||
sendMaster("QUERY %s %s: (%s) %s" % (actType, name, user, msgLower))
|
||||
@@ -98,7 +98,7 @@ def actKeyword(user, channel, message, nickname, actType, name):
|
||||
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/%s) %s" % (actType, name, user, channel, msgLower))
|
||||
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")
|
||||
|
||||
36
modules/monitor.py
Normal file
36
modules/monitor.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import main
|
||||
import modules.keyword as keyword
|
||||
from pprint import pformat
|
||||
|
||||
def testNetTarget(name, target):
|
||||
for i in main.monitor.keys():
|
||||
if "sources" in main.monitor[i].keys():
|
||||
if name in main.monitor[i]["sources"]:
|
||||
if main.monitor[i]["sources"][name] == True:
|
||||
return i
|
||||
elif target in main.monitor[i]["sources"][name]:
|
||||
return i
|
||||
else:
|
||||
return i
|
||||
return False
|
||||
|
||||
def magicFunction(A, B):
|
||||
return all(A[k] in B[k] for k in set(A) & set(B)) and set(B) <= set(A)
|
||||
|
||||
def event(name, target, cast):
|
||||
monitorGroup = testNetTarget(name, target)
|
||||
if monitorGroup == False:
|
||||
return
|
||||
matcher = magicFunction(cast, main.monitor[monitorGroup])
|
||||
|
||||
if matcher == True:
|
||||
if "send" in main.monitor[monitorGroup]:
|
||||
for i in main.monitor[monitorGroup]["send"].keys():
|
||||
if not i in main.pool.keys():
|
||||
keyword.sendMaster("ERROR on monitor %s: No such name: %s" % (monitorGroup, i))
|
||||
if not i in main.IRCPool.keys():
|
||||
keyword.sendMaster("ERROR on monitor %s: No such instance: %s" % (monitorGroup, i))
|
||||
for x in main.monitor[monitorGroup]["send"][i]:
|
||||
main.IRCPool[i].msg(x, "MONITOR [%s] %s" % (monitorGroup, pformat(cast)))
|
||||
else:
|
||||
keyword.sendMaster("MONITOR [%s] %s " % (monitorGroup, pformat(cast)))
|
||||
Reference in New Issue
Block a user