示例#1
0
def main_move(call):
    if authorized(message=call.message, bot=bot):
        User.update(status=call.data).where(User.telegram_id == call.message.chat.id).execute()
        bot.edit_message_text(chat_id=call.message.chat.id,
                              message_id=call.message.message_id,
                              text=bot_messages_text.get('enter_korpus_num'),
                              reply_markup=korpusa_keyboard)
示例#2
0
def main_sync(call):
    if authorized(message=call.message, bot=bot):
        User.update(status=call.data).where(User.telegram_id == call.message.chat.id).execute()
        bot.edit_message_text(chat_id=call.message.chat.id,
                              message_id=call.message.message_id,
                              text=bot_messages_text.get('getting_equipments'))
        values = users[f'{call.message.chat.id}'].get('operator').get_equipments()
        for i in range(len(values)):
            item = values[i]
            if i % 50 == 9:
                bot.edit_message_text(chat_id=call.message.chat.id,
                                      message_id=call.message.message_id,
                                      text=bot_messages_text.get('process_equipment_list').format(cur_item=i,
                                                                                                  sum_item=len(values)))
            if len(item) < 7:
                for j in range(len(item), 7):
                    item.append('')
            Equipment.get_or_create(it_id=item[0],
                                    defaults={
                                        'pos_in_buh': item[1],
                                        'invent_num': item[2],
                                        'type': item[3],
                                        'mark': item[4],
                                        'model': item[5],
                                        'serial_num': item[6]})
        bot.edit_message_text(chat_id=call.message.chat.id,
                              message_id=call.message.message_id,
                              text=bot_messages_text.get('equipment_list_getting_complete'))
示例#3
0
def main_search(call):
    if authorized(message=call.message, bot=bot):
        User.update(status=MAIN_SEARCH).where(User.telegram_id == call.message.chat.id).execute()
        bot.edit_message_text(chat_id=call.message.chat.id,
                              message_id=call.message.message_id,
                              text=bot_messages_text.get('searching_parameter'),
                              reply_markup=search_keyboard)
def authorized(message: Message, bot: TeleBot):
    user, created = User.get_or_create(telegram_id=message.chat.id,
                                       defaults={'status': IN_REGISTRATION_PROCCESS,
                                                 'authorized': 0})
    if user.authorized == 0 and user.status == IN_REGISTRATION_PROCCESS:
        bot.send_message(chat_id=message.chat.id,
                         text=bot_messages_text.get('start_registration'))
        User.update(status=FINISH_REGISTRATION).where(User.telegram_id == message.chat.id).execute()
        return False
    if user.authorized == 0 and user.status == FINISH_REGISTRATION:
        if message.text == USER_SECRET:
            User.update(status='', authorized=1).where(User.telegram_id == message.chat.id).execute()
            bot.send_message(chat_id=message.chat.id,
                             text=bot_messages_text.get('auth_ok'),
                             reply_markup=go_main_keyboard)
            return True
        else:
            bot.send_message(chat_id=message.chat.id,
                             text=bot_messages_text.get('wrong_auth_key'))
            return False
    if user.authorized == 1:
        return True
示例#5
0
def plain_text_message(message: Message):
    if authorized(message=message, bot=bot):

        # для вновь подключенного пользователя свой синхронизатор с Google-таблицей
        if users.get(f'{message.chat.id}') is None:
            users[f'{message.chat.id}'] = {
                'operator': GoogleSynchronizer(spreadsheet_id=SPREADSHEET_ID,
                                               credentials_file_name=CREDENTIAL_FILE)
            }

        # Обработка нажатия кнопки показа основных функций
        if message.text == main_reply_keyboard_text:
            User.update(status='').where(User.telegram_id == message.chat.id).execute()
            bot.send_message(chat_id=message.chat.id,
                             text=bot_messages_text.get('show_functions'),
                             reply_markup=main_inline_keyboard)
            return

        # Поиск по инвентарному или серийному номеру
        if User.get(telegram_id=message.chat.id).status == INVENT_SEARCH or \
                User.get(telegram_id=message.chat.id).status == SERIAL_SEARCH:
            found_items = None
            temp_item = None
            if User.get(telegram_id=message.chat.id).status == INVENT_SEARCH:
                bot.send_message(chat_id=message.chat.id,
                                 text=bot_messages_text.get('invent_search').format(invent_num=message.text))
                found_items = Equipment.select().where(Equipment.invent_num == message.text)
            elif User.get(telegram_id=message.chat.id).status == SERIAL_SEARCH:
                bot.send_message(chat_id=message.chat.id,
                                 text=bot_messages_text.get('serial_search').format(serial_num=message.text))
                found_items = Equipment.select().where(Equipment.serial_num == message.text)
            show_equipments(found_items, bot, message)

        # Выполнить перемещение в базе
        if User.get(telegram_id=message.chat.id).status.split('_')[0] == 'MOVE':
            Movement.update(room=message.text). \
                where(Movement.it_id == Equipment.get(it_id=User.get(telegram_id=message.chat.id).status.split('_')[1])
                      and Movement.room == 'N/A'). \
                execute()
            users[f'{message.chat.id}'].get('operator').add_new_movement(
                id=User.get(telegram_id=message.chat.id).status.split('_')[1])
            bot.send_message(chat_id=message.chat.id,
                             text=bot_messages_text.get('complete_move'))
            found_items = Equipment.select().where(
                Equipment.invent_num == users[f'{message.chat.id}']['invent_num_for_show_again'])
            show_equipments(found_items, bot, message)

        if User.get(telegram_id=message.chat.id).status.split('_')[0] == 'edit-type':
            Equipment.update(type=message.text). \
                where(Equipment.it_id == User.get(telegram_id=message.chat.id).status.split('_')[1]). \
                execute()
            users[f'{message.chat.id}'].get('operator').edit_in_table(
                item=Equipment.get(Equipment.it_id == User.get(telegram_id=message.chat.id).status.split('_')[1]))
            bot.send_message(chat_id=message.chat.id,
                             text=bot_messages_text.get('edit_complete'))
            found_items = Equipment.select().where(
                Equipment.invent_num == users[f'{message.chat.id}']['invent_num_for_show_again'])
            show_equipments(found_items, bot, message)

        if User.get(telegram_id=message.chat.id).status.split('_')[0] == 'edit-mark':
            Equipment.update(mark=message.text). \
                where(Equipment.it_id == User.get(telegram_id=message.chat.id).status.split('_')[1]). \
                execute()
            users[f'{message.chat.id}'].get('operator').edit_in_table(
                item=Equipment.get(Equipment.it_id == User.get(telegram_id=message.chat.id).status.split('_')[1]))
            bot.send_message(chat_id=message.chat.id,
                             text=bot_messages_text.get('edit_complete'))
            found_items = Equipment.select().where(
                Equipment.invent_num == users[f'{message.chat.id}']['invent_num_for_show_again'])
            show_equipments(found_items, bot, message)

        if User.get(telegram_id=message.chat.id).status.split('_')[0] == 'edit-model':
            Equipment.update(model=message.text). \
                where(Equipment.it_id == User.get(telegram_id=message.chat.id).status.split('_')[1]). \
                execute()
            users[f'{message.chat.id}'].get('operator').edit_in_table(
                item=Equipment.get(Equipment.it_id == User.get(telegram_id=message.chat.id).status.split('_')[1]))
            bot.send_message(chat_id=message.chat.id,
                             text=bot_messages_text.get('edit_complete'))
            found_items = Equipment.select().where(
                Equipment.invent_num == users[f'{message.chat.id}']['invent_num_for_show_again'])
            show_equipments(found_items, bot, message)

        if User.get(telegram_id=message.chat.id).status.split('_')[0] == 'edit-serial':
            Equipment.update(serial_num=message.text). \
                where(Equipment.it_id == User.get(telegram_id=message.chat.id).status.split('_')[1]). \
                execute()
            users[f'{message.chat.id}'].get('operator').edit_in_table(
                item=Equipment.get(Equipment.it_id == User.get(telegram_id=message.chat.id).status.split('_')[1]))
            bot.send_message(chat_id=message.chat.id,
                             text=bot_messages_text.get('edit_complete'))
            found_items = Equipment.select().where(
                Equipment.invent_num == users[f'{message.chat.id}']['invent_num_for_show_again'])
            show_equipments(found_items, bot, message)

        User.update(status='').where(User.telegram_id == message.chat.id).execute()
示例#6
0
def main_edit(call):
    if authorized(message=call.message, bot=bot):
        User.update(status=call.data).where(User.telegram_id == call.message.chat.id).execute()
        bot.edit_message_text(chat_id=call.message.chat.id,
                              message_id=call.message.message_id,
                              text=bot_messages_text.get('enter_new_serial'))
示例#7
0
def main_edit(call):
    if authorized(message=call.message, bot=bot):
        User.update(status=MAIN_EDIT).where(User.telegram_id == call.message.chat.id).execute()
        bot.send_message(chat_id=call.message.chat.id,
                         text=bot_messages_text.get('what_edit'),
                         reply_markup=get_edit_inline_keyboard(it_id=call.data.split('_')[1]))
示例#8
0
def serial_search(call):
    if authorized(message=call.message, bot=bot):
        User.update(status=SERIAL_SEARCH).where(User.telegram_id == call.message.chat.id).execute()
        bot.edit_message_text(chat_id=call.message.chat.id,
                              message_id=call.message.message_id,
                              text=bot_messages_text.get('enter_serial_num'))