示例#1
0
def set_catalog_profiles_limit(user_id, username, chat_id, message_id, new_val):
    def is_valid(val):
        return (val == 1 or val % 5 == 0) and val != 0

    if new_val:
        user = BotUtils.get_user(user_id, username)
        BotUtils.write_changes(user, 'catalog_profiles_num', new_val)

        msg = MSG_CATALOG.format(get_total_profiles())
        kb = create_main_catalog_keyboard(user.catalog_profiles_num)
        bot.edit_message_text(msg, chat_id, message_id, parse_mode='Markdown', reply_markup=kb)
        bot.send_message(chat_id, MSG_SUCCESS_CHANGE_OPTION, parse_mode='Markdown')
    else:
        bot.edit_message_text(
            MSG_CATALOG_NUM_PROFILES,
            chat_id,
            message_id,
            parse_mode='Markdown',
            reply_markup=Keyboards.create_inline_keyboard_ext(
                *(
                    KeyboardOption(name=f'{x}', callback=f'{PX_CAT_SET}profiles_num:{x}')
                    for x in range(11)
                    if is_valid(x)
                ), prefix='', row_width=1
            )
        )
示例#2
0
def process_change_range_option_val_step(message, **kwargs):
    user_id, username, chat_id, message_id, val = BotUtils.get_message_data(
        message)

    if val.endswith('Отмена'):
        bot.send_message(chat_id, MSG_CANCELED, reply_markup=KB_MENU)
        return

    default_values, filter_class, key = kwargs.values()
    valid_values = VALIDATORS.get('range').validate(
        value=val, default_values=default_values)

    if valid_values:
        BotUtils.write_changes(filter_class,
                               key,
                               valid_values,
                               filter_by={'user_id': user_id})
        bot.send_message(chat_id,
                         MSG_SUCCESS_CHANGE_OPTION,
                         parse_mode='Markdown',
                         reply_markup=KB_MENU)
    else:
        msg = bot.send_message(chat_id,
                               MSG_INCORRECT_VALUE,
                               parse_mode='Markdown')
        bot.register_next_step_handler(msg,
                                       process_change_range_option_val_step,
                                       **kwargs)
示例#3
0
def process_change_city_step(message):
    user_id, username, chat_id, message_id, msg_text = BotUtils.get_message_data(
        message)
    city = msg_text.capitalize()

    # TODO: validate city.
    # if city in ('Дмитров', 'Москва'):
    if city:
        BotUtils.write_changes(
            BotUtils.get_user(user_id, username).base_filter, 'city', city)

        if city == 'Москва':
            msg = bot.send_message(chat_id,
                                   MSG_ENTER_SUBWAY,
                                   parse_mode='Markdown')
            bot.register_next_step_handler(msg, process_change_subway_step)
            return

        bot.send_message(chat_id,
                         MSG_MENU_ATTENTION.format(SUPPORT_MAIL),
                         parse_mode='Markdown',
                         reply_markup=KB_MENU)

    elif msg_text == '/reset':
        msg = bot.send_message(chat_id, MSG_RESET, parse_mode='Markdown')
        bot.register_next_step_handler(msg, start)
    else:
        msg = bot.send_message(chat_id,
                               MSG_UNAVAILABLE_LOCATION.format(city),
                               parse_mode='Markdown')
        bot.register_next_step_handler(msg, process_change_city_step)
示例#4
0
def process_promocode_step(message):
    user_id, username, chat_id, message_id, promocode = BotUtils.get_message_data(
        message)
    promocode_data = PROMOCODES.get(promocode, None)

    if promocode.endswith('Отмена'):
        bot.send_message(chat_id,
                         MSG_CANCELED,
                         parse_mode='Markdown',
                         reply_markup=KB_MENU)
        return

    if promocode_data:
        user = BotUtils.get_user(user_id, username)
        user.promocode = promocode
        pyutils.set_attrs_values_from_dict(promocode_data,
                                           user,
                                           date_specific=True)

        BotUtils.write_changes(user)
        bot.send_message(chat_id,
                         MSG_SUCCESS_PROMO,
                         parse_mode='Markdown',
                         reply_markup=KB_MENU)
    else:
        msg = bot.send_message(chat_id,
                               MSG_ERROR_PROMO,
                               parse_mode='Markdown',
                               reply_markup=KB_CANCEL)
        bot.register_next_step_handler(msg, process_promocode_step)
示例#5
0
def catalog(message):
    user_id, username, chat_id, message_id, msg_text = BotUtils.get_message_data(
        message)
    catalog_profiles_num = BotUtils.get_obj(User, {
        'id': user_id
    }).catalog_profiles_num

    kb = create_main_catalog_keyboard(catalog_profiles_num)
    bot.send_message(chat_id,
                     MSG_CATALOG.format(get_total_profiles()),
                     parse_mode='Markdown',
                     reply_markup=kb)
示例#6
0
    def change_country_option_value(country, user_id, chat_id):
        BotUtils.write_changes(UserGirlBaseFilter,
                               'country',
                               country,
                               filter_by={'user_id': user_id})

        msg = bot.send_message(chat_id,
                               MSGS_LOCATIONS['city'],
                               parse_mode='Markdown',
                               reply_markup=KB_CANCEL)
        bot.register_next_step_handler(msg,
                                       process_change_location_step,
                                       location='city')
示例#7
0
    def change_enum_option_value(filter_name, option_key, value, user_id,
                                 username, chat_id, message_id):
        filter_class = FILTERS.get(filter_name)
        is_valid = VALIDATORS.get('enum').validate(enum_key=option_key,
                                                   value=value)

        if is_valid:
            obj = user_session.query(filter_class).filter_by(
                user_id=user_id).one()
            BotUtils.write_changes(obj, option_key, value)

        FiltersCBQ(filter_name, user_id, username, chat_id,
                   message_id).send_options()
示例#8
0
def start(message):
    user_id, username, chat_id, message_id, msg_text = BotUtils.get_message_data(
        message)
    BotUtils.get_user(user_id, username)

    welcome = MSG_WELCOME.format(username)

    bot.send_message(chat_id,
                     welcome,
                     parse_mode='Markdown',
                     reply_markup=types.ReplyKeyboardRemove())
    bot.send_message(chat_id,
                     MSG_ENTER_COUNTRY,
                     parse_mode='Markdown',
                     reply_markup=KB_COUNTRIES)
示例#9
0
def statistic(message):
    user_id, username, chat_id, message_id, msg_text = BotUtils.get_message_data(
        message)
    user = BotUtils.get_user(user_id, username)
    msg = MSG_STATISTIC.format(
        bot_active_days=0,
        total_ordered_girls=0,
        bot_total_money=0,
        days_since_register=user.days_since_register,
        total_txs=user.total_txs,
        total_qiwi_sum=int(user.total_qiwi_sum),
        total_girls=user.total_girls,
        total_girls_profiles=get_total_profiles(),
    )
    bot.send_message(chat_id, msg, parse_mode='Markdown')
示例#10
0
def discounts(message):
    user_id, username, chat_id, message_id, msg_text = BotUtils.get_message_data(
        message)
    user = BotUtils.get_user(user_id, username)
    if user.promocode:
        text = MSG_DISCOUNTS.format(user.promocode,
                                    str(user.promo_discount) + ' %',
                                    user.discount_expires_days)
    else:
        text = MSG_DISCOUNTS.format('не введен', 'отсутствует', 0)

    bot.send_message(chat_id,
                     text,
                     parse_mode='Markdown',
                     reply_markup=KB_PROMOCODE)
示例#11
0
 def _get_new_option_val(self):
     services = BotUtils.get_user(self._user_id,
                                  self._username,
                                  attr_name='services')
     column = self._get_selected_column()
     current_option_val = services.__getattribute__(column.key)
     return (services, column.key,
             False) if current_option_val else (services, column.key, True)
示例#12
0
def main_callback_query(call):
    user_id, username, chat_id, message_id, msg_text = BotUtils.get_message_data(
        call, callback=True)

    if re.search(PN_SET, msg_text):
        country = msg_text.split(':')[-1]
        process_change_country_step(country, user_id, username, chat_id)

    elif re.search(PN_ENTER, msg_text):
        MainCBQ.enter_promocode(chat_id)
示例#13
0
def catalog_callback_query(call):
    # TODO: начать просмотр девушек с N девушки (offset от юзверя)
    user_id, username, chat_id, message_id, msg_text = BotUtils.get_message_data(
        call, callback=True)
    default_args = (user_id, username, chat_id, message_id)
    default_kwargs = {
        'user_id': user_id,
        'username': username,
        'chat_id': chat_id,
        'message_id': message_id
    }

    if re.search(PN_CAT_SET, msg_text):
        try:
            new_val = msg_text.split(':')[2]
        except IndexError:
            new_val = None

        set_catalog_profiles_limit(*default_args, new_val)

    elif re.match(PN_CAT, msg_text):
        profiles_limit = msg_text.split(':')[1]
        CatProfiles(profiles_limit=profiles_limit,
                    **default_kwargs).send_profiles()

    elif re.match(PN_CAT_MORE, msg_text):
        profiles_limit = msg_text.split(':')[1]
        CatProfiles(profiles_limit=profiles_limit, more=True,
                    **default_kwargs).send_profiles()

    elif re.match(PN_CAT_PROFILE, msg_text):
        profiles_limit, girl_id, last_profile = msg_text.split(':')[1:]
        kwargs = {
            'girl_id': girl_id,
            'last_profile': last_profile,
            'profiles_limit': profiles_limit
        }
        CatProfileDetail(**kwargs, **default_kwargs).send_profile_detail()

    elif re.match(PN_CAT_PAY_BACK, msg_text):
        pass

    elif re.match(PN_CAT_PAY, msg_text):
        profiles_limit, girl_id, last_profile = msg_text.split(':')[1:]
        kwargs = {
            'girl_id': girl_id,
            'last_profile': last_profile,
            'profiles_limit': profiles_limit
        }
        CatPayment(**kwargs, **default_kwargs).send_payment()
示例#14
0
def process_change_subway_step(message):
    user_id, username, chat_id, message_id, msg_text = BotUtils.get_message_data(
        message)
    subway = msg_text.capitalize()

    # TODO: validate subway
    # if subway in ('Лефортово', 'Бассманная'):
    if subway:
        BotUtils.write_changes(
            BotUtils.get_user(user_id, username).base_filter, 'subway', subway)
        bot.send_message(chat_id,
                         MSG_MENU_ATTENTION.format(SUPPORT_MAIL),
                         parse_mode='Markdown',
                         reply_markup=KB_MENU)

    elif msg_text == '/reset':
        msg = bot.send_message(chat_id, MSG_RESET, parse_mode='Markdown')
        bot.register_next_step_handler(msg, start)
    else:
        msg = bot.send_message(chat_id,
                               MSG_UNAVAILABLE_LOCATION.format(subway),
                               parse_mode='Markdown')
        bot.register_next_step_handler(msg, process_change_subway_step)
示例#15
0
def process_change_location_step(message, **kwargs):
    # TODO: validate location
    # TODO: write location into DATABASE
    # TODO: register next step if city is moscow
    # TODO: if location is subway and city is not Moscow - revert

    user_id, username, chat_id, message_id, location = BotUtils.get_message_data(
        message)

    if location.endswith('Отмена'):
        bot.send_message(chat_id, MSG_CANCELED, reply_markup=KB_MENU)
        return

    bot.register_next_step_handler_by_chat_id(chat_id,
                                              process_change_location_step,
                                              kwargs=kwargs)
示例#16
0
def callback_query(call):
    msg_text = BotUtils.get_message_data(call, callback=True)[-1]
    call.data = pyutils.remove_prefix(call.data)

    if DEBUG:
        logger.info(f'--- CALLBACK DATA --- {msg_text}')

    try:
        if msg_text.startswith('MAIN'):
            main_callback_query(call)

        if msg_text.startswith('CAT'):
            catalog_callback_query(call)

        if msg_text.startswith('FIL') or msg_text.startswith('CH'):
            filters_callback_query(call)
    except:
        # todo: if exception is blocked bot by user - add user to block too and unblock when he restart the bot.
        logger.exception('CALLBACK QUERY ERRORS')
示例#17
0
def filters_callback_query(call):
    user_id, username, chat_id, message_id, msg_text = BotUtils.get_message_data(
        call, callback=True)
    default_kwargs = {
        'user_id': user_id,
        'username': username,
        'chat_id': chat_id,
        'message_id': message_id
    }

    if re.match(PN_FIL, msg_text) or re.match(PN_CH_BACK, msg_text):
        filter_name = msg_text.split(':')[1]
        FiltersCBQ(filter_name, *default_kwargs.values()).send_options()
        return

    elif re.match(PN_FIL_OP, msg_text):
        filter_name, option_key = msg_text.split(':')[1:]
        kwargs = {'filter_name': filter_name, 'option_name_key': option_key}
        kwargs.update(default_kwargs)
        FiltersOptionsHandler(**kwargs).send_change_option_value_msg()
        return

    elif re.match(PN_FIL_MOVE, msg_text):
        filter_name, move_where = msg_text.split(':')[1:]
        increment = 1 if move_where == 'next' else -1
        FiltersCBQ(filter_name, *default_kwargs.values(),
                   increment=increment).send_options()

    elif re.match(PN_FIL_ENTER, msg_text):
        country = msg_text.split(':')[-1]
        FiltersOptionsHandler.change_country_option_value(
            country, user_id, chat_id)

    elif re.match(PN_CH_SET, msg_text):
        filter_name, option_key, option_value = msg_text.split(':')[1:]
        FiltersOptionsHandler.change_enum_option_value(
            filter_name, option_key, option_value, *default_kwargs.values())
示例#18
0
def process_change_country_step(country_name, user_id, username, chat_id):
    user = BotUtils.get_user(user_id, username)
    BotUtils.write_changes(user.base_filter, 'country', country_name)

    msg = bot.send_message(chat_id, MSG_ENTER_CITY, parse_mode='Markdown')
    bot.register_next_step_handler(msg, process_change_city_step)
示例#19
0
 def girls_options(self):
     filter_ = BotUtils.get_user(self._user_id,
                                 self._username,
                                 attr_name=self._filter_name)
     return filter_.as_tuple(filter_)
示例#20
0
 def _get_user_filters_instances(self):
     user = BotUtils.get_user(self._user_id, self._username)
     return user.base_filter, user.ext_filter, user.services
示例#21
0
 def send_service_msg(self):
     o, key, new_option_val = self._get_new_option_val()
     BotUtils.write_changes(o, key, new_option_val)
     FiltersCBQ(self._filter_name, self._user_id, self._username,
                self._chat_id, self._message_id).send_options()