Esempio n. 1
0
    def add_node(user: User,
                 node_type=ActionsEnum.A_FILL_TYPE_TIME,
                 time=Constants.base_time):
        current_task = user.get_current_task()

        chosen_date = user.get_chosen_date()

        TS = user.get_TS()

        if node_type == ActionsEnum.A_FILL_TYPE_TIME:
            current_task[Constants.presence] = True

            current_task[Constants.role_id] = user.get_role()
            current_task[Constants.chours] = time

            try:
                user.get_TS().change_time_in_task(
                    current_task[Constants.cdate],
                    current_task[Constants.task_id],
                    current_task[Constants.chours])

                current_task[Constants.update] = True
                user.add_task_to_list(current_task)
                user.set_current_task({})
            except TimeError as e:
                raise e
            except ValueError as e:
                raise e
        else:
            user.get_TS().write_absence(chosen_date, node_type)
Esempio n. 2
0
def parser(message):
    user = User(message.from_user.id)

    if not Registration.check_user(user):
        user.set_uname(message.text)

        err_messages = []

        Registration.create_request(user, err_messages)

        if len(err_messages) != 0:
            bot.send_message(message.chat.id,
                             ErrorParser.from_list_to_string(err_messages))
        else:
            bot.send_message(message.chat.id,
                             "Для подтверждения регистрации проверьте почту")
    else:
        if ActiveUsers.check_user(user.get_id()):
            user = ActiveUsers.get_user(user.get_id())

            if user.check_task():

                try:
                    user.get_TS().reset_absence(Constants.sick,
                                                user.get_chosen_date())
                    user.get_TS().reset_absence(Constants.vacation,
                                                user.get_chosen_date())

                    task_time = message.text
                    Actions.write_time(user, task_time)

                    ActiveUsers.update_user(user)

                    status_text = user.get_TS().get_string_status()

                    keyboard = Keyboard.get_action_keyboard()
                    bot.send_message(user.get_id(),
                                     f"{status_text}\nВыберите действие",
                                     reply_markup=keyboard)

                except TimeError as e:
                    bot.send_message(user.get_id(), e.message)

                except ValueError as e:
                    bot.send_message(user.get_id(), e.args[0])
            else:
                bot.send_message(user.get_id(), "Не выбрана задача")
        else:
            bot.send_message(user.get_id(), "Не выбрано действие")

    pass
Esempio n. 3
0
    def update_user(user: User):

        node = {
            Constants.chosen_date: user.get_chosen_date(),
            Constants.role_id: user.get_role(),
            Constants.task_list: user.get_task_list(),
            Constants.current_task: user.get_current_task(),
            Constants.reset_request: user.get_reset_request(),
            Constants.TS: user.get_TS()
        }

        ActiveUsers.users.update({user.get_id(): node})

        pass
Esempio n. 4
0
 def get_fill_status_text(user: User):
     return user.get_TS().get_string_status()
Esempio n. 5
0
def callback(callback_data):
    data = json.loads(callback_data.data)

    id = callback_data.from_user.id

    if ActiveUsers.check_user(id):
        user = ActiveUsers.get_user(id)
    else:
        user = User(id)

    err_list = []

    bot.delete_message(chat_id=callback_data.message.chat.id,
                       message_id=callback_data.message.message_id)

    keyboard = None
    text = ''

    if data[Constants.type] == ActionsEnum.A_MAIN_DELETE_INFOTYPE:
        Registration.delete_request(user)
        text = "Id удалён из системы"

    elif data[Constants.type] == ActionsEnum.A_MAIN_FILL:

        status_text = Actions.get_fill_status_text(user)

        keyboard = Keyboard.get_fill_keyboard()
        text = f"{status_text}Выберите действие"

    elif data[Constants.type] == ActionsEnum.A_TO_START:
        keyboard = Keyboard.get_main_keyboard()
        text = "Выберите действие"

    elif data[Constants.type] == ActionsEnum.A_FILL_TODAY or \
            data[Constants.type] == ActionsEnum.A_FILL_YESTERDAY or \
            data[Constants.type] == ActionsEnum.A_CALENDAR_ACTION:

        if data.get(Constants.cdate):
            user.set_chosen_date(data[Constants.cdate])
        else:
            Actions.choose_day_by_action_type(data[Constants.type], user)

        task_list = Actions.get_tasks_by_day(user)

        try:
            user.get_TS().update(user.get_id(), user.get_chosen_date(),
                                 task_list)

            status_text = Actions.get_fill_status_text(user)

            keyboard = Keyboard.get_fill_type_keyboard(user)
            text = f"{status_text}\nВыберите действие"
        except TelegramBotError:
            keyboard = Keyboard.get_main_keyboard()
            text = "У вас нет задач!"

    elif data[Constants.type] == ActionsEnum.A_FILL_TYPE_SICK or \
            data[Constants.type] == ActionsEnum.A_FILL_TYPE_VACATION or \
            data[Constants.type] == ActionsEnum.A_FILL_TYPE_MISSION:
        TS = user.get_TS()

        TS.reset_absence(Constants.sick, user.get_chosen_date())
        TS.reset_absence(Constants.vacation, user.get_chosen_date())
        TS.reset_absence(Constants.mission, user.get_chosen_date())

        Actions.add_node(user, data[Constants.type])

        status_text = TS.get_string_status_for_date(user.get_chosen_date())

        keyboard = Keyboard.get_action_keyboard()
        text = f"{status_text}\nВыберите действие"

    elif data[Constants.type] == ActionsEnum.A_FILL_ANOTHER_DAY:
        Actions.move_calendar(data, user)

        month = Utils.get_month_by_chosen_date(user.get_chosen_date())

        keyboard = Keyboard.get_calendar(user)
        text = f"Выбранный месяц: {month}\nВыберите день"

    elif data[Constants.type] == ActionsEnum.A_FILL_TYPE_TIME:
        task_list = Actions.get_tasks_by_day(user)

        user.get_TS().update(user.get_id(), user.get_chosen_date(), task_list)

        keyboard = Keyboard.get_tasks_keyboard(user)
        text = "Выберите задачу"

    elif data[Constants.type] == ActionsEnum.A_FILL_FOR_DATE:
        Actions.create_task_for_user(user, data[Constants.task_id])
        text = "Введите время отведённое на задачу"

    elif data[Constants.type] == ActionsEnum.A_APPROVE:
        Actions.approve_changes(user, err_list)

        if len(err_list) != 0:
            text = ErrorParser.from_list_to_string(err_list)
        else:
            text = "Изменения выполнены"

        keyboard = Keyboard.get_main_keyboard()

    elif data[Constants.type] == ActionsEnum.A_RESET:
        Actions.approve_changes(user)

        keyboard = Keyboard.get_main_keyboard()
        text = "Изменения отклонены"

    elif data[Constants.type] == ActionsEnum.A_RESET_MISSION:
        TS = user.get_TS()
        chosen_date = user.get_chosen_date()
        TS.reset_mission_node(chosen_date)

        status_text = Actions.get_fill_status_text(user)

        keyboard = Keyboard.get_fill_type_keyboard(user)
        text = f"{status_text}\nВыберите действие"

    elif data[Constants.type] == ActionsEnum.A_ACTIVE_MISSION:
        user.get_TS().write_absence(user.get_chosen_date(),
                                    data[Constants.type])

        status_text = Actions.get_fill_status_text(user)

        keyboard = Keyboard.get_fill_type_keyboard(user)
        text = f"{status_text}\nВыберите действие"

    elif data[Constants.type] == ActionsEnum.A_APPROVE_REQUEST:
        user.set_session(data[Constants.session_guid])
        Actions.reset_pass(user, err_list)

        if len(err_list) != 0:
            text = ErrorParser.from_list_to_string(err_list)
        else:
            text = f"Ваш временный пароль: {user.get_password()}"

        keyboard = Keyboard.get_main_keyboard()

    elif data[Constants.type] == ActionsEnum.A_RESET_REQUEST:
        user.set_session(data[Constants.session_guid])
        Actions.drop_reset_session(user)

        text = "Запрос на сброс пароля отменён"
        keyboard = Keyboard.get_main_keyboard()

    elif data[Constants.type] == ActionsEnum.A_RESET_PASSWORD:
        ways = Actions.get_ways(user)
        user.set_ways(ways)

        keyboard = Keyboard.get_ways_keyboard(user)
        text = f"{user.get_request_text()}Выберите способ сброса пароля"

    elif data[Constants.type] == ActionsEnum.A_CHOOSE_WAY:
        way_id = data[Constants.way_id]
        Actions.create_request_for_user(user, way_id)

        systems = Actions.get_systems(user)
        user.set_systems(systems)

        keyboard = Keyboard.get_system_keyboard(user)
        text = f"{user.get_request_text()}Выберите систему"

    elif data[Constants.type] == ActionsEnum.A_CHOOSE_SYSTEM:
        system = data[Constants.full_info]
        Actions.add_system_to_request(user, system)

        keyboard = Keyboard.get_reset_approve_keyboard(user)
        text = f"{user.get_request_text()}"

    elif data[Constants.type] == ActionsEnum.A_APPROVE_DROP:
        Actions.send_drop_request(user, err_list)

        if len(err_list):
            text = ErrorParser.from_list_to_string(err_list)
            keyboard = Keyboard.get_main_keyboard()
        else:
            text = "Запрос на сброс пароля отправлен"

            request_type = Actions.get_request_type(user)

            if request_type == Constants.email_reset:
                keyboard = Keyboard.get_main_keyboard()

            Actions.clear_request(user)

    bot.send_message(user.get_id(), text, reply_markup=keyboard)

    ActiveUsers.update_user(user)