async def create_sticker(message: types.Message, state: FSMContext): if Sticker.select().where( Sticker.stick_uniq == message.sticker.file_unique_id): await message.answer('Такой стикер уже существует') stick = Sticker.get(stick_uniq=message.sticker.file_unique_id) await send_stick(message, stick) state.finish() return await state.update_data(sticker_id=message.sticker.file_id, sticker_uniq_id=message.sticker.file_unique_id) await message.answer('Придумайте название для стикера', reply_markup=Markup.every_state()) await SSticker.name.set()
async def weather_handler( query: types.CallbackQuery, callback_data: Dict[str, str], state: FSMContext, ): """ This handler will be called when user sends callback_query with weather action """ if callback_data['answer'] == '_': state.finish() return await send_message_with_resorts(query, callback_data['action']) resort = await mongo.find_one_resort({'slug': callback_data['answer']}) if not resort: logging.error(f'Resort not found. Slug: {callback_data["answer"]}') return await query.message.edit_text('Упс.. что-то пошло не так') current_weather = await get_current_weather(resort.coordinates) data = { 'resort': resort.name, 'coordinates': resort.coordinates, 'current_weather': current_weather.dict(), } await state.set_data(data=data) markup = types.InlineKeyboardMarkup() for slug, text in weather_actions.items(): button = types.InlineKeyboardButton( text.format(temp=f'{current_weather.temp:+.1f} \xb0С'), callback_data=weather_cb.new( action='get_weather', answer=slug, ), ) markup.add(button) markup.add( types.InlineKeyboardButton( 'Назад', callback_data=main_cb.new( action='weather', answer='_', ), )) await query.message.edit_text( 'Выберите действие:', reply_markup=markup, ) await WeatherState.waiting_for_weather_action.set()
async def admin(msg: types.Message, state: FSMContext): text = msg.text user_id = msg.from_user.id dolj = '' if text == 'Создать': if dolj == '': await state.set_state(States.DOLJ) await bot.send_message(msg.from_user.id, "Введи должность:") return elif text == 'Изменить': board_4 = create_reply_keyboard() await state.set_state(States.CHANGE) full_text = num_list() await bot.send_message(msg.from_user.id, full_text) await bot.send_message(msg.from_user.id, "Это весь список, кого будем редактировать?", reply_markup=board_4) elif text == 'Удалить': board_4 = create_reply_keyboard() await state.set_state(States.DELETE) full_text = num_list() await bot.send_message(msg.from_user.id, full_text) await bot.send_message(msg.from_user.id, "Это весь список, кого будем удалять?", reply_markup=board_4) elif text == 'Сохранить': new_collection.remove({}) docs = adm_collection.find({}, {'_id': 0}) full = [] for doc in docs: if 'admin_id' in doc: if doc['admin_id'] == str(user_id): adm_collection.update_one({'doljname': doc['doljname']}, {"$unset": { 'admin_id': 1 }}) doc.pop('admin_id') full.append(doc) new_collection.insert_many(full) state.finish() await bot.send_message(msg.from_user.id, "Все изменения сохранены", reply_markup=ReplyKeyboardRemove())
async def process_update_date(message: types.Message, state: FSMContext): logging.info("Processing date update...") try: if message.text != "Cancel": Session = sessionmaker(bind=engine) session = Session() date = message.text date = datetime.datetime.date(dateparser.parse(date)) id_ = await state.get_data() id_ = id_["id_"] session.query(Task).filter(Task.id_ == id_).update( {Task.date: date}, synchronize_session=False) session.commit() state.finish() else: await message.answer("Выхожу из интерфейса.", reply_markup=ReplyKeyboardRemove()) await state.finish() return except Exception as e: await message.answer(str(e))
async def enter_post_num(message: types.Message, state: FSMContext): mess = message.text res_post_num = poshtomat_num_to_id(mess) # Получаем id из номера потомата await state.update_data(postomat_id=res_post_num) # Заносим id в стейт if res_post_num is False: # проверка существует ли почтомат await message.answer_sticker( r"CAACAgIAAxkBAAEBV_hfY3oxV-wJjpmg-gY-tQ8vKTEPHgACCwADnP4yMPctMM3hxWgtGwQ" ) keyboard = types.InlineKeyboardMarkup() keyboard.add( types.InlineKeyboardButton(text="До головного меню", callback_data="Cancel3")) await message.answer( 'Для повернення до головного меню, скасуйте операцію', reply_markup=keyboard) return await message.answer( hbold("Поштомат під номером: ") + hcode(message.text) + hbold("не існує\nСпробуйте ще раз")) else: poshtomat_id_ref = poshtomat_info(message.text) await state.update_data(poshtomatIDRef=poshtomat_id_ref) poshtomat_num = message.text await state.update_data(poshtomat_num=poshtomat_num) user_id = message.from_user.id user_data = await db.get_user_data(user_id) user_phone = user_data['phone_number'] print(user_phone) await state.update_data(user_phone=user_phone) await message.answer_sticker( r"CAACAgIAAxkBAAEBWclfZnya3xNdppAKqMv3U_pxremMfAACDAADnP4yMAvSYoYcS3C6GwQ" ) result = "\n".join(branch_search(message.text)) await message.answer(f"{result}", parse_mode=types.ParseMode.HTML) # data = await state.get_data() print("ЭТО ХЕНДЛЕР OUT") # print(data) # user_phone = data.get("user_phone") # берем номер телефона # poshtomat_num = data.get("poshtomat_num") # берем номер почтомата result = parcels_list_out(poshtomat_num, user_phone) await state.update_data(choose_out_result=result) if result is False: keyboard_send_parcel = types.InlineKeyboardMarkup() keyboard_send_parcel.row( types.InlineKeyboardButton(text="Так", callback_data="send_parcel_yes")) keyboard_send_parcel.row( types.InlineKeyboardButton(text="Ні", callback_data="Cancel3")) await message.answer( message.from_user.first_name + hbold(",для Вас не має посилок для отримання у поштоматі №:") + hcode(poshtomat_num) + hbold("\nБажаєте відправити посилку?"), reply_markup=keyboard_send_parcel) return state.finish() else: await message.answer('Оберіть Вашу посилку для отримання у поштоматі') for i in result: keyboard = types.InlineKeyboardMarkup() keyboard.add( types.InlineKeyboardButton(text=f"Отримати", callback_data=i['id'])) keyboard.add( types.InlineKeyboardButton(text=f"До головного меню", callback_data="Cancel3")) await message.answer(i['text'], parse_mode=types.ParseMode.HTML, reply_markup=keyboard) main_menu = types.InlineKeyboardMarkup() main_menu.add( types.InlineKeyboardButton(text=f"До головного меню", callback_data="Cancel3")) # await message.answer("Для повернення у головне меню", reply_markup=main_menu) # keyboard = types.InlineKeyboardMarkup() # keyboard.add(types.InlineKeyboardButton(text="Отримати", callback_data="parcels_out")) # keyboard.add(types.InlineKeyboardButton(text="Відправити", callback_data="parcels_in")) # keyboard.add(types.InlineKeyboardButton(text=f"До головного меню", callback_data="Cancel2")) # await message.answer('Оберіть дію з поштоматом 👇', reply_markup=keyboard) await ParcelTake.Take1.set()