def todays_mwe_handler(user: User, update: Update, context: CallbackContext): todays_mwe = mwe_helper.get_todays_mwe(user.language) update.message.reply_text( get_language_token(user.language, Tokens.TODAYS_MWE_REPLY_TEXT) % (todays_mwe.name, todays_mwe.meaning), parse_mode=telegram.ParseMode.MARKDOWN, reply_markup=get_main_keyboard_markup(user.language))
def submit_handler(user: User, update: Update, context: CallbackContext): todays_mwe = mwe_helper.get_todays_mwe(user.language) update.message.reply_text( get_language_token(user.language, Tokens.PLEASE_ENTER_EXAMPLE) % todays_mwe.name, parse_mode=telegram.ParseMode.MARKDOWN, reply_markup=telegram.ReplyKeyboardRemove()) context.user_data["state"] = "submit_example"
def add_review_by_user(user: User, submisson: Submission, review_type: int) -> None: review = Review(user=user, submission=submisson, review_type=review_type, mwe=mwe_helper.get_todays_mwe(user.language)) session.add(review) session.commit() pass
def add_submission_by_user(user: User, subm: str, cat: str, lang: str) -> Submission: submission = Submission(user=user, value=subm, category=cat, language=lang, mwe=mwe_helper.get_todays_mwe(lang)) session.add(submission) session.commit() return submission
def submit_handler_2(user: User, update: Update, context: CallbackContext): todays_mwe = mwe_helper.get_todays_mwe(user.language) submission = Submission(value=update.message.text) context.user_data["submission"] = submission context.user_data["state"] = "submit_example_type_1" update.message.reply_text( get_language_token(user.language, Tokens.SPECIAL_MEANING) % todays_mwe.name, 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 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 review_handler_2(user: User, update: Update, context: CallbackContext): review_types = [ get_language_token(user.language, Tokens.AGREE_NICE_EXAMPLE), get_language_token(user.language, Tokens.DO_NOT_LIKE_EXAMPLE), get_language_token(user.language, Tokens.SKIP_THIS_ONE), get_language_token(user.language, Tokens.QUIT_REVIEWING) ] user = get_user_from_update(update) if update.message.text in review_types: submission = context.user_data["submission"] todays_mwe = mwe_helper.get_todays_mwe(user.language) points_earned_for_submission = { "together": 10, "separated": 20, "non-mwe": 30 } if update.message.text == review_types[0]: points_earned = points_earned_for_submission[submission.category] reply_message = get_language_token( user.language, Tokens.SOMEONE_LOVED_YOUR_EXAMPLE) % ( get_random_congrats_message(user.language), points_earned) send_message_to_user(submission.user, reply_message) review = Review(user=user, mwe=todays_mwe, submission=submission, review_type=POSITIVE_REVIEW) session.add(review) session.commit() review_handler(user, update, context) elif update.message.text == review_types[1]: review = Review(user=user, mwe=todays_mwe, submission=submission, review_type=NEGATIVE_REVIEW) session.add(review) session.commit() review_handler(user, update, context) elif update.message.text == review_types[2]: review = Review(user=user, mwe=todays_mwe, submission=submission, review_type=NEUTRAL_REVIEW) session.add(review) session.commit() review_handler(user, update, context) elif update.message.text == review_types[3]: del context.user_data["submission"] del context.user_data["state"] update.message.reply_text( get_language_token(user.language, Tokens.THANKS_FOR_CONTRIBUTION), parse_mode=telegram.ParseMode.MARKDOWN, reply_markup=get_main_keyboard_markup(user.language)) else: update.message.reply_text( get_language_token(user.language, Tokens.PLEASE_ENTER_VALID_REVIEW), parse_mode=telegram.ParseMode.MARKDOWN, reply_markup=get_review_type_keyboard_keyboard_markup( user.language))