示例#1
0
 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}
示例#2
0
 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
         }