Beispiel #1
0
def check_name_surname(message: Message):
    """
    Обрабатывает введенные пользователем имя и фамилию
    при регистрации
    :param message: сообщение пользователя с именем и фамилией
    """
    user_id = message.chat.id

    if message.text in COMMANDS:
        return handle_cancel(message, 'регистрации')

    if not is_text(message) or not is_name_surname_correct(message):
        instruction = bot.send_message(user_id, INCORRECT_DATA_MSG)
        return bot.register_next_step_handler(instruction, check_name_surname)

    message.text = escape(message.text)

    state = get_state(user_id)
    state.registering_user = User(user_id=user_id, name=message.text)
    save_state(user_id, state)

    instruction = bot.send_message(user_id,
                                   REG_MAIL_MSG,
                                   reply_markup=ReplyKeyboardRemove())
    bot.register_next_step_handler(instruction, check_email)
Beispiel #2
0
def check_email(message: Message):
    """
    Обрабатывает введенный пользователем адрес электронной почты
    при регистрации
    :param message: сообщение пользователя с адресом электронной почты
    """
    chat_id = message.chat.id

    if message.text in COMMANDS:
        return handle_cancel(message, 'регистрации')

    if not is_text(message) or not is_email_correct(message):
        instruction = bot.send_message(chat_id, INCORRECT_DATA_MSG)
        return bot.register_next_step_handler(instruction, check_email)

    state = get_state(chat_id)

    state.registering_user.code = str(int.from_bytes(os.urandom(2), 'little'))
    state.registering_user.email = message.text

    # ставим статус боту, пока письмо отправляется
    bot.send_chat_action(chat_id, 'typing')

    send_email(state.registering_user.email, 'Регистрация в боте BaumanLib',
               state.registering_user.code)

    state.last_email_date = datetime.now()
    state.email_attempt += 1

    save_state(chat_id, state)

    instruction = bot.send_message(chat_id, REG_CODE_MSG)
    bot.register_next_step_handler(instruction, check_code)
Beispiel #3
0
def check_course(message: Message):
    """
    Обрабатывает введенный пользователем курс материала
    для загрузки
    :param message: сообщение пользователя с курсом материала
    """
    chat_id = message.chat.id

    if message.text in COMMANDS:
        return handle_cancel(message, 'загрузки')

    if not is_text(message) or not is_course_correct(message):
        instruction = bot.send_message(chat_id, INCORRECT_DATA_MSG)
        return bot.register_next_step_handler(instruction, check_course)

    state = get_state(chat_id)
    state.uploading_material.course = message.text

    markup = ReplyKeyboardMarkup(one_time_keyboard=True)
    for subject in SUBJECTS:
        markup.row(KeyboardButton(subject))

    save_state(chat_id, state)

    instruction = bot.send_message(chat_id,
                                   UPLOAD_SUBJECT_MSG,
                                   reply_markup=markup)
    bot.register_next_step_handler(instruction, check_subject)
Beispiel #4
0
def check_subject(message: Message):
    """
    Обрабатывает введенный пользователем предмет материала
    для загрузки
    :param message: сообщение пользователя с предметом материала
    """
    chat_id = message.chat.id

    if message.text in COMMANDS:
        return handle_cancel(message, 'загрузки')

    correct_subject = is_subject_correct(message)

    if not is_text(message) or not correct_subject:
        instruction = bot.send_message(chat_id, INCORRECT_DATA_MSG)
        return bot.register_next_step_handler(instruction, check_subject)

    state = get_state(chat_id)
    state.uploading_material.discipline = correct_subject

    save_state(chat_id, state)

    instruction = bot.send_message(chat_id,
                                   UPLOAD_FILE_MSG,
                                   reply_markup=ReplyKeyboardRemove())
    bot.register_next_step_handler(instruction, check_file)
Beispiel #5
0
def check_material(message: Message):
    """
    Обрабатывает введенное пользователем название материала
    для загрузки
    :param message: сообщение пользователя с названием материала
    """
    author_id = message.from_user.id

    if message.text in COMMANDS:
        return handle_cancel(message, 'загрузки')

    if not is_text(message) or not is_title_correct(message):
        instruction = bot.send_message(author_id, INCORRECT_DATA_MSG)
        return bot.register_next_step_handler(instruction, check_material)

    # так как сообщения в поиске выводятся в HTML,
    # для защиты необходимо экранировать пользовательский ввод
    message.text = escape(message.text)

    state = get_state(author_id)
    state.uploading_material = Resource(title=message.text,
                                        author_id=author_id)
    save_state(author_id, state)

    instruction = bot.send_message(author_id, UPLOAD_COURSE_MSG)
    bot.register_next_step_handler(instruction, check_course)
Beispiel #6
0
def initiate_registration(user: telebot.types.User):
    """
    Запускает процесс регистрации для пользователя
    :param user: пользователь, которого необходимо зарегистрировать
    """
    state = get_state(user.id)

    first_name = user.first_name
    last_name = user.last_name

    bot.send_message(user.id, NEEDS_REG_MSG)

    if state.last_email_date and state.email_attempt >= MAX_NO_LIMIT_ATTEMPTS:
        seconds_passed = (datetime.now() - state.last_email_date).seconds
        seconds_left = EMAIL_LIMIT - seconds_passed

        if seconds_left > 0:
            return bot.send_message(user.id, reg_limit_msg(seconds_left))

    markup = None

    if last_name:
        markup = ReplyKeyboardMarkup(one_time_keyboard=True)
        markup.row(KeyboardButton(f'{first_name} {last_name}'))

    save_state(user.id, state)

    instruction = bot.send_message(user.id,
                                   REG_NAME_SURNAME_MSG,
                                   reply_markup=markup)
    return bot.register_next_step_handler(instruction, check_name_surname)
Beispiel #7
0
def main():
    try:
        common.reset_timestamp()
        # p = period.g_period
        period.describe()
        cache = db.fetch()
        # print 1 /0
        timesheets.create_timesheets(cache)

        excel.encache(cache)
        # db.save_state(cache)
        excel.verify(cache)
        expenses.create_expense_report(cache)
        statements.create_statements(cache)

        all_invoices = invoices.enumerate_invoices(cache)
        invoices.create_text_invoice_summary(all_invoices)

        the_tweaks = cache["InvTweaks"]  # tweaks.load(cache)
        accumulated_tweaks = tweaks.accum_tweaks_to_job_level(the_tweaks)
        # db.save_state(cache)
        post.post_main(cache, accumulated_tweaks)
        recoveries.create_recovery_report(cache, the_tweaks)
        wip.create_wip_report(cache, True)  # self.cbox_text_wip.IsChecked())
        health.create_health_report(cache)
        html.create_html()
    finally:
        # print "pydra.main().finally"
        if registry.get_defaulted_binary_reg_key("autopickle", False):
            # print "saving cache"
            db.save_state(cache)
    return cache  # useful if we want to pickle it
def switch_to_state(user_id, state):
    handlers.states[user_id].state = state
    save_state(handlers.states)
    if state == State.SETTINGS:
        show_settings_keyboard(user_id)
    elif state == State.MAIN:
        show_main_keyboard(user_id)
    elif state == State.SETTING_LOCATION:
        show_select_location_keyboard(user_id)
    elif state == State.SETTING_LANGUAGE:
        show_select_language_keyboard(user_id)
    elif state == State.SETTING_UNITS:
        show_select_units_keyboard(user_id)
Beispiel #9
0
def check_code(message: Message):
    """
    Обрабатывает введенный пользователем код при регистрации
    :param message: сообщение пользователя с кодом
    """
    chat_id = message.chat.id

    if message.text in COMMANDS:
        return handle_cancel(message, 'регистрации')

    state = get_state(chat_id)
    registering_user = state.registering_user

    if registering_user.code != message.text:
        state.code_attempt += 1
        save_state(chat_id, state)

        if state.code_attempt >= MAX_CODE_ATTEMPTS:
            state.code_attempt = 0
            save_state(chat_id, state)

            handle_cancel(message, 'регистрации')
            return bot.send_message(chat_id, CODE_LIMIT_MSG)

        instruction = bot.send_message(chat_id, INCORRECT_DATA_MSG)
        return bot.register_next_step_handler(instruction, check_code)

    registering_user.verified = True

    session.add(registering_user)
    session.commit()

    # Закончили — можем отчистить состояние
    clear_state(chat_id)

    bot.send_message(chat_id, REG_SUCCESS_MSG)
Beispiel #10
0
def pic():
    data = db.fetch()
    db.save_state(data)
Beispiel #11
0
 def menu_data_pickle_selected(self, event): # wxGlade: MainFrame.<event_handler>
     db.save_state(self.cache)