Esempio n. 1
0
def todo_start(message):
    user_registered_status = utils.db.add_user(message, COLLECTION)
    user_first_name = message.from_user.first_name
    if not user_registered_status:
        sticker = open(ui.sticker_path['returned'], 'rb')
        bot.send_sticker(message.from_user.id, sticker)
        quantity = utils.todo.quantity_tasks(utils.db.user_get_tasks(message, COLLECTION))
        text = ui.dialogue['user_returned'] \
            .format(user_first_name, ui.menu_list_items['important'].replace('й', 'х'),
                    quantity['important'],
                    ui.menu_list_items['ordinary'].replace('й', 'x'),
                    quantity['ordinary'])
        bot.send_message(message.from_user.id, text, reply_markup=MENU_MAIN,
                         parse_mode='HTML')
    else:
        bot_name = ui.bot_name
        sticker = open(ui.sticker_path['hello'], 'rb')
        bot.send_sticker(message.from_user.id, sticker)
        text = ui.dialogue['welcome_text'].format(user_first_name, bot_name)
        bot.send_message(message.from_user.id, text, reply_markup=MENU_MAIN)
    notifi_data = utils.db.user_get_notifications(message, COLLECTION)
    if notifi_data['notifications']:
        schedule.clear(message.from_user.id)
        job = utils.todo.run_notifi(message, notifi_data['notification_interval'])
    else:
        schedule.clear(message.from_user.id)
Esempio n. 2
0
def todo_main(message):
    if message.chat.type == 'private':
        if message.text == ui.menu_main_items['help']:
            bot.send_message(message.from_user.id,
                             ui.help_todo['short_info'],
                             parse_mode='HTML')
            text = ui.dialogue['more_info'].format(
                message.from_user.first_name)
            bot.send_message(message.from_user.id,
                             text,
                             reply_markup=BTN_MORE_HELP)
        if message.text == ui.menu_main_items['add']:
            text = ui.dialogue['change_list']
            bot.send_message(message.from_user.id,
                             text,
                             reply_markup=MENU_CASE)
        if message.text == ui.menu_list_items['important']:
            list_name = list(ui.menu_list_items.keys())[0]
            text = ui.dialogue['task_desc']
            notification_before_task(message, text)
            bot.register_next_step_handler(message, add_task, list_name,
                                           COLLECTION)
        if message.text == ui.menu_list_items['ordinary']:
            list_name = list(ui.menu_list_items.keys())[1]
            text = ui.dialogue['task_desc']
            notification_before_task(message, text)
            bot.register_next_step_handler(message, add_task, list_name,
                                           COLLECTION)
        if message.text == ui.menu_list_items['back']:
            sticker = open(ui.sticker_path['main'], 'rb')
            bot.send_sticker(message.from_user.id, sticker)
            text = ui.dialogue['main_menu']
            bot.send_message(message.from_user.id,
                             text,
                             reply_markup=MENU_MAIN)
        if message.text == ui.menu_main_items['view']:
            show_tasks(message, COLLECTION)
        if message.text == ui.menu_main_items['edit']:
            edit_tasks(message, COLLECTION)
        if message.text == ui.menu_main_items['notifi']:
            text = ui.dialogue['notification_settings'].format(
                ui.different_signs['gear'])
            bot.send_message(message.from_user.id,
                             text,
                             reply_markup=MENU_NOTIFI)
        if message.text == ui.menu_settings_notification['notification_off']:
            notifi_change_status(message, COLLECTION, False)
            todo_start(message)
        if message.text == ui.menu_settings_notification[
                'notification_interval']:
            text = ui.interval_warning['desc_warning'].format(min=MIN_VALUE,
                                                              max=MAX_VALUE)
            bot.send_message(message.from_user.id, text)
            pre_interval_notifications(message)
            bot.register_next_step_handler(message, interval_change)