Exemple #1
0
def reminder_confirm_for_delete(bot: Bot, update: Update,
                                user_data: dict) -> str:
    """The function asks for confirmation to delete the reminder.
 
    :param bot: Bot
    :param update: Update
    :param user_data: User data
    :return: The function sends a message to the user with list of reminers. 
    """
    user_data["number_reminder_for_delete"] = update.message.text
    reminder_for_delete = reminder_get_from_database(
        user_data["number_reminder_for_delete"])
    if reminder_for_delete.get('id') is None:
        text_message = settings.NO_REMIND
        update.message.reply_text(text_message,
                                  reply_markup=reminder_keyboard())
    else:
        description_reminder_for_delete = settings.REMINDER_LIST_MESSAGE.format(
            reminder_for_delete.get('id'),
            reminder_for_delete.get('date_remind'),
            reminder_for_delete.get('comment'),
            reminder_for_delete.get('status'))
        text_message = settings.CONFIRM_REMIND_FOR_DELETE.format(
            description_reminder_for_delete)
        update.message.reply_text(
            text_message, reply_markup=remind_confirm_for_delete_keyboard())

        return "reminder_commit_for_delete"
Exemple #2
0
def reminder_skip_comment(bot: Bot, update: Update,
                          user_data: dict) -> Union[str, ConversationHandler]:
    """The function skips adding a comment to the reminder 
       and writes reminders to the database.
    
    The function sends a message to the user with reminder parameters and 
    ends the dialog or sends an error and asks to enter reminder parameters.
    
    :param bot: Bot
    :param update: Update
    :param user_data: User data
    :return: The function sends a message to the user with reminer or error. 
    """
    user_data['comment'] = settings.NO_COMMENT
    if reminder_add_new_to_database(update.effective_user.id,
                                    user_data['comment'], user_data['date'],
                                    settings.REMINDER_STATUS_ON_ADD):
        text_message = settings.COMMIT_WITH_COMMENT.format(
            user_data["date"], user_data["comment"],
            settings.TRUE_COMMIT_STATUS)
        text_message = settings.COMMIT_WITHOUT_COMMENT
        update.message.reply_text(text_message,
                                  reply_markup=reminder_keyboard())
        return ConversationHandler.END
    text_message = settings.ADD_ERROR
    update.message.reply_text(text_message,
                              reply_markup=reminder_add_date_keyboard())
    return "reminder_add_date"
Exemple #3
0
def reminder_list(bot: Bot, update: Update, user_data: dict) -> Message:
    """The function forms a list of reminders and sends it to the user.
 
    :param bot: Bot
    :param update: Update
    :param user_data: User data
    :return: The function sends a message to the user with list of reminers. 
    """
    text_message = ''
    list_reminders = reminder_list_from_database(update.effective_user.id)
    text_message = reminders_list_message(list_reminders)
    update.message.reply_text(text_message, reply_markup=reminder_keyboard())
Exemple #4
0
def dontknow(bot: Bot, update: Update, user_data: dict) -> ConversationHandler:
    """The function interrupts the dialogue and sends a message to the 
       user about the unknown command.

    :param bot: Bot
    :param update: Update
    :param user_data: User data
    :return: The function sends a message to the user about 
             the unknown command. 
    """
    update.message.reply_text(settings.DONTKNOW_TEXT,
                              reply_markup=reminder_keyboard())

    return ConversationHandler.END
Exemple #5
0
def reminder_cancel_for_delete(bot: Bot, update: Update,
                               user_data: dict) -> ConversationHandler:
    """The function sends a message to the user in case of 
       cancellation of the reminder.
 
    :param bot: Bot
    :param update: Update
    :param user_data: User data
    :return: The function sends a message to the user with cancellation. 
    """
    update.message.reply_text(settings.CANCEL_REMIND_FOR_DELETE,
                              reply_markup=reminder_keyboard())

    return ConversationHandler.END
Exemple #6
0
def greet_user(bot: Bot, update: Update, user_data: dict) -> Message:
    """Welcome function. Called upon message: /start
    :param bot: Bot
    :param update: Update
    :param user_data: User data
    :return: If the user is in the database, the function sends a 
             welcome message to the user indicating his name or 
             a welcome message with a proposal to be added to 
             the database. 
    """
    if get_information_about_user(update.effective_user.id) is None:
        message_text = settings.JOIN_TEXT
        update.message.reply_text(message_text,
                                  reply_markup=starting_keyboard())
    else:
        message_text = settings.JOIN_TEXT_FOR_USER.format(
            update.effective_user.first_name)
        update.message.reply_text(message_text,
                                  reply_markup=reminder_keyboard())
Exemple #7
0
def join_user(bot: Bot, update: Update, user_data: dict) -> Message:
    """The function is adding user in the database.
    :param bot: Bot
    :param update: Update
    :param user_data: User data
    :return: If the user is not in the database, the function add
             user to database and sends a greet message to the user.
             If an error occurs during adding, an error message 
             is sent to the user. 
    """
    if add_user_to_database(update.effective_user.id,
                            update.effective_user.first_name,
                            update.effective_user.last_name,
                            update.effective_user.username,
                            update.message.chat_id):
        text_message = settings.ADD_USER
    else:
        text_message = settings.ADD_ERROR

    update.message.reply_text(text_message, reply_markup=reminder_keyboard())
Exemple #8
0
def reminder_commit_for_delete(bot: Bot, update: Update,
                               user_data: dict) -> ConversationHandler:
    """In case of successful removal of the reminder from the database, 
       the function generates a message to the user with confirmation; 
       if the removal was unsuccessful, an error message is sent.
 
    :param bot: Bot
    :param update: Update
    :param user_data: User data
    :return: The function sends a message to the user with 
             confirmation of deletion or error.. 
    """
    if reminder_delete(user_data["number_reminder_for_delete"]):
        text_message = settings.REMOVE_REMIND_FOR_DELETE
    else:
        text_message = settings.ADD_ERROR

    update.message.reply_text(text_message, reply_markup=reminder_keyboard())

    return ConversationHandler.END