Beispiel #1
0
def set_time_remind(message):
    task = util.get_task_by_id(
        EDIT_TASK_REMIND[message.from_user.id]['task_id'])
    if message.text == button_text['closed']:
        task = util.update_task(
            task_id=EDIT_TASK_REMIND[message.from_user.id]['task_id'],
            time=EDIT_TASK_REMIND[message.from_user.id]['time'])
        del EDIT_TASK_REMIND[message.from_user.id]
        bot.send_message(message.from_user.id,
                         'Время установлено',
                         reply_markup=mark_conf.menu())
        bot.send_message(message.from_user.id,
                         timer_task(task),
                         reply_markup=mark_conf.set_remind_task(task),
                         parse_mode='HTML')
    elif message.text == button_text['cancel']:
        bot.send_message(message.from_user.id,
                         msg_text['cancel_do'],
                         reply_markup=mark_conf.menu(),
                         parse_mode='HTML')
        bot.send_message(message.from_user.id,
                         create_task_text(task),
                         reply_markup=mark_conf.task_menu(task),
                         parse_mode='HTML')
        del EDIT_TASK_REMIND[message.from_user.id]

    else:
        msg = bot.send_message(
            message.from_user.id,
            f'Нажмите на кнопку <b>{button_text["closed"]}</b>',
            parse_mode='HTML')
        bot.register_next_step_handler(msg, set_time_remind)
Beispiel #2
0
def input_new_tag_name(message, tag_id):
    try:
        bot.delete_message(message.from_user.id, message.message_id - 1)
    except:
        pass
    try:
        bot.delete_message(message.from_user.id, message.message_id)
    except:
        pass
    if message.text == button_text['cancel']:
        bot.send_message(message.from_user.id,
                         msg_text['cancel_do'],
                         reply_markup=mark_conf.menu())
        tag = util.get_tag_by_id(tag_id)
    else:
        if tag_id == 0:
            bot.send_message(message.from_user.id,
                             msg_text['saved_tag'],
                             reply_markup=mark_conf.menu())
            all_tags = util.get_user_tags(message.from_user.id, only_user=None)
            bot.send_message(message.from_user.id,
                             'Выберите тег',
                             reply_markup=mark_conf.all_tags(all_tags))
            return

        tag = util.update_tag(message.text, tag_id)
        bot.send_message(message.from_user.id,
                         msg_text['saved_tag'],
                         reply_markup=mark_conf.menu())

    bot.send_message(message.from_user.id,
                     create_tag_text(tag),
                     reply_markup=mark_conf.get_tag_page(tag_id))
Beispiel #3
0
def input_fullname(message):
    if message.text == button_text['cancel']:
        bot.send_message(message.from_user.id,
                         msg_text['cancel_do'],
                         reply_markup=mark_conf.menu())
        return

    util.update_user_fullname(message.from_user.id, message.text)
    bot.send_message(message.from_user.id,
                     'Имя изменено',
                     reply_markup=mark_conf.menu())
Beispiel #4
0
def message_text_handler(message):
    print('Text: ', message.text)
    if message.text == button_text['add_record']:
        msg = bot.send_message(message.from_user.id,
                               msg_text['input_task_name'],
                               reply_markup=mark_conf.create_custom_button(
                                   button_text['cancel']))
        bot.register_next_step_handler(msg, input_task_name)
    elif message.text == button_text['my_record']:
        task_list = util.get_task_list_by_user(message.from_user.id,
                                               not_closed=True)
        if task_list:
            bot.send_message(message.from_user.id,
                             msg_text['chose_task'],
                             reply_markup=mark_conf.task_list_menu(task_list))
        else:
            bot.send_message(message.from_user.id,
                             msg_text['task_not_found'],
                             reply_markup=mark_conf.menu())

    elif message.text == button_text['archive_record']:
        task_list = util.get_task_list_by_user(message.from_user.id)
        msg = bot.send_message(message.from_user.id,
                               msg_text['search_by_task'],
                               reply_markup=mark_conf.search_by_task())
        bot.register_next_step_handler(msg, search_task_name)

        bot.send_message(message.from_user.id,
                         msg_text['chose_task'],
                         reply_markup=mark_conf.task_list_menu(task_list))
    elif message.text == button_text['settings']:
        bot.send_message(message.from_user.id,
                         msg_text['settings'],
                         reply_markup=mark_conf.settings_menu())
    elif message.text == button_text['tags']:
        all_tags = util.get_user_tags(message.from_user.id, only_user=None)
        bot.send_message(message.from_user.id,
                         'Выберите тег',
                         reply_markup=mark_conf.all_tags(all_tags))
    elif message.text == button_text['change_name']:
        msg = bot.send_message(message.from_user.id,
                               msg_text['input_fullname'],
                               reply_markup=mark_conf.create_custom_button(
                                   button_text['cancel']))
        bot.register_next_step_handler(msg, input_fullname)
    else:
        bot.send_message(message.from_user.id,
                         msg_text['restart_system'],
                         reply_markup=mark_conf.menu())
Beispiel #5
0
def tag_data(message):
    try:
        bot.delete_message(message.from_user.id, message.message_id - 1)
    except:
        pass
    # Если несколько раз нажали на кнопку
    if message.from_user.id not in TASK_TAGS:
        return

    if message.text == button_text['closed']:
        bot.send_message(message.from_user.id,
                         'Новые теги сохраенын',
                         reply_markup=mark_conf.menu())
        util.add_tag_to_task(TASK_TAGS[message.from_user.id]['task_id'],
                             TASK_TAGS[message.from_user.id]['selected_tags'])
        task = util.get_task_by_id(TASK_TAGS[message.from_user.id]['task_id'])
        bot.send_message(message.from_user.id,
                         create_task_text(task),
                         reply_markup=mark_conf.task_menu(task),
                         parse_mode='HTML')
        try:
            del TASK_TAGS[message.from_user.id]
        except Exception as e:
            print('Error in delete TASK_TAGS[message.from_user.id] (1): ', e)

    elif message.text == button_text['cancel']:
        bot.send_message(message.from_user.id,
                         msg_text['cancel_do'],
                         reply_markup=mark_conf.menu())
        task = util.get_task_by_id(TASK_TAGS[message.from_user.id]['task_id'])
        bot.send_message(message.from_user.id,
                         create_task_text(task),
                         reply_markup=mark_conf.task_menu(task),
                         parse_mode='HTML')
        try:
            del TASK_TAGS[message.from_user.id]
        except Exception as e:
            print('Error in delete TASK_TAGS[message.from_user.id] (2): ', e)

    elif not TASK_TAGS[message.from_user.id]['selected_tags']:
        msg = bot.send_message(message.from_user.id,
                               'Выберите хотя бы один тег')
        bot.register_next_step_handler(msg, tag_data)
    else:
        bot.send_message(
            message.from_user.id,
            f'Нажмите на кнопку {button_text["closed"]} или {button_text["cancel"]}'
        )
Beispiel #6
0
def input_task_name(message):
    if message.text == button_text['cancel']:
        bot.send_message(message.from_user.id,
                         msg_text['cancel_create_task'],
                         reply_markup=mark_conf.menu())
        return

    task_id = util.add_task(message.from_user.id, message.text)
    task = util.get_task_by_id(task_id)
    bot.send_message(message.from_user.id,
                     'Задача создана',
                     reply_markup=mark_conf.menu())
    bot.send_message(message.from_user.id,
                     create_task_text(task),
                     reply_markup=mark_conf.task_menu(task),
                     parse_mode='HTML')
Beispiel #7
0
def currency(call):
    current_currency = call.data[4:]  # Выбранная валюта
    chat = call.message.chat
    bot.edit_message_text(base.get_text(chat.id, 'operations'),
                          chat.id,
                          call.message.message_id,
                          reply_markup=markups.menu())
Beispiel #8
0
def back(msg):
    bot.send_message(msg.chat.id,
                     "Операции покупки или продажи",
                     reply_markup=markups.addWelcome())
    bot.send_message(msg.chat.id,
                     base.get_text(msg.chat.id, "operations"),
                     reply_markup=markups.menu())
Beispiel #9
0
def message_start_handler(message):
    if util.check_user_in_bd(message.from_user.id):
        bot.send_message(message.from_user.id,
                         msg_text['restart_system'],
                         reply_markup=mark_conf.menu())
    else:
        bot.send_message(message.from_user.id, msg_text['welcome'])
        util.add_user_in_bd(message.from_user.id, message.from_user.username)
Beispiel #10
0
def search_task_name(message):
    if message.text == button_text['cancel']:
        bot.send_message(message.from_user.id,
                         'Отмена поиска',
                         reply_markup=mark_conf.menu())

        msg = bot.send_message(message.from_user.id,
                               msg_text['search_by_task'],
                               reply_markup=mark_conf.search_by_task())
        bot.register_next_step_handler(msg, search_task_name)
        print('sya')
        return

    task_list = util.get_task_list_by_user_where_name(message.from_user.id,
                                                      message.text)
    if task_list:
        bot.send_message(message.from_user.id,
                         msg_text['chose_task'],
                         reply_markup=mark_conf.task_list_menu(task_list))
    else:
        bot.send_message(message.from_user.id,
                         msg_text['task_not_found'],
                         reply_markup=mark_conf.menu())
Beispiel #11
0
def change_task_name(message):
    if message.text == button_text['cancel']:
        bot.send_message(message.from_user.id, 'Отмена изменения')

        task_list = util.get_task_list_by_user(message.from_user.id,
                                               not_closed=True)
        if task_list:
            bot.send_message(message.from_user.id,
                             msg_text['chose_task'],
                             reply_markup=mark_conf.task_list_menu(task_list))
        else:
            bot.send_message(message.from_user.id,
                             msg_text['task_not_found'],
                             reply_markup=mark_conf.menu())
        return
    if int(message_id) >= 0:
        util.change_tittle_task(message_id, message.text)
        bot.send_message(message.from_user.id, 'Напоминалка изменена ;)')
Beispiel #12
0
def task_edit(call):
    bot.delete_message(call.from_user.id, call.message.message_id)
    res = call.data.split('_')
    task_id = res[2]
    print(res[1])
    if res[1] == 'view':
        task = util.get_task_by_id(task_id)
        bot.send_message(call.from_user.id,
                         create_task_text(task),
                         reply_markup=mark_conf.task_menu(task),
                         parse_mode='HTML')
        return
    elif res[1] == 'tittle':
        msg = bot.send_message(call.from_user.id,
                               'Новый заголовок',
                               reply_markup=mark_conf.create_custom_button(
                                   button_text['cancel']))
        bot.register_next_step_handler(msg, change_task_name)
        global message_id
        message_id = task_id
        return
    elif res[1] == 'search':
        bot.send_message(call.from_user.id,
                         msg_text['input_task_name'],
                         reply_markup=mark_conf.create_custom_button(
                             button_text['cancel']))
        return
    elif res[1] == 'tags':
        # Удаляем словарь. если он уже существоватл
        if call.from_user.id in TASK_TAGS:
            del TASK_TAGS[call.from_user.id]

        TASK_TAGS[call.from_user.id] = {}
        TASK_TAGS[call.from_user.id]['task_id'] = task_id
        TASK_TAGS[call.from_user.id]['tag_list'] = []
        TASK_TAGS[call.from_user.id]['selected_tags'] = []

        # Создаем меню и словарь и создае меню тегов
        inline_key = telebot.types.InlineKeyboardMarkup()
        for tag in util.get_user_tags(call.from_user.id, task_id=task_id):
            TASK_TAGS[call.from_user.id]['tag_list'].append(tag)

            if tag['status']:
                TASK_TAGS[call.from_user.id]['selected_tags'].append({
                    'id':
                    tag['id'],
                    'name':
                    tag['name']
                })
                button_name = '✅ ' + tag['name']
            else:
                button_name = tag['name']

            inline_btn = telebot.types.InlineKeyboardButton(
                text=button_name,
                callback_data=inline_conf.tag + 'choise_' + str(tag['id']))
            inline_key.add(inline_btn)
        bot.send_message(call.from_user.id,
                         'Выберите теги:',
                         reply_markup=inline_key)

        custom_key = telebot.types.ReplyKeyboardMarkup(resize_keyboard=True)
        custom_key.row(button_text['closed'], button_text['cancel'])
        bot.clear_step_handler(call.message)
        msg = bot.send_message(
            call.from_user.id,
            'После выбора нужных пунктов нажмите на кнопку <b>Готово ✅</b>.',
            parse_mode='HTML',
            reply_markup=custom_key)
        bot.register_next_step_handler(msg, tag_data)
        return
    elif res[1] == 'favorite':
        task = util.update_favorite_task(util.get_task_by_id(task_id))
        bot.send_message(call.from_user.id,
                         create_task_text(task),
                         reply_markup=mark_conf.task_menu(task),
                         parse_mode='HTML')
        return
    elif res[1] == 'closed':
        util.change_active_task(task_id)
        bot.send_message(call.from_user.id, 'Задача перемещена в 🗄 Архив')
    elif res[1] == 'activate':
        util.change_active_task(task_id, activate=1)
        bot.send_message(call.from_user.id, 'Задача перемещена в ✅ Активные')

        task = util.get_task_by_id(task_id)
        bot.send_message(call.from_user.id,
                         create_task_text(task),
                         reply_markup=mark_conf.task_menu(task),
                         parse_mode='HTML')
        return
    elif res[1] == 'delete':
        util.delete_task(task_id)
        bot.send_message(call.from_user.id, 'Напоминалка удалено ;)')

    elif res[1] == 'invite':
        # TODO доделать интеграцию с гугл диском или др. сервисами
        return
    elif res[1] == 'back':
        bot.send_message(call.from_user.id,
                         msg_text['back'],
                         parse_mode='HTML')
        return
    # По окончанию действий выводим список активных тасков для дальнейшей работы с ними
    task_list = util.get_task_list_by_user(call.from_user.id, not_closed=True)
    if task_list:
        bot.send_message(call.from_user.id,
                         msg_text['chose_task'],
                         reply_markup=mark_conf.task_list_menu(task_list))
    else:
        bot.send_message(call.from_user.id,
                         msg_text['task_not_found'],
                         reply_markup=mark_conf.menu())
Beispiel #13
0
def currency(call):
    chat = call.message.chat
    bot.edit_message_text(base.get_text(chat.id, 'operations'),
                          chat.id,
                          call.message.message_id,
                          reply_markup=markups.menu())