def _send_submission_to_review(user: User, update: Update, context: CallbackContext): if not user.viewed_review_help: reply_to(user, update, user.language.get(Token.REVIEW_HELP_MESSAGE_1)) time.sleep(4) reply_to(user, update, user.language.get(Token.REVIEW_HELP_MESSAGE_2)) time.sleep(4) user.viewed_review_help = True update_user(user) todays_mwe = get_todays_mwe(user.language) submissions = get_submissions_to_review(todays_mwe, user) if len(submissions) > 0: submission: Submission = submissions[0] context.user_data["submission"] = submission if "review_count" not in context.user_data: context.user_data["review_count"] = 0 parsed = parser.parse(submission.value, submission.mwe) review_example = submission.value for index in reversed(sorted(submission.mwe_indices)): start_index = parsed.token_positions[index][0] end_index = parsed.token_positions[index][1] review_example = review_example[: end_index] + "</u></b>" + review_example[ end_index:] review_example = review_example[: start_index] + "<b><u>" + review_example[ start_index:] if submission.category == SubmissionCategory.POSITIVE_SEPARATED or \ submission.category == SubmissionCategory.POSITIVE_TOGETHER: review_question = user.language.get(Token.REVIEW_QUESTION_POSITIVE) \ % (review_example, _get_word_list_str_from_submission(submission)) reply_html(user, update, review_question, Keyboard.review_keyboard(user.language)) else: review_question = user.language.get(Token.REVIEW_QUESTION_NEGATIVE) \ % (review_example, _get_word_list_str_from_submission(submission)) reply_html(user, update, review_question, Keyboard.review_keyboard(user.language)) else: if "review_count" in context.user_data: reply_to(user, update, user.language.get(Token.NO_SUB_LEFT_TO_REVIEW), Keyboard.main(user)) else: reply_to(user, update, user.language.get(Token.NO_SUBMISSIONS), Keyboard.main(user)) clear_state(context) unmute_user(user.id) _safe_delete_context_data(context, "submission") _safe_delete_context_data(context, "review_count")
def _review_answer_handler(user: User, update: Update, context: CallbackContext): mute_user(user.id) available_inputs = [ user.language.get(Token.AGREE_NICE_EXAMPLE), user.language.get(Token.DO_NOT_LIKE_EXAMPLE), user.language.get(Token.REPORT_SUBMISSION), user.language.get(Token.QUIT_REVIEWING) ] if update.message.text not in available_inputs: reply_to(user, update, user.language.get(Token.PLEASE_ENTER_VALID_REVIEW), Keyboard.review_keyboard(user.language)) return submission = context.user_data["submission"] context.user_data["review_count"] += 1 if update.message.text == user.language.get(Token.AGREE_NICE_EXAMPLE): add_review(user, submission, ReviewCategory.LIKE) reply_to( user, update, user.language.get(Token.THANKS_FOR_REVIEW) % (get_random_congrats_message( user.language), submission_scores.get_review_score())) _process_review_achievements(user, update) notification_manager.send_someone_liked_your_example( submission.user, context) scoreboard.iterate(update, context) elif update.message.text == user.language.get(Token.DO_NOT_LIKE_EXAMPLE): add_review(user, submission, ReviewCategory.DISLIKE) reply_to( user, update, user.language.get(Token.THANKS_FOR_REVIEW) % (get_random_congrats_message( user.language), submission_scores.get_review_score())) _process_review_achievements(user, update) scoreboard.iterate(update, context) elif update.message.text == user.language.get(Token.REPORT_SUBMISSION): add_review(user, submission, ReviewCategory.SKIP) reply_to(user, update, user.language.get(Token.REPORT_SUBMISSION_REPLY)) context.bot.send_message( mwexpress_config.moderator, f"Someone reported this submission: {submission.value}\n" f"Flag submission: /flag{submission.id}, " f"ban user: /ban{submission.user.id}") _process_review_achievements(user, update) scoreboard.iterate(update, context) else: unmute_user(user.id) reply_to(user, update, user.language.get(Token.REVIEW_CANCELLED), Keyboard.main(user)) _safe_delete_context_data(context, "submission") clear_state(context) return _send_submission_to_review(user, update, context)