def edit_from_location_callback(update: Update, context: CallbackContext): text = update.message.text user_data = context.user_data user = user_data['user_data'] if user[LANG] == LANGS[0]: reply_text = "Yuboruvchi geolokatsiyasi tahrirlandi" if user[LANG] == LANGS[1]: reply_text = "Геолокация отправителя изменена" if user[LANG] == LANGS[2]: reply_text = "Юборувчи геолокацияси таҳрирланди" reply_text = '\U0001F44F\U0001F44F\U0001F44F ' + reply_text if update.message.location: longitude = update.message.location.longitude latitude = update.message.location.latitude user_data[USER_INPUT_DATA][FROM_LOCATION] = { 'longitude': longitude, 'latitude': latitude } update.message.reply_text(reply_text, reply_markup=ReplyKeyboardRemove()) inline_keyboard = InlineKeyboard('edit_keyboard', user[LANG]).get_keyboard() state = 'edit' user_data[USER_INPUT_DATA][STATE] = state elif text == "«Eski geolokatsiyamni o'chirish»" or text == '«Удалить мою старую геолокацию»' or \ text == "«Ески геолокациямни ўчириш»": user_data[USER_INPUT_DATA][FROM_LOCATION] = None update.message.reply_text(reply_text, reply_markup=ReplyKeyboardRemove()) inline_keyboard = InlineKeyboard('edit_keyboard', user[LANG]).get_keyboard() state = 'edit' user_data[USER_INPUT_DATA][STATE] = state elif text == "« Ortga" or text == "« Назад" or text == "« Ортга": update.message.reply_text(update.message.text, reply_markup=ReplyKeyboardRemove()) inline_keyboard = InlineKeyboard(edit_address_keyboard, user[LANG]).get_keyboard() state = 'edit_address' user_data[USER_INPUT_DATA][STATE] = state else: if user[LANG] == LANGS[0]: error_text = "Geolokatsiyangizni yuboring" if user[LANG] == LANGS[1]: error_text = "Отправьте свою геолокацию" if user[LANG] == LANGS[2]: error_text = "Геолокациянгизни юборинг" error_text = f'\U000026A0 {error_text} !' update.message.reply_text(error_text, quote=True) return user_data[USER_INPUT_DATA][STATE] # logger.info('new_cargo_info: %s', user_data[USER_INPUT_DATA]) layout = get_new_cargo_layout(user_data[USER_INPUT_DATA], user[LANG]) if user_data[USER_INPUT_DATA][PHOTO]: message = update.message.reply_photo(user_data[USER_INPUT_DATA][PHOTO]['file_id'], caption=layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) else: message = update.message.reply_html(layout, reply_markup=inline_keyboard) user_data[USER_INPUT_DATA][MESSAGE_ID] = message.message_id return state
def edit_region_callback(update: Update, context: CallbackContext): callback_query = update.callback_query data = callback_query.data user_data = context.user_data user = user_data['user_data'] if data == 'back': layout = get_new_cargo_layout(user_data[USER_INPUT_DATA], user[LANG]) if user[LANG] == LANGS[0]: button1_text = "Viloyatni tahrirlash" button2_text = "Tumanni tahrirlash" button3_text = "Ortga" if user[LANG] == LANGS[1]: button1_text = "Изменить область" button2_text = "Изменить район" button3_text = "Назад" if user[LANG] == LANGS[2]: button1_text = "Вилоятни таҳрирлаш" button2_text = "Туманни таҳрирлаш" button3_text = "Ортга" button3_text = '« ' + button3_text inline_keyboard = InlineKeyboardMarkup([ [ InlineKeyboardButton(button1_text, callback_data='edit_region'), InlineKeyboardButton(button2_text, callback_data='edit_district') ], [ InlineKeyboardButton(button3_text, callback_data='back') ] ]) callback_query.answer() if user_data[USER_INPUT_DATA][PHOTO]: callback_query.edit_message_caption(layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) else: callback_query.edit_message_text(layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) return user_data[USER_INPUT_DATA][STATE] region_id = data if user_data[USER_INPUT_DATA][STATE] == 'edit_from_address': user_data[USER_INPUT_DATA]['new_from_region'] = region_id if user_data[USER_INPUT_DATA][STATE] == 'edit_to_address': user_data[USER_INPUT_DATA]['new_to_region'] = region_id # logger.info('new_cargo_info: %s', user_data[USER_INPUT_DATA]) callback_query.answer() inline_keyboard = InlineKeyboard(districts_keyboard, user[LANG], region_id=region_id).get_keyboard() callback_query.edit_message_reply_markup(reply_markup=inline_keyboard) return 'edit_district'
def edit_district_callback(update: Update, context: CallbackContext): callback_query = update.callback_query data = callback_query.data user_data = context.user_data user = user_data['user_data'] if data == 'back_btn': if user[LANG] == LANGS[0]: button1_text = "Viloyatni tahrirlash" button2_text = "Tumanni tahrirlash" button3_text = "Ortga" if user[LANG] == LANGS[1]: button1_text = "Изменить область" button2_text = "Изменить район" button3_text = "Назад" if user[LANG] == LANGS[2]: button1_text = "Вилоятни таҳрирлаш" button2_text = "Туманни таҳрирлаш" button3_text = "Ортга" button3_text = '« ' + button3_text inline_keyboard = InlineKeyboardMarkup([ [ InlineKeyboardButton(button1_text, callback_data='edit_region'), InlineKeyboardButton(button2_text, callback_data='edit_district') ], [ InlineKeyboardButton(button3_text, callback_data='back') ] ]) state = user_data[USER_INPUT_DATA][STATE] answer = None if state == 'edit_from_address': key = 'new_from_region' elif state == 'edit_to_address': key = 'new_to_region' if key in user_data[USER_INPUT_DATA].keys(): user_data[USER_INPUT_DATA].pop(key) layout = get_new_cargo_layout(user_data[USER_INPUT_DATA], user[LANG]) if user_data[USER_INPUT_DATA][PHOTO]: callback_query.edit_message_caption(layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) else: callback_query.edit_message_text(layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) else: district_id = data state = user_data[USER_INPUT_DATA][STATE] if state == 'edit_from_address': new_key = 'new_from_region' key = FROM_REGION user_data[USER_INPUT_DATA][FROM_DISTRICT] = district_id if user[LANG] == LANGS[0]: answer = "Yuboruvchi manzili tahrirlandi" if user[LANG] == LANGS[1]: answer = "Адрес отправителя изменен" if user[LANG] == LANGS[2]: answer = "Юборувчи манзили таҳрирланди" if state == 'edit_to_address': new_key = 'new_to_region' key = TO_REGION user_data[USER_INPUT_DATA][TO_DISTRICT] = district_id if user[LANG] == LANGS[0]: answer = "Qabul qiluvchi manzili tahrirlandi" if user[LANG] == LANGS[1]: answer = "Адрес получателя изменен" if user[LANG] == LANGS[2]: answer = "Қабул қилувчи манзили таҳрирланди" answer = '\U0001F44F\U0001F44F\U0001F44F ' + answer if new_key in user_data[USER_INPUT_DATA].keys(): user_data[USER_INPUT_DATA][key] = user_data[USER_INPUT_DATA].pop(new_key) layout = get_new_cargo_layout(user_data[USER_INPUT_DATA], user[LANG]) inline_keyboard = InlineKeyboard('edit_keyboard', user[LANG]).get_keyboard() if user_data[USER_INPUT_DATA][PHOTO]: callback_query.edit_message_caption(layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) else: callback_query.edit_message_text(layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) state = 'edit' user_data[USER_INPUT_DATA][STATE] = state callback_query.answer(answer) return state
def phone_number_callback(update: Update, context: CallbackContext): # with open('jsons/update.json', 'w') as update_file: # update_file.write(update.to_json()) text = update.message.text contact = update.message.contact user_data = context.user_data user = user_data['user_data'] if contact: phone_number = phone_number_filter(contact.phone_number) else: phone_number = phone_number_filter(text) if phone_number: user_data[USER_INPUT_DATA][USER_PHONE_NUMBER] = phone_number layout = get_new_cargo_layout(user_data[USER_INPUT_DATA], user[LANG]) inline_keyboard = InlineKeyboard( confirm_keyboard, user[LANG], data=user_data[USER_INPUT_DATA]).get_keyboard() update.message.reply_text('\U0001F447\U0001F447\U0001F447', reply_markup=ReplyKeyboardRemove()) if user_data[USER_INPUT_DATA][PHOTO]: message = update.message.reply_photo( user_data[USER_INPUT_DATA][PHOTO].get('file_id'), layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) else: message = update.message.reply_html(layout, reply_markup=inline_keyboard) logger.info('user_input_data: %s', user_data[USER_INPUT_DATA]) state = CONFIRMATION user_data[USER_INPUT_DATA][STATE] = state user_data[USER_INPUT_DATA][MESSAGE_ID] = message.message_id else: if user[LANG] == LANGS[0]: error_text = "Xato telefon raqami yuborildi" if user[LANG] == LANGS[1]: error_text = "Номер телефона с ошибкой отправлен" if user[LANG] == LANGS[2]: error_text = "Хато телефон рақами юборилди" error_text = f'\U000026A0 {error_text} !' phone_number_layout = get_phone_number_layout(user[LANG]) update.message.reply_text(error_text, quote=True) update.message.reply_html(phone_number_layout) state = user_data[USER_INPUT_DATA][STATE] return state
def edit_region_or_district_callback(update: Update, context: CallbackContext): callback_query = update.callback_query data = callback_query.data user_data = context.user_data user = user_data['user_data'] if data == 'back': inline_keyboard = InlineKeyboard(edit_address_keyboard, user[LANG]).get_keyboard() text = get_new_cargo_layout(user_data[USER_INPUT_DATA], user[LANG]) state = 'edit_address' user_data[USER_INPUT_DATA][STATE] = state if data == 'edit_region': if user[LANG] == LANGS[0]: buton_text = "Ortga" text = "Viloyatni tanlang" if user[LANG] == LANGS[1]: buton_text = "Назад" text = "Выберите область" if user[LANG] == LANGS[2]: buton_text = "Ортга" text = "Вилоятни танланг" text = f'{text} :' buton_text = '« ' + buton_text inline_keyboard = InlineKeyboard(regions_keyboard, user[LANG]).get_keyboard() inline_keyboard['inline_keyboard'].append([InlineKeyboardButton(buton_text, callback_data='back')]) state = 'edit_region' if data == 'edit_district': if user[LANG] == LANGS[0]: text = "Tumanni tanlang" if user[LANG] == LANGS[1]: text = "Выберите район" if user[LANG] == LANGS[2]: text = "Туманни танланг" text = f'{text} :' if user_data[USER_INPUT_DATA][STATE] == 'edit_from_address': region_id = user_data[USER_INPUT_DATA][FROM_REGION] elif user_data[USER_INPUT_DATA][STATE] == 'edit_to_address': region_id = user_data[USER_INPUT_DATA][TO_REGION] inline_keyboard = InlineKeyboard(districts_keyboard, user[LANG], region_id=region_id).get_keyboard() state = 'edit_district' callback_query.answer() if user_data[USER_INPUT_DATA][PHOTO]: callback_query.edit_message_caption(text, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) else: callback_query.edit_message_text(text, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) return state
def edit_weight_callback(update: Update, context: CallbackContext): user_data = context.user_data user = user_data['user_data'] callback_query = update.callback_query if callback_query: if callback_query.data == 'back': if 'new_weight_unit' in user_data[USER_INPUT_DATA].keys(): user_data[USER_INPUT_DATA].pop('new_weight_unit') if user[LANG] == LANGS[0]: button3_text = "Yuk og'irligini o'chirish" button4_text = "Ortga" text = "Yuk og'irlik birligini tanlang :\n\n" \ "Yoki eskisini o'chirish uchun «o'chirish» ni bosing" if user[LANG] == LANGS[1]: button3_text = "Удалить вес груза" button4_text = "Назад" text = "Выберите единицу веса груза :\n\n" \ "Или нажмите «удалить», чтобы удалить старую" if user[LANG] == LANGS[2]: button3_text = "Юк оғирлигини ўчириш" button4_text = "Ортга" text = "Юк оғирлик бирлигини танланг :\n\n" \ "Ёки ескисини ўчириш учун «ўчириш» ни босинг" button4_text = '« ' + button4_text inline_keyboard = InlineKeyboard(weights_keyboard, user[LANG]).get_keyboard() if user_data[USER_INPUT_DATA][WEIGHT]: inline_keyboard['inline_keyboard'].append([ InlineKeyboardButton(button3_text, callback_data='delete') ]) else: text = text.partition(':') text = text[0] + text[1] inline_keyboard['inline_keyboard'].append( [InlineKeyboardButton(button4_text, callback_data='back')]) callback_query.answer() if user_data[USER_INPUT_DATA][PHOTO]: callback_query.edit_message_caption( text, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) else: callback_query.edit_message_text(text, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) state = 'edit_weight_unit' user_data[USER_INPUT_DATA][STATE] = state return state else: text = update.message.text if not text.isdigit(): if user[LANG] == LANGS[0]: error_text = "Yuk og'irligini raqamda yuboring" if user[LANG] == LANGS[1]: error_text = "Отправите вес груза цифрами" if user[LANG] == LANGS[2]: error_text = "Юк оғирлигини рақамда юборинг" error_text = f'\U000026A0 {error_text} !' update.message.reply_text(error_text, quote=True) return user_data[USER_INPUT_DATA][STATE] user_data[USER_INPUT_DATA][WEIGHT] = text user_data[USER_INPUT_DATA][WEIGHT_UNIT] = user_data[ USER_INPUT_DATA].pop('new_weight_unit') inline_keyboard = InlineKeyboard(edit_keyboard, user[LANG]).get_keyboard() layout = get_new_cargo_layout(user_data[USER_INPUT_DATA], user[LANG]) if user[LANG] == LANGS[0]: answer = "Yuk og'irligi tahrirlandi" if user[LANG] == LANGS[1]: answer = "Вес груза изменен" if user[LANG] == LANGS[2]: answer = "Юк оғирлиги таҳрирланди" answer = '\U0001F44F\U0001F44F\U0001F44F ' + answer update.message.reply_text(answer) context.bot.edit_message_reply_markup( update.effective_chat.id, user_data[USER_INPUT_DATA].pop(MESSAGE_ID)) if user_data[USER_INPUT_DATA][PHOTO]: message = update.message.reply_photo( user_data[USER_INPUT_DATA][PHOTO].get('file_id'), layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) else: message = update.message.reply_html(layout, reply_markup=inline_keyboard) state = 'edit' user_data[USER_INPUT_DATA][STATE] = state user_data[USER_INPUT_DATA][MESSAGE_ID] = message.message_id return state
def new_cargo_callback(update: Update, context: CallbackContext): user_data = context.user_data set_user_data(update.effective_user.id, user_data) user = user_data['user_data'] user_data[USER_INPUT_DATA] = dict() callback_query = update.callback_query if callback_query: # print(callback_query.data) cargo_id = int(callback_query.data.split('_')[0]) cargo_data = get_cargo_by_id(cargo_id) cargo_data[USERNAME] = user[USERNAME] cargo_data[NAME] = user[NAME] cargo_data[SURNAME] = user[SURNAME] cargo_data[STATE] = CONFIRMATION cargo_data.pop('shipping_datetime') cargo_data.pop('id') cargo_data.pop('created_at') cargo_data.pop('updated_at') cargo_data[DATE] = datetime.datetime.now().strftime('%d-%m-%Y') cargo_data[TIME] = 'now' cargo_data[PHOTO] = cargo_data[FROM_LOCATION] = cargo_data[ TO_LOCATION] = None if cargo_data['photo_id']: cargo_data[PHOTO] = { 'file_id': cargo_data.pop('photo_id'), 'width': cargo_data.pop('photo_width'), 'height': cargo_data.pop('photo_height'), 'file_size': cargo_data.pop('photo_size') } if cargo_data['from_longitude']: cargo_data[FROM_LOCATION] = { 'longitude': cargo_data.pop('from_longitude'), 'latitude': cargo_data.pop('from_latitude') } if cargo_data['to_longitude']: cargo_data[TO_LOCATION] = { 'longitude': cargo_data.pop('to_longitude'), 'latitude': cargo_data.pop('to_latitude') } edit_text = inline_keyboard_types[paginate_keyboard][user[LANG]][1] callback_query.edit_message_text(edit_text) reply_text = inline_keyboard_types[paginate_keyboard][user[LANG]][2] reply_text += '\n\U0001F447\U0001F447\U0001F447' callback_query.message.reply_text(reply_text, reply_markup=ReplyKeyboardRemove()) layout = get_new_cargo_layout(cargo_data, user[LANG]) inline_keyboard = InlineKeyboard(confirm_keyboard, user[LANG], data=cargo_data).get_keyboard() if cargo_data[PHOTO]: message = callback_query.message.reply_photo( cargo_data[PHOTO].get('file_id'), layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) else: message = callback_query.message.reply_html( layout, reply_markup=inline_keyboard) cargo_data[MESSAGE_ID] = message.message_id user_data[USER_INPUT_DATA].update(cargo_data) return CONFIRMATION else: text = update.message.text.split(' ', 1)[-1] if text == reply_keyboard_types[menu_keyboard][user[LANG]][1]: if user[LANG] == LANGS[0]: text = "Qayerdan (Viloyatni tanlang)" if user[LANG] == LANGS[1]: text = "Откуда (Выберите область)" if user[LANG] == LANGS[2]: text = "Қаердан (Вилоятни танланг)" text = f'{text} :' update.message.reply_text(update.message.text, reply_markup=ReplyKeyboardRemove()) inline_keyboard = InlineKeyboard(regions_keyboard, user[LANG]).get_keyboard() message = update.message.reply_text(text, reply_markup=inline_keyboard) state = FROM_REGION user_data[USER_INPUT_DATA][STATE] = state user_data[USER_INPUT_DATA][USER_ID] = user[ID] user_data[USER_INPUT_DATA][USER_TG_ID] = user[TG_ID] user_data[USER_INPUT_DATA][USERNAME] = user[USERNAME] user_data[USER_INPUT_DATA][NAME] = user[NAME] user_data[USER_INPUT_DATA][SURNAME] = user[SURNAME] user_data[USER_INPUT_DATA][MESSAGE_ID] = message.message_id return state
def edit_date_and_time_callback(update: Update, context: CallbackContext): callback_query = update.callback_query data = callback_query.data user_data = context.user_data user = user_data['user_data'] if data == 'back' or data == 'now': inline_keyboard = InlineKeyboard(edit_keyboard, user[LANG]).get_keyboard() answer = None if data == 'now': user_data[USER_INPUT_DATA][DATE] = datetime.datetime.now( ).strftime('%d-%m-%Y') user_data[USER_INPUT_DATA][TIME] = 'now' if user[LANG] == LANGS[0]: answer = "Kun va vaqt tahrirlandi" if user[LANG] == LANGS[1]: answer = "Дата и время изменены" if user[LANG] == LANGS[2]: answer = "Кун ва вақт таҳрирланди" answer = '\U0001F44F\U0001F44F\U0001F44F ' + answer layout = get_new_cargo_layout(user_data[USER_INPUT_DATA], user[LANG]) state = 'edit' if data == 'today' or data == 'tomorrow' or data == 'after_tomorrow': if data == 'today': user_data[USER_INPUT_DATA]['new_date'] = datetime.datetime.now( ).strftime('%d-%m-%Y') if data == 'tomorrow': tomorrow = datetime.datetime.now() + datetime.timedelta(days=1) user_data[USER_INPUT_DATA]['new_date'] = tomorrow.strftime( '%d-%m-%Y') if data == 'after_tomorrow': after_tomorrow = datetime.datetime.now() + datetime.timedelta( days=2) user_data[USER_INPUT_DATA]['new_date'] = after_tomorrow.strftime( '%d-%m-%Y') if user[LANG] == LANGS[0]: text = "Soatni belgilang" button_text = 'Ortga' if user[LANG] == LANGS[1]: text = "Выберите время" button_text = "Назад" if user[LANG] == LANGS[2]: text = "Соатни белгиланг" button_text = "Ортга" text = f'{text} :' button_text = '« ' + button_text inline_keyboard = InlineKeyboard(hours_keyboard, user[LANG], begin=6, end=17).get_keyboard() inline_keyboard['inline_keyboard'].append( [InlineKeyboardButton(button_text, callback_data='back')]) layout = text answer = None state = 'edit_hour' callback_query.answer(answer) if user_data[USER_INPUT_DATA][PHOTO]: callback_query.edit_message_caption(layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) else: callback_query.edit_message_text(layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) user_data[USER_INPUT_DATA][STATE] = state return state
def edit_hour_callback(update: Update, context: CallbackContext): callback_query = update.callback_query data = callback_query.data user_data = context.user_data user = user_data['user_data'] if data == 'back_btn' or data == 'next_btn' or data == 'back': if user[LANG] == LANGS[0]: button_text = "Ortga" if user[LANG] == LANGS[1]: button_text = "Назад" if user[LANG] == LANGS[2]: button_text = "Ортга" button_text = f'« {button_text}' if data == 'back': user_data[USER_INPUT_DATA].pop('new_date') inline_keyboard = InlineKeyboard(dates_keyboard, user[LANG]).get_keyboard() inline_keyboard['inline_keyboard'].append( [InlineKeyboardButton(button_text, callback_data='back')]) state = 'edit_date_and_time' if data == 'next_btn' or data == 'back_btn': if data == 'next_btn': inline_keyboard = InlineKeyboard(hours_keyboard, user[LANG], begin=18, end=29).get_keyboard() if data == 'back_btn': inline_keyboard = InlineKeyboard(hours_keyboard, user[LANG], begin=6, end=17).get_keyboard() inline_keyboard['inline_keyboard'].append( [InlineKeyboardButton(button_text, callback_data='back')]) state = user_data[USER_INPUT_DATA][STATE] callback_query.answer() callback_query.edit_message_reply_markup(inline_keyboard) user_data[USER_INPUT_DATA][STATE] = state return state else: if user[LANG] == LANGS[0]: answer = "Kun va vaqt tahrirlandi" if user[LANG] == LANGS[1]: answer = "Дата и время изменены" if user[LANG] == LANGS[2]: answer = "Кун ва вақт таҳрирланди" answer = f'\U0001F44F\U0001F44F\U0001F44F {answer}' callback_query.answer(answer) user_data[USER_INPUT_DATA][TIME] = data user_data[USER_INPUT_DATA][DATE] = user_data[USER_INPUT_DATA].pop( 'new_date') layout = get_new_cargo_layout(user_data[USER_INPUT_DATA], user[LANG]) inline_keyboard = InlineKeyboard(edit_keyboard, user[LANG]).get_keyboard() if user_data[USER_INPUT_DATA][PHOTO]: callback_query.edit_message_caption(layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) else: callback_query.edit_message_text(layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) state = 'edit' user_data[USER_INPUT_DATA][STATE] = state return state
def edit_user_phone_callback(update: Update, context: CallbackContext): callback_query = update.callback_query user_data = context.user_data user = user_data['user_data'] if callback_query: data = callback_query.data if data == 'back': inline_keyboard = InlineKeyboard(edit_cargo_info_keyboard, user[LANG]).get_keyboard() answer = None state = 'edit_cargo_info' callback_query.answer(answer) layout = get_new_cargo_layout(user_data[USER_INPUT_DATA], user[LANG]) if user_data[USER_INPUT_DATA][PHOTO]: callback_query.edit_message_caption(layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) else: callback_query.edit_message_text(layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) user_data[USER_INPUT_DATA][STATE] = state return state else: contact = update.message.contact text = update.message.text if contact: phone_number = phone_number_filter(contact.phone_number) else: phone_number = phone_number_filter(text) if phone_number: user_data[USER_INPUT_DATA][USER_PHONE_NUMBER] = phone_number inline_keyboard = InlineKeyboard(edit_keyboard, user[LANG]).get_keyboard() if user[LANG] == LANGS[0]: answer = "Telefon raqami tahrirlandi" if user[LANG] == LANGS[1]: answer = "Номер телефона изменен" if user[LANG] == LANGS[2]: answer = "Телефон рақами таҳрирланди" answer = '\U0001F44F\U0001F44F\U0001F44F ' + answer update.message.reply_text(answer) layout = get_new_cargo_layout(user_data[USER_INPUT_DATA], user[LANG]) context.bot.edit_message_reply_markup( update.effective_chat.id, user_data[USER_INPUT_DATA].pop(MESSAGE_ID)) if user_data[USER_INPUT_DATA][PHOTO]: message = update.message.reply_photo( user_data[USER_INPUT_DATA][PHOTO].get('file_id'), layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) else: message = update.message.reply_text( layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) state = 'edit' user_data[USER_INPUT_DATA][STATE] = state user_data[USER_INPUT_DATA][MESSAGE_ID] = message.message_id return state else: if user[LANG] == LANGS[0]: error_text = "Xato telefon raqami yuborildi" if user[LANG] == LANGS[1]: error_text = "Номер телефона с ошибкой отправлен" if user[LANG] == LANGS[2]: error_text = "Хато телефон рақами юборилди" error_text = f'\U000026A0 {error_text} !' phone_number_layout = get_phone_number_layout(user[LANG]) update.message.reply_text(error_text, quote=True) update.message.reply_html(phone_number_layout) return user_data[USER_INPUT_DATA][STATE]
def message_handler_callback(update: Update, context: CallbackContext): # with open('jsons/update.json', 'w') as update_file: # update_file.write(update.to_json()) user_data = context.user_data set_user_data(update.effective_user.id, user_data) user = user_data['user_data'] full_text = update.message.text text = full_text.split(' ', 1)[-1] if user: if text == reply_keyboard_types[menu_keyboard][user[LANG]][3]: if user[LANG] == LANGS[0]: reply_text = "Sizda hali e'lonlar mavjud emas" if user[LANG] == LANGS[1]: reply_text = "У вас нет объявлений пока" if user[LANG] == LANGS[2]: reply_text = "Сизда ҳали эълонлар мавжуд емас" reply_text = f'\U0001F615 {reply_text}' inline_keyboard = None user_cargoes = get_user_cargoes(user[TG_ID]) if len(user_cargoes) > 0: user_data['user_cargoes'] = user_cargoes wanted = 1 wanted_cargo_data = user_cargoes[wanted - 1] shipping_datetime = wanted_cargo_data['shipping_datetime'] wanted_cargo_data[DATE] = shipping_datetime.strftime( '%d-%m-%Y') wanted_cargo_data[TIME] = shipping_datetime.strftime('%H:%M') wanted_cargo_data[NAME] = user[NAME] wanted_cargo_data[SURNAME] = user[SURNAME] wanted_cargo_data[USERNAME] = user[USERNAME] reply_text = get_new_cargo_layout(wanted_cargo_data, user[LANG]) inline_keyboard = InlineKeyboard( paginate_keyboard, user[LANG], data=(wanted, user_cargoes)).get_keyboard() update.message.reply_html(reply_text, reply_markup=inline_keyboard) elif text == reply_keyboard_types[menu_keyboard][user[LANG]][4]: reply_keyboard = ReplyKeyboard(settings_keyboard, user[LANG]).get_keyboard() update.message.reply_text(full_text, reply_markup=reply_keyboard) elif text == reply_keyboard_types[settings_keyboard][user[LANG]][1]: inline_keyboard = InlineKeyboard(user_data_keyboard, user[LANG]).get_keyboard() update.message.reply_html(get_user_info_layout(user), reply_markup=inline_keyboard) elif text == reply_keyboard_types[settings_keyboard][user[LANG]][2]: reply_text = 'Tilni tanlang\nВыберите язык\nТилни танланг' inline_keyboard = InlineKeyboard(langs_keyboard).get_keyboard() update.message.reply_text(reply_text, reply_markup=inline_keyboard) elif text == reply_keyboard_types[settings_keyboard][user[LANG]][3]: reply_keyboard = ReplyKeyboard(menu_keyboard, user[LANG]).get_keyboard() update.message.reply_text(full_text, reply_markup=reply_keyboard) else: thinking_emoji = '\U0001F914' reply_keyboard = ReplyKeyboard(menu_keyboard, user[LANG]).get_keyboard() update.message.reply_text(thinking_emoji, quote=True, reply_markup=reply_keyboard) else: reply_text = "\U000026A0 Siz ro'yxatdan o'tmagansiz !\nBuning uchun /start ni bosing.\n\n'" \ "\U000026A0 Вы не зарегистрированы !\nДля этого нажмите /start\n\n" \ "\U000026A0 Сиз рўйхатдан ўтмагансиз !\nБунинг учун /start ни босинг" update.message.reply_text(reply_text)
def edit_photo_callback(update: Update, context: CallbackContext): callback_query = update.callback_query user_data = context.user_data user = user_data['user_data'] if callback_query: data = callback_query.data if data == 'back': inline_keyboard = InlineKeyboard(edit_cargo_info_keyboard, user[LANG]).get_keyboard() answer = None state = 'edit_cargo_info' layout = get_new_cargo_layout(user_data[USER_INPUT_DATA], user[LANG]) callback_query.answer(answer) if user_data[USER_INPUT_DATA][PHOTO]: callback_query.edit_message_caption( layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) else: callback_query.edit_message_text(layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) if data == 'delete': user_data[USER_INPUT_DATA][PHOTO] = None inline_keyboard = InlineKeyboard(edit_keyboard, user[LANG]).get_keyboard() if user[LANG] == LANGS[0]: answer = "Yuk rasmi tahrirlandi" if user[LANG] == LANGS[1]: answer = "Фотография груза изменен" if user[LANG] == LANGS[2]: answer = "Юк расми таҳрирланди" answer = '\U0001F44F\U0001F44F\U0001F44F ' + answer callback_query.message.reply_text(answer) layout = get_new_cargo_layout(user_data[USER_INPUT_DATA], user[LANG]) context.bot.edit_message_reply_markup( update.effective_chat.id, user_data[USER_INPUT_DATA].pop(MESSAGE_ID)) message = callback_query.message.reply_html( layout, reply_markup=inline_keyboard) state = 'edit' user_data[USER_INPUT_DATA][MESSAGE_ID] = message.message_id else: cargo_photo = update.message.photo if not cargo_photo: if user[LANG] == LANGS[0]: error_text = "Yuk rasmi yuborilmadi" if user[LANG] == LANGS[1]: error_text = "Фотография груза не отправлено" if user[LANG] == LANGS[2]: error_text = "Юк расми юборилмади" error_text = f'\U000026A0 {error_text} !' update.message.reply_text(error_text, quote=True) return user_data[USER_INPUT_DATA][STATE] user_data[USER_INPUT_DATA][PHOTO] = cargo_photo[-1].to_dict() if user[LANG] == LANGS[0]: answer = "Yuk rasmi tahrirlandi" if user[LANG] == LANGS[1]: answer = "Фотография груза изменен" if user[LANG] == LANGS[2]: answer = "Юк расми таҳрирланди" answer = '\U0001F44F\U0001F44F\U0001F44F ' + answer update.message.reply_text(answer) layout = get_new_cargo_layout(user_data[USER_INPUT_DATA], user[LANG]) inline_keyboard = InlineKeyboard(edit_keyboard, user[LANG]).get_keyboard() context.bot.edit_message_reply_markup( update.effective_chat.id, user_data[USER_INPUT_DATA].pop(MESSAGE_ID)) message = update.message.reply_photo( user_data[USER_INPUT_DATA][PHOTO].get('file_id'), layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) state = 'edit' user_data[USER_INPUT_DATA][MESSAGE_ID] = message.message_id user_data[USER_INPUT_DATA][STATE] = state return state
def edit_definition_callback(update: Update, context: CallbackContext): callback_query = update.callback_query user_data = context.user_data user = user_data['user_data'] if callback_query: data = callback_query.data if data == 'back': inline_keyboard = InlineKeyboard(edit_cargo_info_keyboard, user[LANG]).get_keyboard() answer = None state = 'edit_cargo_info' if data == 'delete': user_data[USER_INPUT_DATA][DEFINITION] = None inline_keyboard = InlineKeyboard(edit_keyboard, user[LANG]).get_keyboard() if user[LANG] == LANGS[0]: answer = "Yuk tavsifi tahrirlandi" if user[LANG] == LANGS[1]: answer = "Описание груза изменен" if user[LANG] == LANGS[2]: answer = "Юк тавсифи таҳрирланди" answer = '\U0001F44F\U0001F44F\U0001F44F ' + answer state = 'edit' layout = get_new_cargo_layout(user_data[USER_INPUT_DATA], user[LANG]) callback_query.answer(answer) if user_data[USER_INPUT_DATA][PHOTO]: callback_query.edit_message_caption(layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) else: callback_query.edit_message_text(layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) user_data[USER_INPUT_DATA][STATE] = state else: if user[LANG] == LANGS[0]: answer = "Yuk tavsifi tahrirlandi" if user[LANG] == LANGS[1]: answer = "Описание груза изменен" if user[LANG] == LANGS[2]: answer = "Юк тавсифи таҳрирланди" answer = '\U0001F44F\U0001F44F\U0001F44F ' + answer update.message.reply_text(answer) user_data[USER_INPUT_DATA][DEFINITION] = update.message.text inline_keyboard = InlineKeyboard(edit_keyboard, user[LANG]).get_keyboard() layout = get_new_cargo_layout(user_data[USER_INPUT_DATA], user[LANG]) context.bot.edit_message_reply_markup( update.effective_chat.id, user_data[USER_INPUT_DATA].pop(MESSAGE_ID)) if user_data[USER_INPUT_DATA][PHOTO]: message = update.message.reply_photo( user_data[USER_INPUT_DATA][PHOTO].get('file_id'), layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) else: message = update.message.reply_html(layout, reply_markup=inline_keyboard) state = 'edit' user_data[USER_INPUT_DATA][STATE] = state user_data[USER_INPUT_DATA][MESSAGE_ID] = message.message_id return state
def edit_volume_callback(update: Update, context: CallbackContext): callback_query = update.callback_query user_data = context.user_data user = user_data['user_data'] if callback_query: data = callback_query.data if data == 'back': inline_keyboard = InlineKeyboard(edit_cargo_info_keyboard, user[LANG]).get_keyboard() answer = None state = 'edit_cargo_info' if data == 'delete': user_data[USER_INPUT_DATA][VOLUME] = None inline_keyboard = InlineKeyboard(edit_keyboard, user[LANG]).get_keyboard() if user[LANG] == LANGS[0]: answer = "Yuk hajmi tahrirlandi" if user[LANG] == LANGS[1]: answer = "Объем груза изменен" if user[LANG] == LANGS[2]: answer = "Юк ҳажми таҳрирланди" answer = '\U0001F44F\U0001F44F\U0001F44F ' + answer state = 'edit' layout = get_new_cargo_layout(user_data[USER_INPUT_DATA], user[LANG]) callback_query.answer(answer) if user_data[USER_INPUT_DATA][PHOTO]: callback_query.edit_message_caption(layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) else: callback_query.edit_message_text(layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) user_data[USER_INPUT_DATA][STATE] = state return state else: text = update.message.text if not text.isdigit(): if user[LANG] == LANGS[0]: error_text = "Yuk hajmini raqamda kiriting" if user[LANG] == LANGS[1]: error_text = "Введите объем груза цифрами" if user[LANG] == LANGS[0]: error_text = "Юк ҳажмини рақамда киритинг" error_text = f'\U000026A0 {error_text} !' update.message.reply_text(error_text, quote=True) return user_data[USER_INPUT_DATA][STATE] if user[LANG] == LANGS[0]: answer = "Yuk hajmi tahrirlandi" if user[LANG] == LANGS[1]: answer = "Объем груза изменен" if user[LANG] == LANGS[2]: answer = "Юк ҳажми таҳрирланди" answer = '\U0001F44F\U0001F44F\U0001F44F ' + answer update.message.reply_text(answer) inline_keyboard = InlineKeyboard(edit_keyboard, user[LANG]).get_keyboard() user_data[USER_INPUT_DATA][VOLUME] = text layout = get_new_cargo_layout(user_data[USER_INPUT_DATA], user[LANG]) context.bot.edit_message_reply_markup( update.effective_chat.id, user_data[USER_INPUT_DATA].pop(MESSAGE_ID)) if user_data[USER_INPUT_DATA][PHOTO]: message = update.message.reply_photo( user_data[USER_INPUT_DATA][PHOTO].get('file_id'), layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) else: message = update.message.reply_html(layout, reply_markup=inline_keyboard) state = 'edit' user_data[USER_INPUT_DATA][STATE] = state user_data[USER_INPUT_DATA][MESSAGE_ID] = message.message_id return state
def edit_to_location_callback(update: Update, context: CallbackContext): user_data = context.user_data user = user_data['user_data'] callback_query = update.callback_query if callback_query: data = callback_query.data layout = get_new_cargo_layout(user_data[USER_INPUT_DATA], user[LANG]) if data == 'back': inline_keyboard = InlineKeyboard(edit_address_keyboard, user[LANG]).get_keyboard() answer = None state = 'edit_address' if data == 'delete': user_data[USER_INPUT_DATA][TO_LOCATION] = None inline_keyboard = InlineKeyboard(edit_keyboard, user[LANG]).get_keyboard() if user[LANG] == LANGS[0]: answer = "Qabul qiluvchi geolokatsiyasi tahrirlandi" if user[LANG] == LANGS[1]: answer = "Геолокация получателя изменена" if user[LANG] == LANGS[2]: answer = "Қабул қилувчи геолокацияси таҳрирланди" answer = '\U0001F44F\U0001F44F\U0001F44F ' + answer state = 'edit' callback_query.answer(answer) if user_data[USER_INPUT_DATA][PHOTO]: callback_query.edit_message_caption(layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) else: callback_query.edit_message_text(layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) user_data[USER_INPUT_DATA][STATE] = state return state else: if update.message.location: longitude = update.message.location.longitude latitude = update.message.location.latitude user_data[USER_INPUT_DATA][TO_LOCATION] = { 'longitude': longitude, 'latitude': latitude } if user[LANG] == LANGS[0]: answer = "Qabul qiluvchi geolokatsiyasi tahrirlandi" if user[LANG] == LANGS[1]: answer = "Геолокация получателя изменена" if user[LANG] == LANGS[2]: answer = "Қабул қилувчи геолокацияси таҳрирланди" answer = '\U0001F44F\U0001F44F\U0001F44F ' + answer update.message.reply_text(answer) layout = get_new_cargo_layout(user_data[USER_INPUT_DATA], user[LANG]) inline_keyboard = InlineKeyboard(edit_keyboard, user[LANG]).get_keyboard() context.bot.edit_message_reply_markup(update.effective_chat.id, user_data[USER_INPUT_DATA].pop('message_id')) if user_data[USER_INPUT_DATA][PHOTO]: message = update.message.reply_photo(user_data[USER_INPUT_DATA][PHOTO]['file_id'], caption=layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) else: message = update.message.reply_html(layout, reply_markup=inline_keyboard) state = 'edit' user_data[USER_INPUT_DATA][STATE] = state user_data[USER_INPUT_DATA][MESSAGE_ID] = message.message_id return state else: if user[LANG] == LANGS[0]: error_text = "Yukni jo'natish geolokatsiyasini yuboring" if user[LANG] == LANGS[1]: error_text = "Отправите геолокацию доставки" if user[LANG] == LANGS[2]: error_text = "Юкни жўнатиш геолокациясини юборинг" error_text = f'\U000026A0 {error_text} !' update.message.reply_text(error_text, quote=True) return user_data[USER_INPUT_DATA][STATE]
def confirmation_callback(update: Update, context: CallbackContext): callback_query = update.callback_query data = callback_query.data user_data = context.user_data user = user_data['user_data'] logger.info('user_input_data: %s', user_data[USER_INPUT_DATA]) if data == 'confirm': if user[LANG] == LANGS[0]: text = "E'lon tasdiqlandi" if user[LANG] == LANGS[1]: text = 'Объявление подтверждено' if user[LANG] == LANGS[2]: text = "Эълон тасдиқланди" text = f'\U00002705 {text} !' if user_data[USER_INPUT_DATA][FROM_LOCATION] or user_data[ USER_INPUT_DATA][TO_LOCATION]: inline_keyboard = InlineKeyboard(confirm_keyboard, lang='cy', data=user_data[USER_INPUT_DATA], geolocation=True).get_keyboard() else: inline_keyboard = None user_data[USER_INPUT_DATA][STATE] = 'opened' cargo_data_for_insert = dict(user_data[USER_INPUT_DATA]) cargo_data_for_insert.pop(NAME) cargo_data_for_insert.pop(SURNAME) cargo_data_for_insert.pop(USERNAME) cargo_data_for_insert.pop(MESSAGE_ID) insert_cargo_id = insert_cargo(cargo_data_for_insert) if insert_cargo_id: user_data[USER_INPUT_DATA][ID] = insert_cargo_id layout = get_new_cargo_layout(user_data[USER_INPUT_DATA], user[LANG]) layout_2 = get_new_cargo_layout(user_data[USER_INPUT_DATA], 'cy') if user_data[USER_INPUT_DATA][PHOTO]: message = context.bot.send_photo( GROUP_ID, user_data[USER_INPUT_DATA][PHOTO].get('file_id'), layout_2, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) else: message = context.bot.send_message( GROUP_ID, layout_2, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) update_cargo_post_id(message.message_id, insert_cargo_id) else: layout = 'ERROR' text = layout if user_data[USER_INPUT_DATA][PHOTO]: callback_query.edit_message_caption(layout, parse_mode=ParseMode.HTML) else: callback_query.edit_message_text(layout, parse_mode=ParseMode.HTML) reply_keyboard = ReplyKeyboard(menu_keyboard, user[LANG]).get_keyboard() callback_query.message.reply_text(text, reply_markup=reply_keyboard) del user_data[USER_INPUT_DATA] state = ConversationHandler.END if data == 'edit': # with open('jsons/callback_query.json', 'w') as cargo: # cargo.write(callback_query.to_json()) inline_keyboard = InlineKeyboard(edit_keyboard, user[LANG]).get_keyboard() callback_query.answer() callback_query.edit_message_reply_markup(inline_keyboard) state = EDIT user_data[USER_INPUT_DATA][STATE] = state return state
def main_inline_keyboard_callback(update: Update, context: CallbackContext): # with open('callback_query.json', 'w') as callback_query_file: # callback_query_file.write(callback_query.to_json()) user_data = context.user_data set_user_data(update.effective_user.id, user_data) user = user_data['user_data'] callback_query = update.callback_query data = callback_query.data match_obj = re.search(r'^(\d+_closed)$', data) match_obj_2 = re.search(r'^(w_\d+)$', data) if match_obj: # print(data) data = match_obj.string.split('_') cargo_id = int(data[0]) cargo_status = data[-1] return_value = update_cargo_status(cargo_id, cargo_status) if return_value == 'updated' or return_value == 'not updated': user_data['user_cargoes'] = get_user_cargoes(user[ID]) cargo_data = get_cargo_by_id(cargo_id) shipping_datetime = cargo_data['shipping_datetime'] cargo_data[DATE] = shipping_datetime.strftime('%d-%m-%Y') cargo_data[TIME] = shipping_datetime.strftime('%H:%M') cargo_data[FROM_LOCATION] = None cargo_data[TO_LOCATION] = None cargo_data[NAME] = user[NAME] cargo_data[SURNAME] = user[SURNAME] cargo_data[USERNAME] = user[USERNAME] layout = get_new_cargo_layout(cargo_data, user[LANG]) layout_2 = get_new_cargo_layout(cargo_data, 'cy', hide_user_data=True) open_text = inline_keyboard_types[paginate_keyboard][user[LANG]][1] button4_text = f'{open_text}' button4_data = f'{cargo_id}_opened' inline_keyboard = callback_query.message.reply_markup inline_keyboard['inline_keyboard'][-1][0] = InlineKeyboardButton( button4_text, callback_data=button4_data) callback_query.answer() callback_query.edit_message_text(layout, parse_mode=ParseMode.HTML, reply_markup=inline_keyboard) if return_value == 'updated': if cargo_data['photo_id']: context.bot.edit_message_caption(GROUP_ID, cargo_data[POST_ID], caption=layout_2, parse_mode=ParseMode.HTML) else: context.bot.edit_message_text(layout_2, GROUP_ID, cargo_data[POST_ID], parse_mode=ParseMode.HTML) elif match_obj_2: user_data['user_cargoes'] = get_user_cargoes(user[ID]) wanted = int(match_obj_2.string.split('_')[-1]) wanted_cargo_data = user_data['user_cargoes'][wanted - 1] shipping_datetime = wanted_cargo_data['shipping_datetime'] wanted_cargo_data[DATE] = shipping_datetime.strftime('%d-%m-%Y') wanted_cargo_data[TIME] = shipping_datetime.strftime('%H:%M') wanted_cargo_data[NAME] = user[NAME] wanted_cargo_data[SURNAME] = user[SURNAME] wanted_cargo_data[USERNAME] = user[USERNAME] layout = get_new_cargo_layout(wanted_cargo_data, user[LANG]) inline_keyboard = InlineKeyboard( paginate_keyboard, user[LANG], data=(wanted, user_data['user_cargoes'])).get_keyboard() callback_query.answer() callback_query.edit_message_text(layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) elif data == BUTTONS_DATA_DICT[7] or data == BUTTONS_DATA_DICT[ 8] or data == BUTTONS_DATA_DICT[9]: if data == BUTTONS_DATA_DICT[7]: lang = LANGS[0] text = "Til: O'zbekcha" reply_text = "Til o'zgartirildi" edited_text = '\U0001F1FA\U0001F1FF' elif data == BUTTONS_DATA_DICT[8]: lang = LANGS[1] text = "Язык: русский" reply_text = 'Язык был изменен' edited_text = '\U0001F1F7\U0001F1FA' elif data == BUTTONS_DATA_DICT[9]: lang = LANGS[2] text = "Тил: Ўзбекча" reply_text = "Тил ўзгартирилди" edited_text = '\U0001F1FA\U0001F1FF' context.bot.answer_callback_query(callback_query.id, reply_text) update_user_info(user[TG_ID], lang=lang) user_data['user_data'][LANG] = lang reply_keyboard = ReplyKeyboard(menu_keyboard, lang).get_keyboard() callback_query.edit_message_text(edited_text) callback_query.message.reply_text(text, reply_markup=reply_keyboard) else: callback_query.answer()
def edit_weight_unit_callback(update: Update, context: CallbackContext): user_data = context.user_data user = user_data['user_data'] callback_query = update.callback_query data = callback_query.data if data == 'back': inline_keyboard = InlineKeyboard(edit_cargo_info_keyboard, user[LANG]).get_keyboard() layout = get_new_cargo_layout(user_data[USER_INPUT_DATA], user[LANG]) answer = None state = 'edit_cargo_info' if data == 'delete': user_data[USER_INPUT_DATA][WEIGHT] = None inline_keyboard = InlineKeyboard(edit_keyboard, user[LANG]).get_keyboard() layout = get_new_cargo_layout(user_data[USER_INPUT_DATA], user[LANG]) if user[LANG] == LANGS[0]: answer = "Yuk og'irligi tahrirlandi" if user[LANG] == LANGS[1]: answer = "Вес груза изменен" if user[LANG] == LANGS[2]: answer = "Юк оғирлиги таҳрирланди" answer = '\U0001F44F\U0001F44F\U0001F44F ' + answer state = 'edit' if callback_query.data == 'kg' or callback_query.data == 't': user_data[USER_INPUT_DATA]['new_weight_unit'] = callback_query.data if user[LANG] == LANGS[0]: text = "Yangi yuk og'irligini yuboring (raqamda)" button_text = "Ortga" if user[LANG] == LANGS[1]: text = "Отправьте новый вес груза (цифрами)" button_text = "Назад" if user[LANG] == LANGS[2]: text = "Янги юк оғирлигини юборинг (рақамда)" button_text = "Ортга" text = f'{text} :' button_text = '« ' + button_text layout = text inline_keyboard = InlineKeyboardMarkup([ [InlineKeyboardButton(button_text, callback_data='back')], ]) answer = None state = 'edit_weight' callback_query.answer(answer) if user_data[USER_INPUT_DATA][PHOTO]: callback_query.edit_message_caption(layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) else: callback_query.edit_message_text(layout, reply_markup=inline_keyboard, parse_mode=ParseMode.HTML) user_data[USER_INPUT_DATA][STATE] = state return state