messagePlayed condition

This commit is contained in:
Ruben van de Ven 2019-06-16 17:44:13 +02:00
parent c3cae1ea25
commit ee1a2e39f2
2 changed files with 32 additions and 2 deletions

View file

@ -314,7 +314,7 @@ class Condition(object):
condition = conditionClass(data['@id'])
condition.type = data['type']
condition.originalJsonString = json.dumps(data)
#: :type condition: Condition
# TODO: should Condition be subclassed?
if data['type'] == "replyContains":
condition.method = condition._hasMetReplyContains
@ -324,6 +324,8 @@ class Condition(object):
condition.method = condition._hasVariable
if data['type'] == "diversion":
condition.method = condition._hasDiverged
if data['type'] == "messagePlayed":
condition.method = condition._hasPlayed
if data['type'] == "variableEquals":
condition.method = condition._variableEquals
@ -422,6 +424,30 @@ class Condition(object):
)
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:
"""

View file

@ -1361,8 +1361,12 @@ class Graph {
'notEq': { "label": "Not equal", 'value': '', 'title': "Match if the variables are _not_ equal.", 'type':'checkbox' },
},
'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' },
},
'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' },
}
};
}