def do_propose_sex_choose(self, client: VKinderClient): client.status = STATUSES['sex_choose_wait'] sexes = [f'{sex_id}. {sex}' for sex_id, sex in SEXES.items()] keyboard = self.cmd.kb( ['woman', 'man', 'anybody', None, 'back', 'quit']) self.send_msg(client, '\n'.join(sexes), keyboard=keyboard) self.send_msg(client, PHRASES['choose_sex_number'])
def do_propose_max_age_enter(self, client: VKinderClient): client.status = STATUSES['max_age_input_wait'] keyboard = self.cmd.kb(['back', 'quit']) self.send_msg(client, PHRASES['enter_max_age_from_x_127'].format( client.search.min_age), keyboard=keyboard)
def do_show_next_user(self, client: VKinderClient): self.send_typing_activity(client) client.status = STATUSES['decision_wait'] client.active_user = client.get_next_user() # if we already showed all pairs if not client.active_user: self.do_send_to_start_due_to_reach_end(client) self.do_propose_start_search(client) return client.active_user.photos = self.vk_personal.get_user_photos( client.active_user.vk_id) if not client.active_user.photos: client.active_user.photos = self.vk_personal.get_user_photos( client.active_user.vk_id, album_id='wall') photos = [ f'photo{photo.owner_id}_{photo.id}' for photo in client.active_user.photos ] photos_str = ','.join(photos) log( f'[{client.fname} {client.lname}] Showing user: {client.active_user.fname} ' f'{client.active_user.lname} with {len(client.active_user.photos)} photos', self.debug_mode) age_str = f', возраст: {client.active_user.age}' if client.active_user.age else '' user_info = f'{client.active_user.fname} {client.active_user.lname} ' user_info += f'({client.active_user.city_name}{age_str})' user_info += f'{last_seen(client.active_user.last_seen_time)}\nhttps://vk.com/{client.active_user.domain}' keyboard = self.cmd.kb(['yes', 'no', 'ban', None, 'back', 'quit']) self.send_msg(client, user_info, attachment=photos_str, keyboard=keyboard) self.send_msg(client, PHRASES['do_you_like_it']) self.db.save_photos(client)
def do_propose_status_choose(self, client: VKinderClient): client.status = STATUSES['status_choose_wait'] statuses = [ f'{status_id}. {status}' for status_id, status in LOVE_STATUSES.items() ] keyboard = self.cmd.kb(['back', 'quit']) self.send_msg(client, '\n'.join(statuses), keyboard=keyboard) self.send_msg(client, PHRASES['choose_love_status_number'])
def do_start_search_creating(self, client: VKinderClient): client.status = STATUSES['city_input_wait'] # revert to default for new search client.rating_filter = RATINGS['new'] client.reset_search() keyboard = self.cmd.kb(['country', None, 'back', 'quit']) self.send_msg(client, PHRASES['enter_city_name_in_x'].format( client.country_name), keyboard=keyboard)
def do_show_rated_users(self, msg: str, client: VKinderClient): client.status = STATUSES['loading_users'] if msg in self.cmd.get('banned'): client.rating_filter = RATINGS['banned'] elif msg in self.cmd.get('disliked'): client.rating_filter = RATINGS['disliked'] else: client.rating_filter = RATINGS['liked'] self.db.load_users_from_db(client) if client.found_users: self.do_show_next_user(client) else: self.send_msg(client, PHRASES['no_peoples_found']) self.do_propose_start_search(client)
def do_propose_start_search(self, client: VKinderClient): client.status = STATUSES['invited'] client.rating_filter = RATINGS['new'] if len(client.searches) == 0: keyboard = self.cmd.kb(['yes', 'no']) self.send_msg(client, PHRASES['do_you_want_to_find_pair'], keyboard=keyboard) else: keyboard = self.cmd.kb([ 'new search', 'show history', None, 'liked', 'disliked', 'banned', None, 'quit' ]) self.send_msg(client, PHRASES['you_have_search_history'], keyboard=keyboard)
def do_propose_city_name_choose(self, city: str, client: VKinderClient): client.status = STATUSES['city_choose_wait'] self.send_typing_activity(client) # this needed to prevent repeated search operations with same city name if city: client.found_cities = self.vk_personal.search_cities( country_id=client.country_id, city_name=city) cities = [ f'{index}. {format_city_name(city)}' for index, city in enumerate(client.found_cities, 1) ] if cities: keyboard = self.cmd.kb(['back', 'quit']) self.send_msg(client, '\n'.join(cities), keyboard=keyboard) self.send_msg(client, PHRASES['choose_city_number']) else: self.send_msg(client, PHRASES['no_such_city_name']) self.do_start_search_creating(client)
def do_show_search_history(self, client: VKinderClient): client.status = STATUSES['search_history_input_wait'] client.rating_filter = RATINGS['new'] searches = self.db.load_searches(client) client.searches = searches history = [] for index, searches in enumerate(searches, 1): history.append( str(index) + '. ' + PHRASES['x_x_x_from_x_to_x'].format( searches.city_name, SEXES[searches.sex_id], LOVE_STATUSES[ searches.status_id], searches.min_age, searches.max_age)) if history: keyboard = self.cmd.kb(['back', 'quit']) self.send_msg(client, '\n'.join(history), keyboard=keyboard) self.send_msg(client, PHRASES['choose_search_history_number']) else: self.send_msg(client, PHRASES['no_search_history']) self.do_propose_start_search(client)
def on_country_name_input(self, country_name: str, client: VKinderClient): client.status = STATUSES['country_choose_wait'] self.send_typing_activity(client) # this needed to prevent repeated search operations for countries names if not self.countries: self.countries = self.vk_personal.get_countries() # filter countries by country_name client.found_countries = [ country for country in self.countries if country.title.lower().find(country_name) > -1 ] countries = [ f'{index}. {country.title}' for index, country in enumerate(client.found_countries, 1) ] if countries: keyboard = self.cmd.kb(['back', 'quit']) self.send_msg(client, '\n'.join(countries), keyboard=keyboard) self.send_msg(client, PHRASES['choose_country_number']) else: self.send_msg(client, PHRASES['no_such_city_name']) self.do_propose_country_name_input(client)
def do_users_search(self, client: VKinderClient): client.status = STATUSES['loading_users'] params = PHRASES['city_x_sex_x_status_x_age_xx'].format( client.search.city_name, SEXES[client.search.sex_id], LOVE_STATUSES[client.search.status_id], client.search.min_age, client.search.max_age) self.send_msg(client, f'{PHRASES["started_search_peoples"]}\n({params})') self.send_typing_activity(client) self.db.save_search(client) client.found_users = self.vk_personal.search_users( city_id=client.search.city_id, sex_id=client.search.sex_id, love_status_id=client.search.status_id, age_from=client.search.min_age, age_to=client.search.max_age) client.found_users = [ user for user in client.found_users if not user.is_closed and user.last_seen_time ] client.found_users.sort(key=lambda x: x.last_seen_time, reverse=True) if client.found_users: self.db.load_users_ratings_from_db(client) ratings_sum = get_users_ratings_counts(client.found_users) self.send_msg( client, PHRASES['found_x_peoples_x_new_x_liked_x_disliked_x_banned']. format(len(client.found_users), ratings_sum['new'], ratings_sum['liked'], ratings_sum['disliked'], ratings_sum['banned'])) if ratings_sum['new'] > 0: self.db.save_users(client) self.do_show_next_user(client) else: self.send_msg(client, PHRASES['no_new_peoples_found']) self.do_propose_start_search(client) else: self.send_msg(client, PHRASES['no_peoples_found']) self.do_propose_start_search(client)
def do_send_to_start_due_to_reach_end(self, client: VKinderClient): client.status = STATUSES['has_contacted'] self.send_msg(client, PHRASES['well_lets_start_again'])
def do_send_to_start_after_absence(self, client: VKinderClient): client.status = STATUSES['has_contacted'] self.send_msg( client, PHRASES['sorry_x_you_was_absent_for_x_seconds'].format( client.fname, self.client_activity_timeout))
def do_propose_country_name_input(self, client: VKinderClient): client.status = STATUSES['country_input_wait'] keyboard = self.cmd.kb(['back', 'quit']) self.send_msg(client, PHRASES['enter_country_name'], keyboard=keyboard)