def confirm_email(user: User, update: Update, context: CallbackContext): available_inputs = [ user.language.get(Token.YES), user.language.get(Token.NO), user.language.get(Token.CANCEL) ] message = update.message.text if message not in available_inputs: reply_to(user, update, user.language.get(Token.ENTER_VALID_COMMAND), reply_markup=Keyboard.email_verify_keyboard(user.language)) return if message == user.language.get(Token.YES): email = context.user_data["email"] user.email = email update_user(user) _clear_context(context) reply_html(user, update, user.language.get(Token.EMAIL_SET) % email, Keyboard.main(user)) mwelog.info(f"{user.username} confirms {email} is correct") try: context.bot.send_message( mwexpress_config.moderator, f"{user.username} set their email as: {email}") except Exception as ex: mwelog.exception(ex) else: _clear_context(context) reply_to(user, update, user.language.get(Token.EMAIL_CANCELLED), Keyboard.main(user))
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))