def send_quest_image_start(update, context):
    ReusableComponents.log_command_accessed_timing(update)

    user_id = update.message.from_user.id
    username = update.message.from_user.username

    if not user_is_a_member(update):
        LoggerManager.general_logs(
            f"User {username} ({user_id}) is not a member!")

        update.message.reply_text(MessageTemplates.new_user_found_message)

        return ConversationHandler.END

    list_of_available_quests = get_list_of_available_quests_for_the_week()

    if len(list_of_available_quests) <= 0:
        update.message.reply_text(MessageTemplates.error_message)

        ReusableComponents.prompt_user_next_action(update)

        return ConversationHandler.END

    context.chat_data["quest_titles"] = list_of_available_quests

    update.message.reply_text(
        MessageTemplates.send_quest_image_message(list_of_available_quests))

    return 'QuestDescription'
def display_quest_description(update, context):
    user_choice = update.message.text

    if is_invalid_user_choice(user_choice, context):
        update.message.reply_text(MessageTemplates.invalid_response_message)
        return 'QuestDescription'

    # Get quest description from database
    parsed_user_choice = int(user_choice) - 1
    selected_quest_title = context.chat_data["quest_titles"][
        parsed_user_choice][0]
    quest_description = QuestManager.get_list_of_available_quests_for_the_week(
        selected_quest_title)

    if not quest_description:
        username = update.message.from_user.username
        user_id = update.message.from_user.id

        LoggerManager.general_logs(
            f"Error occurred while {username} ({user_id}) is viewing quest description"
        )

        return ConversationHandler.END

    update.message.reply_text(MessageTemplates.gen_quest_description_message(
        selected_quest_title, quest_description),
                              disable_web_page_preview=True)

    return 'ImageResponse'
Example #3
0
def send_voucher_to_user(update, reward_of_the_day):
    voucher_path = reward_of_the_day[1]
    voucher_info = get_voucher_info(reward_of_the_day)

    caption_to_send = MessageTemplates.gen_voucher_info(voucher_info)

    ReusableComponents.dispatch_voucher(update, voucher_path, caption_to_send)
def broadcast_message_to_users(context, broadcast_message, target_users_list):
    blocked_users_list, unreachable_users_list, unexpected_error_occurred_users_list = [], [], []

    for user_id in target_users_list:
        try:
            if user_id == EMPTY_USER_ID:
                continue

            context.bot.send_message(chat_id=user_id, text=broadcast_message)

        except telegram.error.Unauthorized:
            blocked_users_list.append(user_id)

        except telegram.error.BadRequest:
            unreachable_users_list.append(user_id)

        except Exception as e:
            error_message = MessageTemplates.gen_error_message_while_sending_to_user(
                user_id)

            LoggerManager.exception_logs(e)
            LoggerManager.exception_logs(error_message)

            unexpected_error_occurred_users_list.append(user_id)

    error_occurred_while_sending_to_users_dict = SharedFunctions.gen_broadcast_error_for_users_report(
        blocked_users_list, unreachable_users_list,
        unexpected_error_occurred_users_list)

    return error_occurred_while_sending_to_users_dict
def inform_exchange_result_to_user(update, user_selected_voucher):
    voucher_info = get_voucher_info(user_selected_voucher)

    caption_to_send = MessageTemplates.gen_voucher_info(voucher_info)

    voucher_path = user_selected_voucher[3]

    ReusableComponents.dispatch_voucher(update, voucher_path, caption_to_send)
Example #6
0
def send_message_to_referrer(context, referrer_id, referee_username):
    LoggerManager.general_logs(
        f"Sending notification to user {referrer_id} about referring now!")

    referrer_message_to_send = MessageTemplates.gen_referrer_bonus_message(
        referee_username)

    context.bot.send_message(chat_id=referrer_id,
                             text=referrer_message_to_send)
def inform_sender_no_of_users_to_broadcast(update, target_users_list):
    length_of_target_users = len(target_users_list)

    LoggerManager.general_logs(
        f"Broadcasting message to {length_of_target_users} user(s) now")

    message_to_inform_sender = MessageTemplates.gen_message_to_inform_sender(
        length_of_target_users)

    update.message.reply_text(message_to_inform_sender)
def send_user_profile_message(update, dict_of_vouchers_owned_by_user, user_snapcoin_amount):
    if not dict_of_vouchers_owned_by_user:
        dict_of_vouchers_owned_by_user = {}

    expired_voucher_message, message_to_send = MessageTemplates.gen_user_profile_message(dict_of_vouchers_owned_by_user,
                                                                                         user_snapcoin_amount)

    if expired_voucher_message:
        update.message.reply_text(expired_voucher_message)

    update.message.reply_text(message_to_send)
def send_confirmation_voucher_to_user(update, user_selected_voucher):
    chosen_voucher_image_path = user_selected_voucher[3]
    voucher_info = get_voucher_info(user_selected_voucher)

    caption_to_send = MessageTemplates.gen_voucher_info(voucher_info, True)

    ReusableComponents.dispatch_voucher(update,
                                        chosen_voucher_image_path,
                                        caption_to_send)

    update.message.reply_text(MessageTemplates.confirm_claim_message)
def send_vouchers_to_user(update, vouchers_in_promo_code):
    for voucher_info in vouchers_in_promo_code:
        voucher_path = voucher_info[3]

        voucher_info_to_send = get_voucher_info(voucher_info)

        caption_to_send = MessageTemplates.gen_voucher_info(
            voucher_info_to_send)

        ReusableComponents.dispatch_voucher(update, voucher_path,
                                            caption_to_send)
def send_exchangeable_message_to_user(update, context,
                                      exchangeable_voucher_list):
    user_id = str(update.message.from_user.id)

    context.chat_data.update({
        f'{user_id}': {
            'exchangeable_vouchers_record': exchangeable_voucher_list
        }
    })

    exchangeable_vouchers_message = MessageTemplates.gen_exchangeable_vouchers_message(
        exchangeable_voucher_list)

    update.message.reply_text(exchangeable_vouchers_message)
def inform_new_user_reward_received(update, user_login_details, reward_of_the_day):
    if not reward_of_the_day:
        update.message.reply_text(MessageTemplates.error_message)
        return

    if isinstance(reward_of_the_day, tuple):
        SharedFunctions.send_voucher_to_user(update, reward_of_the_day)

        return

    no_of_days_as_new_user = user_login_details[0][0]

    message_to_send = MessageTemplates.gen_new_user_coin_message(reward_of_the_day,
                                                                 no_of_days_as_new_user)

    update.message.reply_text(message_to_send)
def generate_start_command_message(update, result):
    user_id = update.message.from_user.id
    username = update.message.from_user.username

    if len(result) == EMPTY_LIST:
        LoggerManager.general_logs(
            f"User: {username} ({user_id}) is not a member. Redirecting to registration now."
        )

        return update.message.reply_text(
            MessageTemplates.new_user_found_message)

    LoggerManager.general_logs(f"User: {username} ({user_id}) is a member.")

    message_to_send = MessageTemplates.welcome_back_message(
        update.message.from_user.username)

    update.message.reply_text(message_to_send,
                              disable_web_page_preview=True,
                              reply_markup=KeyboardTemplates.start_keyboard)
def referral_code_instruction_start(update, context):
    ReusableComponents.log_command_accessed_timing(update)

    user_id = update.message.from_user.id
    username = update.message.from_user.username

    referral_code = get_user_referral_code(user_id)

    if not referral_code:
        LoggerManager.general_logs(
            f"User {username} ({user_id} is not a member!")

        update.message.reply_text(MessageTemplates.new_user_found_message)

        return

    update.message.reply_text(MessageTemplates.referral_code_info_message)
    update.message.reply_text(
        MessageTemplates.gen_referral_code_instruction_template(referral_code),
        disable_web_page_preview=True)

    ReusableComponents.prompt_user_next_action(update)
Example #15
0
def send_registration_result(update, context, registration_result):
    user_id = update.message.from_user.id
    username = update.message.from_user.username

    if not registration_result:
        LoggerManager.exception_logs(
            f"Error occurred while registering user {username} ({user_id})!")

        message_to_send = MessageTemplates.error_message

        update.message.reply_text(message_to_send)

        return

    LoggerManager.general_logs(
        f"User {username} ({user_id}) registered successfully!")

    message_to_send = MessageTemplates.gen_welcome_new_user_message(
        username)

    update.message.reply_text(message_to_send)

    send_new_user_bonus_notification(context, user_id)
def inform_user_claim_successful(update, user_selected_voucher_title):
    message_to_send = MessageTemplates.gen_claimed_message(
        user_selected_voucher_title)

    update.message.reply_text(message_to_send)
def send_confirmation_voucher_to_user(update, user_selected_voucher):
    chosen_voucher_title = user_selected_voucher[2]
    message_to_send = MessageTemplates.gen_user_chosen_voucher_message(
        chosen_voucher_title)

    update.message.reply_text(message_to_send)
def send_broadcast_report_to_sender(
        update, error_occurred_while_sending_to_users_dict):
    message_to_send_to_sender = MessageTemplates.gen_broadcast_report(
        error_occurred_while_sending_to_users_dict)

    update.message.reply_text(message_to_send_to_sender)