def on_enter(cls, page, user, prev): t = i18n.translator(user) sep = "-" * 50 + "\n" page.send( user.facebook_id, sep + t(random.choice(cls.texts)), quick_replies=i18n.translate_buttons(cls.buttons, lang=user.language) ) return Transition.STAY
def on_enter(cls, page, user, prev): page.send( user.facebook_id, translate(cls.question, lang=user.language), quick_replies=translate_buttons(cls.buttons, lang=user.language), ) return Transition.STAY
def on_enter(cls, page, user, prev): t = i18n.translator(user) page.send( user.facebook_id, t(random.choice(cls.texts)) + " " + t(random.choice(cls.say_it)), quick_replies=i18n.translate_buttons([random.choice(cls.buttons)], lang=user.language), ) return Transition.STAY
def on_enter(cls, page, user, prev): return Transition.MOVE("tracker.End") t = i18n.translator(user) group = "cigarettes" with cls.storage(user) as s: if group not in s: page.send( user.facebook_id, t("Pour faire un essai, clique sur le bouton «Je fume» ci-dessous. Réponds ensuite aux questions qui suivront, au hasard pour cette fois." ), quick_replies=i18n.translate_buttons(cls.buttons, lang=user.language), ) else: page.send( user.facebook_id, t("Pour enregistrer une cigarette clique sur le bouton «Je fume» ci-dessous." ), quick_replies=i18n.translate_buttons(cls.buttons, lang=user.language), ) return Transition.STAY
def on_event(cls, page, user, event): """Run code when an event occurs.""" # Get the response response = event.quick_reply_payload # If the answer is not valid if response not in [b["payload"] for b in cls.buttons]: page.send( user.facebook_id, translate("Merci de répondre en utilisant les boutons", lang=user.language), quick_replies=translate_buttons(cls.buttons, lang=user.language), ) return Transition.STAY # Save it with cls.storage(user) as s: s[cls.group][-1][cls.name] = response # Move to next question # pylint: disable=not-callable move_to = cls.next(response) if callable(cls.next) else cls.next return Transition.MOVE(move_to)
def to_buttons(cls, proposed, user, num=5): buttons = [ {"title": chr(97 + i), "payload": proposed[i][0]} for i in range(num) ] other = i18n.translate_buttons([{"title": "Autre", "payload": "DISTRACT_OTHER"}], lang=user.language) return buttons + other