Fix monitors to work properly with multiple groups

This commit is contained in:
Mark Veidemanis 2018-08-19 16:02:14 +01:00
parent 4b7c9f83e7
commit de5baf562b
1 changed files with 27 additions and 21 deletions

View File

@ -3,16 +3,21 @@ import modules.keyword as keyword
from copy import deepcopy from copy import deepcopy
def testNetTarget(name, target): def testNetTarget(name, target):
called = False
for i in main.monitor.keys(): for i in main.monitor.keys():
if "sources" in main.monitor[i].keys(): if "sources" in main.monitor[i].keys():
if name in main.monitor[i]["sources"]: if name in main.monitor[i]["sources"]:
if main.monitor[i]["sources"][name] == True: if main.monitor[i]["sources"][name] == True:
return i yield i
called = True
elif target in main.monitor[i]["sources"][name]: elif target in main.monitor[i]["sources"][name]:
return i yield i
called = True
else: else:
return i yield i
return False called = True
if not called:
return False
def magicFunction(A, B): def magicFunction(A, B):
if "send" in B.keys(): if "send" in B.keys():
@ -22,21 +27,22 @@ def magicFunction(A, B):
return all(A[k] in B[k] for k in set(A) & set(B)) and set(B) <= set(A) return all(A[k] in B[k] for k in set(A) & set(B)) and set(B) <= set(A)
def event(name, target, cast): def event(name, target, cast):
monitorGroup = testNetTarget(name, target) monitorGroups = testNetTarget(name, target)
if monitorGroup == False: if monitorGroups == False:
return return
matcher = magicFunction(deepcopy(cast), deepcopy(main.monitor[monitorGroup])) for monitorGroup in monitorGroups:
if matcher == True: matcher = magicFunction(deepcopy(cast), deepcopy(main.monitor[monitorGroup]))
if "send" in main.monitor[monitorGroup].keys(): if matcher == True:
for i in main.monitor[monitorGroup]["send"].keys(): if "send" in main.monitor[monitorGroup].keys():
if isinstance(main.monitor[monitorGroup]["send"][i], bool): for i in main.monitor[monitorGroup]["send"].keys():
keyword.sendMaster("ERRDELIV MONITOR [%s] (%s/%s) %s " % (monitorGroup, name, target, cast)) if isinstance(main.monitor[monitorGroup]["send"][i], bool):
continue keyword.sendMaster("ERRDELIV MONITOR [%s] (%s/%s) %s " % (monitorGroup, name, target, cast))
if not i in main.pool.keys(): continue
keyword.sendMaster("ERROR on monitor %s: No such name: %s" % (monitorGroup, i)) if not i in main.pool.keys():
if not i in main.IRCPool.keys(): keyword.sendMaster("ERROR on monitor %s: No such name: %s" % (monitorGroup, i))
keyword.sendMaster("ERROR on monitor %s: No such instance: %s" % (monitorGroup, i)) if not i in main.IRCPool.keys():
for x in main.monitor[monitorGroup]["send"][i]: keyword.sendMaster("ERROR on monitor %s: No such instance: %s" % (monitorGroup, i))
main.IRCPool[i].msg(x, "MONITOR [%s] (%s/%s) %s" % (monitorGroup, name, target, cast)) for x in main.monitor[monitorGroup]["send"][i]:
else: main.IRCPool[i].msg(x, "MONITOR [%s] (%s/%s) %s" % (monitorGroup, name, target, cast))
keyword.sendMaster("MONITOR [%s] (%s/%s) %s " % (monitorGroup, name, target, cast)) else:
keyword.sendMaster("MONITOR [%s] (%s/%s) %s " % (monitorGroup, name, target, cast))