2018-07-27 21:58:37 +00:00
|
|
|
import main
|
|
|
|
import modules.keyword as keyword
|
2018-07-28 20:33:50 +00:00
|
|
|
from copy import deepcopy
|
2018-07-27 21:58:37 +00:00
|
|
|
|
|
|
|
def testNetTarget(name, target):
|
2018-08-19 15:02:14 +00:00
|
|
|
called = False
|
2018-07-27 21:58:37 +00:00
|
|
|
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:
|
2018-08-19 15:02:14 +00:00
|
|
|
yield i
|
|
|
|
called = True
|
2018-07-27 21:58:37 +00:00
|
|
|
elif target in main.monitor[i]["sources"][name]:
|
2018-08-19 15:02:14 +00:00
|
|
|
yield i
|
|
|
|
called = True
|
2018-07-27 21:58:37 +00:00
|
|
|
else:
|
2018-08-19 15:02:14 +00:00
|
|
|
yield i
|
|
|
|
called = True
|
|
|
|
if not called:
|
|
|
|
return False
|
2018-07-27 21:58:37 +00:00
|
|
|
|
|
|
|
def magicFunction(A, B):
|
2018-07-28 20:33:50 +00:00
|
|
|
if "send" in B.keys():
|
|
|
|
del B["send"]
|
|
|
|
if "sources" in B.keys():
|
|
|
|
del B["sources"]
|
2018-07-27 21:58:37 +00:00
|
|
|
return all(A[k] in B[k] for k in set(A) & set(B)) and set(B) <= set(A)
|
|
|
|
|
|
|
|
def event(name, target, cast):
|
2018-08-19 15:02:14 +00:00
|
|
|
monitorGroups = testNetTarget(name, target)
|
|
|
|
if monitorGroups == False:
|
2018-07-27 21:58:37 +00:00
|
|
|
return
|
2018-08-19 15:02:14 +00:00
|
|
|
for monitorGroup in monitorGroups:
|
|
|
|
matcher = magicFunction(deepcopy(cast), deepcopy(main.monitor[monitorGroup]))
|
|
|
|
if matcher == True:
|
|
|
|
if "send" in main.monitor[monitorGroup].keys():
|
|
|
|
for i in main.monitor[monitorGroup]["send"].keys():
|
|
|
|
if isinstance(main.monitor[monitorGroup]["send"][i], bool):
|
|
|
|
keyword.sendMaster("ERRDELIV MONITOR [%s] (%s/%s) %s " % (monitorGroup, name, target, cast))
|
|
|
|
continue
|
|
|
|
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/%s) %s" % (monitorGroup, name, target, cast))
|
|
|
|
else:
|
|
|
|
keyword.sendMaster("MONITOR [%s] (%s/%s) %s " % (monitorGroup, name, target, cast))
|