def review_handler(user: User, update: Update, context: CallbackContext): submissions = session.query(Submission).filter( and_(Submission.user_id != user.id, Submission.language == user.language)).all() submissions = sorted(submissions, key=lambda x: x.review_count, reverse=True) submissions = [x for x in submissions if user_not_in_reviewers(x, user)] if len(submissions) > 0: todays_mwe = mwe_helper.get_todays_mwe(user.language) submission = submissions[0] submission_category_messages = { "together": get_language_token(user.language, Tokens.FORM_SPECIAL_MEANING_TOGETHER) % get_mwe_words(todays_mwe), "separated": get_language_token(user.language, Tokens.ARE_WORDS_SEPARATED) % get_mwe_words(todays_mwe), "non-mwe": get_language_token(user.language, Tokens.DOESNT_FORM_SPECIAL_MEANING_TOGETHER) % get_mwe_words(todays_mwe) } context.user_data["state"] = "review" context.user_data['submission'] = submission reply_message = get_language_token( user.language, Tokens.REVIEW_MESSAGE) % ( submission.value, submission_category_messages[submission.category]) update.message.reply_text( reply_message, parse_mode=telegram.ParseMode.MARKDOWN, reply_markup=get_review_type_keyboard_keyboard_markup( user.language)) else: if "state" in context.user_data: del context.user_data["state"] update.message.reply_text( get_language_token(user.language, Tokens.NO_EXAMPLES_TO_REVIEW), parse_mode=telegram.ParseMode.MARKDOWN, reply_markup=get_main_keyboard_markup(user.language))
def submit_handler_3(user: User, update: Update, context: CallbackContext): todays_mwe = mwe_helper.get_todays_mwe(user.language) submit_category_1_submissions = [ get_language_token(user.language, Tokens.FORM_SPECIAL_MEANING_TOGETHER) % get_mwe_words(todays_mwe), get_language_token(user.language, Tokens.DOESNT_FORM_SPECIAL_MEANING_TOGETHER) % get_mwe_words(todays_mwe), ] if update.message.text in submit_category_1_submissions: if update.message.text == submit_category_1_submissions[0]: update.message.reply_text( get_language_token(user.language, Tokens.ARE_WORDS_SEPARATED) % get_mwe_words(todays_mwe), parse_mode=telegram.ParseMode.MARKDOWN, reply_markup=get_submit_category_2_keyboard_markup( user.language, todays_mwe)) context.user_data["state"] = "submit_example_type_2" else: submission = context.user_data["submission"] submission.category = "non-mwe" submission.users_who_reviewed = '' submission.user = user submission.language = user.language submission.mwe = todays_mwe session.add(submission) session.commit() del context.user_data["state"] del context.user_data["submission"] update.message.reply_text( get_language_token(user.language, Tokens.THANKS_FOR_SUBMISSION) % (get_random_congrats_message(user.language), 30), parse_mode=telegram.ParseMode.MARKDOWN, reply_markup=get_main_keyboard_markup(user.language)) else: update.message.reply_text( get_language_token(user.language, Tokens.ENTER_VALID_MWE_CATEGORY_1), parse_mode=telegram.ParseMode.MARKDOWN, reply_markup=get_submit_category_1_keyboard_markup( user.language, todays_mwe))
def submit_handler_4(user: User, update: Update, context: CallbackContext): todays_mwe = mwe_helper.get_todays_mwe(user.language) submit_category_1_submissions = [ get_language_token(user.language, Tokens.WORDS_ARE_TOGETHER) % get_mwe_words(todays_mwe), get_language_token(user.language, Tokens.WORDS_ARE_SEPARATED) % get_mwe_words(todays_mwe), ] if update.message.text in submit_category_1_submissions: submission: Submission = context.user_data["submission"] if update.message.text == get_language_token( user.language, Tokens.WORDS_ARE_TOGETHER) % get_mwe_words(todays_mwe): submission.category = "together" elif update.message.text == get_language_token( user.language, Tokens.WORDS_ARE_SEPARATED) % get_mwe_words(todays_mwe): submission.category = "separated" submission.user = user submission.language = user.language submission.mwe = todays_mwe session.add(submission) session.commit() del context.user_data["submission"] del context.user_data["state"] if update.message.text == get_language_token( user.language, Tokens.WORDS_ARE_TOGETHER) % get_mwe_words(todays_mwe): update.message.reply_text( get_language_token(user.language, Tokens.THANKS_FOR_SUBMISSION) % (get_random_congrats_message(user.language), 10), parse_mode=telegram.ParseMode.MARKDOWN, reply_markup=get_main_keyboard_markup(user.language)) elif update.message.text == get_language_token( user.language, Tokens.WORDS_ARE_SEPARATED) % get_mwe_words(todays_mwe): update.message.reply_text( get_language_token(user.language, Tokens.THANKS_FOR_SUBMISSION) % (get_random_congrats_message(user.language), 10), parse_mode=telegram.ParseMode.MARKDOWN, reply_markup=get_main_keyboard_markup(user.language)) else: update.message.reply_text( get_language_token(user.language, Tokens.ENTER_VALID_MWE_CATEGORY_1), parse_mode=telegram.ParseMode.MARKDOWN, reply_markup=get_submit_category_2_keyboard_markup( user.language, todays_mwe))
def get_submit_category_2_keyboard_markup(language: str, mwe: Mwe): submit_category_2_keyboard = [ [get_language_token(language, Tokens.WORDS_ARE_TOGETHER) % get_mwe_words(mwe)], [get_language_token(language, Tokens.WORDS_ARE_SEPARATED) % get_mwe_words(mwe)], ] return telegram.ReplyKeyboardMarkup(submit_category_2_keyboard)
def get_submit_category_1_keyboard_markup(language: str, mwe: Mwe): submit_category_1_keyboard = [ [get_language_token(language, Tokens.FORM_SPECIAL_MEANING_TOGETHER) % get_mwe_words(mwe)], [get_language_token(language, Tokens.DOESNT_FORM_SPECIAL_MEANING_TOGETHER) % get_mwe_words(mwe)], ] return telegram.ReplyKeyboardMarkup(submit_category_1_keyboard)