Implement optional x in y matching for attributes in the monitor system
This commit is contained in:
parent
1de3f17d45
commit
249e99805a
|
@ -20,6 +20,9 @@ class Mon:
|
||||||
group2.add_argument("-p", "--append", action="store_true", dest="doAppend", help="Append entries to lists instead of replacing")
|
group2.add_argument("-p", "--append", action="store_true", dest="doAppend", help="Append entries to lists instead of replacing")
|
||||||
group2.add_argument("-r", "--remove", action="store_true", dest="doRemove", help="Remove entries in lists instead of replacing")
|
group2.add_argument("-r", "--remove", action="store_true", dest="doRemove", help="Remove entries in lists instead of replacing")
|
||||||
|
|
||||||
|
self.parser.add_argument("--inside", action="store_true", dest="inside", help="Use x in y logic for matching instead of comparing exact values")
|
||||||
|
self.parser.add_argument("--outside", action="store_false", dest="inside", help="Don't use x in y logic for matching instead of comparing exact values")
|
||||||
|
|
||||||
self.parser.add_argument("--type", nargs="*", metavar="type", dest="specType", help="Specify type of spec matching. Available types: join, part, quit, msg, topic, mode, nick, kick, notice, action, who")
|
self.parser.add_argument("--type", nargs="*", metavar="type", dest="specType", help="Specify type of spec matching. Available types: join, part, quit, msg, topic, mode, nick, kick, notice, action, who")
|
||||||
self.parser.add_argument("--free", nargs="*", metavar="query", dest="free", help="Use freeform matching")
|
self.parser.add_argument("--free", nargs="*", metavar="query", dest="free", help="Use freeform matching")
|
||||||
self.parser.add_argument("--exact", nargs="*", metavar="query", dest="exact", help="Use exact matching")
|
self.parser.add_argument("--exact", nargs="*", metavar="query", dest="exact", help="Use exact matching")
|
||||||
|
@ -218,6 +221,8 @@ class Mon:
|
||||||
cast["real"] = []
|
cast["real"] = []
|
||||||
for i in obj.real:
|
for i in obj.real:
|
||||||
cast["real"].append(" ".join(i))
|
cast["real"].append(" ".join(i))
|
||||||
|
if not obj.inside == None:
|
||||||
|
cast["inside"] = obj.inside
|
||||||
return cast
|
return cast
|
||||||
|
|
||||||
def subtractCast(self, source, patch, info):
|
def subtractCast(self, source, patch, info):
|
||||||
|
|
|
@ -19,12 +19,34 @@ def testNetTarget(name, target):
|
||||||
if not called:
|
if not called:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def contained_in(x, y):
|
||||||
|
if x is None or y is None:
|
||||||
|
return False
|
||||||
|
elif x == y:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return y in x
|
||||||
|
|
||||||
|
def is_in(k, vs, A):
|
||||||
|
return any(contained_in(A.get(k), vp) for vp in vs)
|
||||||
|
|
||||||
|
def matches(A, B):
|
||||||
|
return all(is_in(k, vs, A) for (k, vs) in B.items())
|
||||||
|
|
||||||
def magicFunction(A, B):
|
def magicFunction(A, B):
|
||||||
|
isInside = False
|
||||||
if "send" in B.keys():
|
if "send" in B.keys():
|
||||||
del B["send"]
|
del B["send"]
|
||||||
if "sources" in B.keys():
|
if "sources" in B.keys():
|
||||||
del B["sources"]
|
del B["sources"]
|
||||||
return all(A[k] in B[k] for k in set(A) & set(B)) and set(B) <= set(A)
|
if "inside" in B.keys():
|
||||||
|
if B["inside"] == True:
|
||||||
|
isInside = True
|
||||||
|
del B["inside"]
|
||||||
|
if isInside:
|
||||||
|
return matches(A, B)
|
||||||
|
else:
|
||||||
|
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):
|
||||||
monitorGroups = testNetTarget(name, target)
|
monitorGroups = testNetTarget(name, target)
|
||||||
|
|
Loading…
Reference in New Issue