messagePlayed condition
This commit is contained in:
parent
c3cae1ea25
commit
ee1a2e39f2
2 changed files with 32 additions and 2 deletions
|
@ -314,7 +314,7 @@ class Condition(object):
|
||||||
condition = conditionClass(data['@id'])
|
condition = conditionClass(data['@id'])
|
||||||
condition.type = data['type']
|
condition.type = data['type']
|
||||||
condition.originalJsonString = json.dumps(data)
|
condition.originalJsonString = json.dumps(data)
|
||||||
|
#: :type condition: Condition
|
||||||
# TODO: should Condition be subclassed?
|
# TODO: should Condition be subclassed?
|
||||||
if data['type'] == "replyContains":
|
if data['type'] == "replyContains":
|
||||||
condition.method = condition._hasMetReplyContains
|
condition.method = condition._hasMetReplyContains
|
||||||
|
@ -324,6 +324,8 @@ class Condition(object):
|
||||||
condition.method = condition._hasVariable
|
condition.method = condition._hasVariable
|
||||||
if data['type'] == "diversion":
|
if data['type'] == "diversion":
|
||||||
condition.method = condition._hasDiverged
|
condition.method = condition._hasDiverged
|
||||||
|
if data['type'] == "messagePlayed":
|
||||||
|
condition.method = condition._hasPlayed
|
||||||
if data['type'] == "variableEquals":
|
if data['type'] == "variableEquals":
|
||||||
condition.method = condition._variableEquals
|
condition.method = condition._variableEquals
|
||||||
|
|
||||||
|
@ -422,6 +424,30 @@ class Condition(object):
|
||||||
)
|
)
|
||||||
|
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
def _hasPlayed(self, story) -> bool:
|
||||||
|
if not story.lastMsgFinishTime:
|
||||||
|
return False
|
||||||
|
|
||||||
|
msg = story.get(self.vars['msgId'])
|
||||||
|
if not msg:
|
||||||
|
story.logger.critical(f"Condition on non-existing message: {self.vars['msgId']}")
|
||||||
|
|
||||||
|
#: :type msg: Message
|
||||||
|
r = msg.isFinished()
|
||||||
|
if r:
|
||||||
|
story.logger.debug(f"Msg {self.vars['msgId']} has been played.")
|
||||||
|
|
||||||
|
if 'inverseMatch' in self.vars and self.vars['inverseMatch']:
|
||||||
|
# inverse:
|
||||||
|
r = not r
|
||||||
|
|
||||||
|
self.logInfo = "Has {} played msg {}".format(
|
||||||
|
'not' if 'inverseMatch' in self.vars and self.vars['inverseMatch'] else '',
|
||||||
|
self.vars['msgId']
|
||||||
|
)
|
||||||
|
|
||||||
|
return r
|
||||||
|
|
||||||
def _hasMetReplyContains(self, story) -> bool:
|
def _hasMetReplyContains(self, story) -> bool:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1361,8 +1361,12 @@ class Graph {
|
||||||
'notEq': { "label": "Not equal", 'value': '', 'title': "Match if the variables are _not_ equal.", 'type':'checkbox' },
|
'notEq': { "label": "Not equal", 'value': '', 'title': "Match if the variables are _not_ equal.", 'type':'checkbox' },
|
||||||
},
|
},
|
||||||
'diversion': {
|
'diversion': {
|
||||||
'diversionId': { 'tag': 'select', 'value': '','placeholder': "Variable name (without $)", 'options': this.diversions.map((d) => d['@id']) },
|
'diversionId': { 'tag': 'select', 'value': '', 'options': this.diversions.map((d) => d['@id']) },
|
||||||
'inverseMatch': { "label": "Match if not done", 'value': '', 'title': "Match if the diversion has _not_ been done.", 'type':'checkbox' },
|
'inverseMatch': { "label": "Match if not done", 'value': '', 'title': "Match if the diversion has _not_ been done.", 'type':'checkbox' },
|
||||||
|
},
|
||||||
|
'messagePlayed': {
|
||||||
|
'msgId': { 'value': '', 'label':'Message ID', 'placeholder': "(eg. en-njsm9b0ni)" },
|
||||||
|
'inverseMatch': { "label": "Match if not played", 'value': '', 'title': "Match if the message has _not_ been played.", 'type':'checkbox' },
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue