Beispiel #1
0
def submit_message_handler(user: User, update: Update,
                           context: CallbackContext) -> None:
    """ Gets the submission text from user """
    submission_value = update.message.text

    sentence_count = parser.get_sentence_count(submission_value)
    if sentence_count != 1:
        reply_to(
            user, update,
            user.language.get(Token.PLEASE_ENTER_ONE_SENTENCE) %
            sentence_count)
        return

    todays_mwe = get_todays_mwe(user.language)
    try:
        parsed = parser.parse(submission_value, todays_mwe)
    except Exception as ex:
        mwelog.error(ex)
        reply_to(user,
                 update,
                 user.language.get(Token.SUBMISSION_CONTAINS_ERROR),
                 reply_markup=Keyboard.remove())
        return
    context.user_data["parsed"] = parsed

    if not parsed.contains_mwe(todays_mwe):
        reply_to(user,
                 update,
                 user.language.get(Token.SUBMISSION_DOES_NOT_CONTAIN_MWE) %
                 todays_mwe.name,
                 reply_markup=Keyboard.remove())
        return

    # Duplicate check
    # submission_hash = get_submission_hash(doc)
    # if session.query(Submission).filter(Submission.hash == submission_hash).count() > 0:
    #     reply_to(user, update,
    #              get_language_token(user.language, Token.DUPLICATE_SUBMISSION))
    #     return

    # Find MWE position

    submission_mwe_lemmas = parsed.get_mwe_tokens(todays_mwe)
    submission_mwe_lemmas_str = ", ".join(submission_mwe_lemmas[:-1])
    submission_mwe_lemmas_str += "</u></b> %s <b><u>%s" % (user.language.get(
        Token.AND), submission_mwe_lemmas[-1])

    context.user_data["sub_state"] = "choosing_category"
    reply_html(
        user, update,
        user.language.get(Token.DOES_WORDS_FORM_SPECIAL_MEANING) %
        submission_mwe_lemmas_str, Keyboard.submission_category(user.language))
Beispiel #2
0
def ask_for_email(user: User, update: Update, context: CallbackContext):
    mwelog.info(f"Asked for email from {user.username}")
    context.user_data["sub_state"] = "typing_email"
    reply_html(user,
               update,
               user.language.get(Token.ADD_EMAIL_START),
               reply_markup=Keyboard.remove())
Beispiel #3
0
def start_submit_handler(user: User, update: Update,
                         context: CallbackContext) -> None:
    """ Starts the submission cycle for user. """
    todays_mwe = get_todays_mwe(user.language)
    context.user_data["sub_state"] = "typing_example"
    if not user.viewed_submission_help:
        reply_html(user, update,
                   user.language.get(Token.SUBMISSION_HELP_MESSAGE_1))
        time.sleep(7)
        user.viewed_submission_help = True
        update_user(user)
    reply_html(user,
               update,
               user.language.get(Token.PLEASE_ENTER_EXAMPLE) %
               _get_word_list_str_from_mwe(todays_mwe),
               reply_markup=Keyboard.remove())
Beispiel #4
0
def check_email_and_ask_confirmation(user: User, update: Update,
                                     context: CallbackContext):
    email_regex = r'(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)'
    email = update.message.text
    mwelog.info(f"Email got from {user.username}: {email}")
    if not re.match(email_regex, email):
        reply_to(user,
                 update,
                 user.language.get(Token.INVALID_EMAIL),
                 reply_markup=Keyboard.remove())
    else:
        context.user_data["sub_state"] = "confirming_email"
        context.user_data["email"] = email
        reply_html(user,
                   update,
                   user.language.get(Token.CONFIRM_EMAIL) % email,
                   reply_markup=Keyboard.email_verify_keyboard(user.language))
Beispiel #5
0
def start(update: Update, context: CallbackContext):
    user = get_user_from_update(update)

    mwelog.info("User {user_name} started using Mwexpress",
                user_name=user.username,
                user_id=user.id)

    clear_state(context)

    context.bot.send_sticker(update.effective_chat.id, TIPS_FEDORA_STICKER)
    reply_to(user, update, user.language.get(Token.WELCOME_MESSAGE_1),
             Keyboard.remove())
    time.sleep(2)
    reply_to(user, update, user.language.get(Token.WELCOME_MESSAGE_2),
             Keyboard.remove())
    time.sleep(5)
    reply_to(user, update, user.language.get(Token.WELCOME_MESSAGE_3),
             Keyboard.remove())
    time.sleep(3)
    reply_to(user, update, user.language.get(Token.WELCOME_MESSAGE_4),
             Keyboard.remove())
    time.sleep(2)
    reply_to(user, update, user.language.get(Token.WELCOME_MESSAGE_5),
             Keyboard.remove())
    time.sleep(5)
    reply_to(user, update, user.language.get(Token.WELCOME_MESSAGE_6),
             Keyboard.remove())
    time.sleep(10)
    update.message.reply_text(text=user.language.get(Token.WELCOME_MESSAGE_7),
                              parse_mode=ParseMode.HTML,
                              reply_markup=Keyboard.remove())
    time.sleep(5)
    context.bot.send_photo(user.id, open("assets/keyboard_button.png", "rb"))
    time.sleep(0.5)
    reply_to(user, update, user.language.get(Token.WELCOME_MESSAGE_8))
    time.sleep(5)
    reply_to(user, update, user.language.get(Token.DISCLAIMER),
             Keyboard.main(user))