def handle_input(self, query): """Handles the input from the user and returns appropriate message.""" system = BeerAdvisor() # initialize beer advisory system user = User.get(User.chat_id == self.message.chat_id) system.input_data(query, user) recommended_beer = system.find_match() # find a match if recommended_beer: self.activate(False) # deactivates the listener reply = self.format_reply(recommended_beer) # turn the beer object into a human readable reply return reply # return the reply to the user else: meal_categories = system.get_categories() keyboard = self.format_keyboard(meal_categories) return {'message': self.dialogs['no_such_meal'] % query, 'keyboard': keyboard}
def reply(self): """Main function of the command, required by the PyBot framework.""" if not self.user_exists(self.message.chat_id): return { 'message': 'Please enter your preferences first by using /start.' } elif self.is_active(): return self.handle_input(self.message.text) elif self.arguments: return self.handle_input(self.arguments) else: self.activate() # activates the listener so it can receive input keyboard = self.format_keyboard(BeerAdvisor().get_categories()) return {'message': self.dialogs['specify'], 'keyboard': keyboard}
def handle_input(self, query): """Handles the input from the user and returns appropriate message.""" system = BeerAdvisor() # initialize beer advisory system user = User.get(User.chat_id == self.message.chat_id) system.input_data(query, user) recommended_beer = system.find_match() # find a match if recommended_beer: self.activate(False) # deactivates the listener reply = self.format_reply( recommended_beer ) # turn the beer object into a human readable reply return reply # return the reply to the user else: meal_categories = system.get_categories() keyboard = self.format_keyboard(meal_categories) return { 'message': self.dialogs['no_such_meal'] % query, 'keyboard': keyboard }
def user_exists(self, chat_id): system = BeerAdvisor() return system.check_database_for(user_chat_id=chat_id)