First implementation of questions management
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
from core.builtin_concepts import BuiltinConcepts
|
||||
from evaluators.BaseEvaluator import OneReturnValueEvaluator
|
||||
|
||||
|
||||
class PrepareEvalQuestionEvaluator(OneReturnValueEvaluator):
|
||||
"""
|
||||
To recognize when the user input is a question
|
||||
"""
|
||||
|
||||
NAME = "PrepareEvalQuestion"
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(self.NAME, [BuiltinConcepts.BEFORE_PARSING], 90)
|
||||
self.question = None
|
||||
|
||||
def matches(self, context, return_value):
|
||||
if not (return_value.status and
|
||||
context.sheerka.isinstance(return_value.body, BuiltinConcepts.USER_INPUT) and
|
||||
isinstance(return_value.body.body, str)):
|
||||
return False
|
||||
|
||||
text = return_value.body.body.strip()
|
||||
if not (text.startswith("question(") and text.endswith(")")):
|
||||
return False
|
||||
|
||||
self.question = text[9:-1].strip()
|
||||
if self.question == "":
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def eval(self, context, return_value):
|
||||
sheerka = context.sheerka
|
||||
|
||||
new_text_to_parse = sheerka.ret(
|
||||
self.name,
|
||||
True, sheerka.new(BuiltinConcepts.USER_INPUT, body=self.question, user_name=context.event.user_id))
|
||||
|
||||
root = context.get_parents(lambda ec: ec.action == BuiltinConcepts.PROCESS_INPUT)
|
||||
root = root[0] if root else context
|
||||
root.protected_hints.add(BuiltinConcepts.EVAL_QUESTION_REQUESTED)
|
||||
root.protected_hints.add(BuiltinConcepts.EVAL_BODY_REQUESTED)
|
||||
root.protected_hints.add(BuiltinConcepts.RETURN_BODY_REQUESTED)
|
||||
|
||||
return new_text_to_parse
|
||||
Reference in New Issue
Block a user