Пример #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 about(message):
    abouts = {
        'Гарантии': MSG_GUARANTY,
        'О сервисе': MSG_ABOUT_SERVICE.format(SUPPORT_MAIL)
    }
    about_text = abouts.get(' '.join(message.text.split()[1:]))
    bot.send_message(message.chat.id, about_text, parse_mode='Markdown')
Пример #5
0
 def send_profiles(self):
     try:
         for id_, *info, preview_photo, last in pyutils.lookahead(self.girls):
             bot.send_photo(self._chat_id, preview_photo)
             self._send_profile_msg(id_, info, last)
     except RuntimeError:
         bot.send_message(self._chat_id, MSG_GIRLS_OVER_EXC, reply_markup=KB_MENU, parse_mode='Markdown')
Пример #6
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)
Пример #7
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)
Пример #8
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)
Пример #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 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)
Пример #11
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)
Пример #12
0
 def _send_other_location_msg(self, option_key, msg_text):
     msg = bot.send_message(self._chat_id,
                            msg_text,
                            self._message_id,
                            parse_mode='Markdown',
                            reply_markup=KB_CANCEL)
     bot.register_next_step_handler(
         msg,
         process_change_location_step,
         location=option_key,
     )
Пример #13
0
 def send_range_msg(self, option_key, default_values, msg):
     chat_msg = bot.send_message(self._chat_id,
                                 msg,
                                 parse_mode='Markdown',
                                 reply_markup=KB_CANCEL)
     bot.register_next_step_handler(
         chat_msg,
         process_change_range_option_val_step,
         default_values=default_values,
         filter_class=self._filter_class,
         key=option_key,
     )
Пример #14
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')
Пример #15
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)
Пример #16
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)
Пример #17
0
def filters(message):
    bot.send_message(message.chat.id,
                     MSG_FILTERS,
                     parse_mode='Markdown',
                     reply_markup=KB_FILTERS_MENU)
Пример #18
0
 def enter_promocode(chat_id):
     msg = bot.send_message(chat_id,
                            MSG_ENTER_PROMO,
                            parse_mode='Markdown',
                            reply_markup=KB_CANCEL)
     bot.register_next_step_handler(msg, process_promocode_step)
Пример #19
0
 def _send_profile_msg(self, id_, info, last):
     msg = MSG_GIRL_SHORT_INFO.format(*info)
     bot.send_message(self._chat_id, msg, reply_markup=self._get_keyboard(id_, last), parse_mode='Markdown')