async def equipment_confirmation(admin_id: int, user_id: int, eq_names: list): """ Confirm taking the equipment """ keyboard_interface = buttons.create_inline_markup([{ 'text': '\U00002705', 'callback': f'conf_success {user_id}' }, { 'text': '\U0000274C', 'callback': f'conf_failed {user_id}' }]) transformed_eq_names = "\n".join(eq_names["equipment_names"]) username = user.get_user(user_id)["username"] user_name = (f"@{username}" if username is not None else f"[{user_id}]\ (tg://user?id={user_id})") # save message data message = await bot.send_message( chat_id=admin_id, text=f"Подтвердите передачу техники к {user_name}.\ Список техники:\n{transformed_eq_names}", reply_markup=keyboard_interface, parse_mode="Markdown", ) state = dp.current_state() messages_list = await state.get_data() await state.update_data(admin_messages=messages_list["admin_messages"] + [message])
async def take_equipment_step_4_ok(call: types.CallbackQuery): """ Close transfer and add it to the history """ # get user id user_id = int(call.data.split()[1]) state = dp.current_state(chat=user_id, user=user_id) messages_data = await state.get_data() try: for message in messages_data["admin_messages"]: await bot.delete_message(message.chat.id, message.message_id) except Exception: logging.info(f"Deleting messages for {user_id} failed...") await bot.send_message( chat_id=user_id, text="Ваша заявка на взятие техники\ была подтверждена", ) user_transfers = [ trans["id"] for trans in transfer.get_active_transfers(user_id) ] list(map(transfer.verify_transfer, user_transfers)) await state.finish() logging.info(f"[TAKING EQUIPMENT] Administrator {call.message.chat.id}\ accepted equipment transfer by the user {user_id}")
async def notify_admins(message: types.Message, username: str): await Verification.waiting_for_action.set() state = dp.current_state() await state.update_data(admin_messages=[]) for admin in user.get_admin_list(): await verification(admin_id=admin['id'], user_id=message.chat.id, username=username)
async def cancel_current_state(message: types.Message): """ Allow user to cancel any action """ state = dp.current_state() info(f'[CANCELLING] Cancelling state ({state}) by {message.chat.id}...') await state.finish() await bot.send_message(chat_id=message.chat.id, text='\U0001F44C')
async def verification_failed(call: types.CallbackQuery): # get user id and state with all admin messages user_id = int(call.data.split()[2]) state = dp.current_state(chat=user_id, user=user_id) messages_data = await state.get_data() for message in messages_data['admin_messages']: await bot.delete_message(message.chat.id, message.message_id) await bot.send_message(chat_id=user_id, text='Администраторы отклонили вашу заявку') await state.finish() logging.info(f'[USER VERIFICATION] Administrator {call.message.chat.id}\ declined verification of the user {user_id}')
async def verification_success(call: types.CallbackQuery): # get user id and state with all admin messages user_id = int(call.data.split()[2]) state = dp.current_state(chat=user_id, user=user_id) messages_data = await state.get_data() for message in messages_data['admin_messages']: await bot.delete_message(message.chat.id, message.message_id) user.verify_user(user_id) await bot.send_message(chat_id=user_id, text='Вы получили доступ к боту.\ Пропишите /start для использования') await state.finish() logging.info(f'[USER VERIFICATION] Administrator {call.message.chat.id}\ accepted verification of the user {user_id}')
async def take_equipment_step_1(call: types.CallbackQuery): """ Request a photo with QR code """ await bot.send_message( chat_id=call.message.chat.id, text="Отправьте фото с\ QR кодом техники. QR код должен занимать <b>80% фото</b>(это можно сделать с помощью кадрирования). На одном фото должен быть <b>только один QR\ код</b>.\nПосле отправки всех QR кодов напишите /ok", parse_mode=types.message.ParseMode.HTML, ) await Take_Equipment.scan_qr_code.set() state = dp.current_state() await state.update_data(user_items=[], equipment_names=[])
async def verification(admin_id: int, user_id: int, username: str = None): keyboard_interface = buttons.create_inline_markup([{ 'text': '\U00002705', 'callback': f'verification success {user_id}' }, { 'text': '\U0000274C', 'callback': f'verification failed {user_id}' }]) user_name = f'@{username}' if username is not None else \ f'[{user_id}](tg://user?id={user_id})' message = await bot.send_message( chat_id=admin_id, text=f"Подтвердите пользователя {user_name}", reply_markup=keyboard_interface) # save message data state = dp.current_state() messages_list = await state.get_data() await state.update_data(admin_messages=messages_list['admin_messages'] + [message])