def faq(update, context): context.user_data['user'] = users.user_exists( update.callback_query.from_user.id) if context.user_data['user'].get('is_blocked'): blocked_message = strings.get_string( 'blocked', context.user_data['user'].get('language')) update.callback_query.answer(text=blocked_message, show_alert=True) return if context.user_data['user'].get('language') == 'uz': faq_message = settings.get_settings().get('faq_uz') else: faq_message = settings.get_settings().get('faq') faq_message = utils.replace_new_line(faq_message) faq_keyboard = keyboards.get_keyboard( 'faq', language=context.user_data['user'].get('language')) context.bot.delete_message( chat_id=update.effective_chat.id, message_id=update.callback_query.message.message_id) image = images.get_faq_image(context.user_data['user'].get('language')) if image: chat_id = update.effective_message.chat_id context.bot.send_photo(chat_id=chat_id, photo=image, caption=faq_message, parse_mode=ParseMode.HTML, reply_markup=faq_keyboard) else: update.effective_message.reply_text(text=faq_message, parse_mode=ParseMode.HTML, reply_markup=faq_keyboard)
def news(update, context): context.user_data['user'] = users.user_exists(update.message.from_user.id) if context.user_data['user'].get('is_blocked'): blocked_message = strings.get_string( 'blocked', context.user_data['user'].get('language')) update.message.reply_text(blocked_message) return if context.user_data['user'].get('language') == 'uz': news_message = settings.get_settings().get('news_uz') else: news_message = settings.get_settings().get('news') news_message = utils.replace_new_line(news_message) news_keyboard = keyboards.get_keyboard( 'news', language=context.user_data['user'].get('language')) image = images.get_news_image() if image: chat_id = update.message.chat_id message = context.bot.send_photo(chat_id=chat_id, photo=image, caption=news_message, parse_mode=ParseMode.HTML, reply_markup=news_keyboard) else: message = update.message.reply_text(text=news_message, parse_mode=ParseMode.HTML, reply_markup=news_keyboard) if 'news_message_id' in context.user_data: try: context.bot.delete_message( chat_id=update.message.chat_id, message_id=context.user_data['news_message_id']) except BadRequest: pass context.user_data['news_message_id'] = message.message_id
def partners(update, context): context.user_data['user'] = users.user_exists(update.message.from_user.id) if context.user_data['user'].get('is_blocked'): blocked_message = strings.get_string( 'blocked', context.user_data['user'].get('language')) update.message.reply_text(blocked_message) return bot_settings = settings.get_settings() language = context.user_data['user'].get('language') partners_keyboard = keyboards.get_keyboard('partners', language) if context.user_data['user'].get('language') == 'uz': ad_image_path = bot_settings.get('partners_ad_image_uz') partners_message = bot_settings.get('partners_uz') else: ad_image_path = bot_settings.get('partners_ad_image') partners_message = bot_settings.get('partners') if not partners_message: if context.user_data['user'].get('language') == 'uz': partners_message = bot_settings.get('partners_tariffs_uz') else: partners_message = bot_settings.get('partners_tariffs') partners_message = utils.replace_new_line(partners_message) if ad_image_path: if os.path.exists(ad_image_path): image = open(ad_image_path, 'rb') else: image = images.get_partners_image( context.user_data['user'].get('language')) else: image = images.get_partners_image( context.user_data['user'].get('language')) photo_message = None if image: chat_id = update.message.chat_id photo_message = context.bot.send_photo(chat_id=chat_id, photo=image) message = context.bot.send_message(chat_id=chat_id, text=partners_message, parse_mode=ParseMode.HTML, reply_markup=partners_keyboard) else: message = update.message.reply_text(text=partners_message, parse_mode=ParseMode.HTML, reply_markup=partners_keyboard) if 'partners_message_id' in context.user_data: try: context.bot.delete_message( chat_id=update.message.chat_id, message_id=context.user_data['partners_message_id']) except BadRequest: pass if 'partners_photo_id' in context.user_data: try: context.bot.delete_message( chat_id=update.message.chat_id, message_id=context.user_data['partners_photo_id']) except BadRequest: pass context.user_data['partners_message_id'] = message.message_id if photo_message: context.user_data['partners_photo_id'] = photo_message.message_id
def handle_tariffs(update, context): query = update.callback_query if 'user' not in context.user_data: context.user_data['user'] = users.user_exists(query.message.chat_id) if context.user_data['user'].get('language') == 'uz': tariffs_message = settings.get_settings().get('partners_tariffs_uz') else: tariffs_message = settings.get_settings().get('partners_tariffs') tariffs_message = utils.replace_new_line(tariffs_message) partners_keyboard = keyboards.get_keyboard( 'partners', context.user_data['user'].get('language')) try: query.edit_message_text(text=tariffs_message, parse_mode=ParseMode.HTML, reply_markup=partners_keyboard) except BadRequest: query.answer() pass
def about(update, context): context.user_data['user'] = users.user_exists(update.message.from_user.id) if context.user_data['user'].get('is_blocked'): blocked_message = strings.get_string('blocked', context.user_data['user'].get('language')) update.message.reply_text(blocked_message) return if context.user_data['user'].get('language') == 'uz': about_message = settings.get_settings().get('about_uz') else: about_message = settings.get_settings().get('about') about_message = utils.replace_new_line(about_message) about_keyboard = keyboards.get_keyboard('about', language=context.user_data['user'].get('language')) message = update.message.reply_text(text=about_message, parse_mode=ParseMode.HTML, reply_markup=about_keyboard) if 'about_message_id' in context.user_data: try: context.bot.delete_message(chat_id=update.message.chat_id, message_id=context.user_data['about_message_id']) except BadRequest: pass context.user_data['about_message_id'] = message.message_id
def about(update: Update, context): context.user_data['user'] = users.user_exists( update.callback_query.from_user.id) if context.user_data['user'].get('is_blocked'): blocked_message = strings.get_string( 'blocked', context.user_data['user'].get('language')) update.callback_query.answer(text=blocked_message, show_alert=True) return if context.user_data['user'].get('language') == 'uz': about_message = settings.get_settings().get('about_uz') else: about_message = settings.get_settings().get('about') about_message = utils.replace_new_line(about_message) about_keyboard = keyboards.get_keyboard( 'about', language=context.user_data['user'].get('language')) context.bot.delete_message( chat_id=update.effective_chat.id, message_id=update.callback_query.message.message_id) update.effective_message.reply_text(text=about_message, parse_mode=ParseMode.HTML, reply_markup=about_keyboard)
def start(update, context): user_id = update.message.from_user.id if 'user' not in context.user_data: context.user_data['user'] = users.user_exists(user_id) if context.user_data['user'].get('is_blocked'): blocked_message = strings.get_string( 'blocked', context.user_data['user'].get('language')) update.message.reply_text(blocked_message) return ConversationHandler.END context.user_data['has_action'] = True language = context.user_data['user'].get('language') bot_settings = settings.get_settings() support_message = bot_settings.get('support_' + language) if not support_message: support_message = strings.get_string( 'support.welcome', language).format(name=context.user_data['user'].get('name')) support_message = utils.replace_new_line(support_message) support_keyboard = keyboards.get_keyboard('support.cancel', language) image = None if bot_settings.get('support_image_' + language): try: image = open(bot_settings.get('support_image_' + language), 'rb') except FileNotFoundError: pass if not image: image = images.get_support_image(language) if image: chat_id = update.message.chat_id message = context.bot.send_photo(chat_id=chat_id, photo=image, caption=support_message, reply_markup=support_keyboard, parse_mode=ParseMode.HTML) else: message = update.message.reply_text(text=support_message, reply_markup=support_keyboard, parse_mode=ParseMode.HTML) context.user_data['support_message'] = message return SUPPORT
def vacation_categories(update, context): user = context.user_data['user'] language = user.get('language') query = update.callback_query category_id = query.data.split(':')[1] if category_id == 'back': current_category = context.user_data['current_category'] if current_category.get('parent_id'): siblings_category = categories.get_siblings( current_category.get('id')) siblings_category = sorted(siblings_category, key=lambda i: i['position']) message = strings.get_category_description(current_category, language) keyboard = keyboards.get_categories_keyboard( siblings_category, language, context.user_data['vacation']['categories']) query.answer() query.edit_message_text(text=message, reply_markup=keyboard) context.user_data['current_category'] = categories.get_category( current_category.get('parent_id')) return CATEGORIES else: return to_parent_categories(query, context) if category_id == 'save': context.user_data['user'] = users.user_exists( update.callback_query.from_user.id) if context.user_data['user'].get('is_blocked'): blocked_message = strings.get_string( 'blocked', context.user_data['user'].get('language')) update.callback_query.answer(text=blocked_message, show_alert=True) return ConversationHandler.END if user.get(user.get('user_role') + '_tariff') or user.get('free_actions_count') > 0: payment_settings = settings.get_settings() item_cost = payment_settings.get( user.get(user.get('user_role') + '_tariff')) user_balance = user.get('balance_' + user.get('user_role')) if user_balance is None: user_balance = 0 if user_balance >= int(item_cost) or user.get( 'free_actions_count') > 0: result = vacations.create_vacation( context.user_data['vacation']) vacation = result.get('vacation') context.user_data['user'] = vacation.get('user') success_message = strings.get_string( 'vacations.create.success', language) help_message = strings.get_string( 'vacations.create.success.help', language) context.bot.delete_message(chat_id=query.message.chat.id, message_id=query.message.message_id) context.bot.send_message(chat_id=query.message.chat.id, text=success_message) menu_keyboard = keyboards.get_keyboard('menu', language) help_image = images.get_help_panel_image() if help_image: context.bot.send_photo(chat_id=query.message.chat_id, photo=help_image, caption=help_message, parse_mode=ParseMode.HTML, reply_markup=menu_keyboard) else: context.bot.send_message(chat_id=query.message.chat.id, text=help_message, parse_mode=ParseMode.HTML, reply_markup=menu_keyboard) Navigation.to_account(update, context, new_message=True) del context.user_data['vacation'] del context.user_data['has_action'] Notifications.notify_users_new_item(context.bot, result.get('notifyUsers'), 'vacations.notify.new') if result.get('notifyUsers'): Notifications.notify_users_new_item( context.bot, [user], 'resumes.notify.new') return ConversationHandler.END empty_balance = strings.get_string('empty_balance', language) query.answer(text=empty_balance, show_alert=True) return payments.start(update, context) category = categories.get_category(category_id) children_categories = category.get('categories') if 'categories' not in context.user_data['vacation']: context.user_data['vacation']['categories'] = [] if children_categories: children_categories = sorted(children_categories, key=lambda i: i['position']) keyboard = keyboards.get_categories_keyboard( children_categories, language, context.user_data['vacation']['categories']) message = strings.get_category_description(category, language) query.edit_message_text(message, reply_markup=keyboard) context.user_data['current_category'] = category return CATEGORIES else: if any(d['id'] == category['id'] for d in context.user_data['vacation']['categories']): added = False context.user_data['vacation']['categories'][:] = [ c for c in context.user_data['vacation']['categories'] if c.get('id') != category.get('id') ] else: if len(context.user_data['vacation']['categories']) == 10: limit_message = strings.get_string('categories.limit', language) query.answer(text=limit_message, show_alert=True) return CATEGORIES added = True context.user_data['vacation']['categories'].append(category) category_siblings = categories.get_siblings(category_id) category_siblings = sorted(category_siblings, key=lambda i: i['position']) keyboard = keyboards.get_categories_keyboard( category_siblings, language, context.user_data['vacation']['categories']) message = strings.from_categories( category, context.user_data['vacation']['categories'], added, language) answer_message = strings.from_categories_message( category, context.user_data['vacation']['categories'], added, language) query.answer(text=answer_message) query.edit_message_text(message, reply_markup=keyboard) return CATEGORIES