示例#1
0
def catalog_action(update: Update, context: CallbackContext):
    query = update.callback_query
    if 'categories' in query.data:
        return catalog_categories(update, context)
    elif 'submit_ad' in query.data:
        context.user_data['mode'] = 'catalog'
        account.change_role(update, context)
        return ConversationHandler.END
    elif 'close' in query.data:
        if 'catalog_photo_id' in context.user_data:
            try:
                context.bot.delete_message(
                    chat_id=query.message.chat_id,
                    message_id=context.user_data['catalog_photo_id'])
            except BadRequest:
                pass
        if 'catalog_message_id' in context.user_data:
            try:
                context.bot.delete_message(
                    chat_id=query.message.chat_id,
                    message_id=context.user_data['catalog_message_id'])
            except BadRequest:
                pass
        Navigation.to_account(update, context, new_message=True)
        return ConversationHandler.END
示例#2
0
def resumes_for_vacation(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 ConversationHandler.END
    query = update.callback_query
    language = context.user_data['user'].get('language')
    vacation_id = query.data.split(':')[1]
    if vacation_id == 'back':
        Navigation.to_account(update, context)
        return ConversationHandler.END
    resumes = vacations.get_resumes_for_vacation(vacation_id)
    if len(resumes) == 0:
        empty_message = strings.get_string('vacations.resumes.empty', language)
        query.answer(text=empty_message, show_alert=True)
        return LIST
    if type(resumes) is dict:
        resumes = list(resumes.values())
    context.user_data['found_resumes'] = resumes
    context.user_data['current_page'] = 1
    first_resume = resumes[0]
    user = users.user_exists(first_resume.get('user_id'))
    vacation_message = strings.from_resume(first_resume,
                                           language,
                                           for_vacation=True,
                                           user=user)
    vacations_keyboard = keyboards.get_list_paginated_keyboard(
        resumes, language)
    query.edit_message_text(text=vacation_message,
                            reply_markup=vacations_keyboard,
                            parse_mode=ParseMode.HTML)
    return RESUMES
示例#3
0
 def go_back():
     resume_message = strings.get_string('resumes.edit', language).format(
         context.user_data['editing_resume'].get('title'))
     Navigation.to_main_menu(
         update, language, user_name=context.user_data['user'].get('name'))
     edit_keyboard = keyboards.get_keyboard('resume.edit', language)
     message.reply_text(text=resume_message,
                        reply_markup=edit_keyboard,
                        parse_mode=ParseMode.HTML)
     return EDIT_ACTION
示例#4
0
def vacation_title(update, context):
    language = context.user_data['user'].get('language')
    if strings.get_string('go_back', language) in update.message.text:
        del context.user_data['vacation']
        Navigation.to_main_menu(
            update, language, user_name=context.user_data['user'].get('name'))
        Navigation.to_account(update, context)
        del context.user_data['has_action']
        return ConversationHandler.END
    context.user_data['vacation']['title'] = update.message.text
    message = strings.get_string('vacations.create.salary', language)
    update.message.reply_text(message, parse_mode=ParseMode.HTML)
    return SALARY
示例#5
0
def resume_title(update, context):
    language = context.user_data['user'].get('language')
    if strings.get_string('go_back', language) in update.message.text:
        Navigation.to_main_menu(
            update, language, user_name=context.user_data['user'].get('name'))
        Navigation.to_account(update, context)
        del context.user_data['has_action']
        del context.user_data['resume']
        return ConversationHandler.END
    context.user_data['resume']['title'] = update.message.text
    message = strings.get_string('resumes.create.description', language)
    update.message.reply_text(message, parse_mode=ParseMode.HTML)
    return DESCRIPTION
示例#6
0
def vacation_title(update, context):
    language = context.user_data['user'].get('language')
    if update.callback_query and update.callback_query.data == 'back':
        del context.user_data['vacation']
        Navigation.to_account(update, context)
        del context.user_data['has_action']
        return ConversationHandler.END
    context.user_data['vacation']['title'] = update.message.text
    message = strings.get_string('vacations.create.price', language)
    keyboard = keyboards.get_keyboard('go_back.inline', language)
    update.message.reply_text(message,
                              parse_mode=ParseMode.HTML,
                              reply_markup=keyboard)
    return PRICE
示例#7
0
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