def get_response(self): value = self.wit_response.get_values(self.keyword)[0] if value in self.possible_answers: index = randint(0, len(self.possible_answers[value]) - 1) text = self.possible_answers[value][index] return Response(text) return Response('Du schmeichelst mir')
def get_response(self): name = self.get_name_from_message() if name is None: text = 'Ich weiß leider nicht für wen die Nachricht ist...' return Response(text) text = name + ', ich soll dir das sagen:\n' + \ self.get_message_from_message() return Response(text)
def search_wiki(self): if not self.wit_response.has_key('query'): return Response('Ich weiß nicht was ich suchen soll') query = self.wit_response.get_values('query')[0] text = wikipedia.summary(query)[:300] array = text.split('.') array.pop() text = ''.join(array) return Response(text)
def search_wolfram(self): if not self.wit_response.has_key('term'): return Response('Ich weiß nicht was ich berechnen soll') term = self.wit_response.get_values('term')[0] result = wolfram_client.query(term) value = next(result.results).text text = random_answer(self.possible_answers, 'loese').format(term, value) return Response(text)
def delete_notification(self): time_value, finish_time = self._get_time() if finish_time is None: text = 'Ich weiß nicht welchen Timer ich löschen soll' return Response(text) for notification_object in notification_object_list: if notification_object.finish_time == int(finish_time): notification_object.stop_timer() text = 'Deine Erinnerung wurde gelöscht.' return Response(text)
def create_timer(self): if self.wit_response.has_key('duration'): value, unit = self.wit_response.get_values('duration') unit_value, unit = self.__get_unit(unit) if unit_value is not None: time_object = TimerObject(self.sleep_funtion, value * unit_value, unit) time_object.start_timer() text = 'Timer gestartet' return Response(text) else: return Response('Ich weiß nicht für wie lange ich den Timer stellen soll')
def create_notification(self): message = self._get_message() if message is None: return Response('Mir fehlt die Nachricht') time_value, finish_time = self._get_time() if time_value is None: text = 'Ich weiß nicht zu wann ich die Erinnerung stellen soll' return Response(text) NotificationObject(self.sleep_funtion, time_value, message, finish_time).start_timer() return Response('Erinnerung erstellt.')
def status_timer(self): time_object = self._get_time_object() if time_object is not None: return self.status_to_time(time_object.get_status()) else: if len(time_object_list) == 1: return self.status_to_time(time_object_list[0].get_status()) elif len(time_object_list) > 1: keyboard = {} for time_object in time_object_list: keyboard[time_object.name] = 'timer_status;' + time_object.name return Response('Welchen Timer meinst du?', keyboard, type='question') return Response('Es gibt zurzeit keine Timer.')
def get_response(self): value = self.wit_response.get_values(self.keyword)[0] if value == 'suche': return self.search_wiki() elif value == 'loese': return self.search_wolfram() return Response('Treffer')
def get_response(self): if self.wit_response.get_values(self.keyword)[0] == 'help': return self.HelpEntity().get_help() elif self.wit_response.get_values(self.keyword)[0] == 'voice_mode': return self.VoiceModeEntity().question_change_mode() else: return Response('Ich habe nicht den passenden Befehl gefunden')
def get_response(self): values = self.wit_response.get_values(self.keyword) text = '' if len(values) > 1: if values[1] == 'wie geht es': text += WelcomeEntity.get_greeting(self.possible_answers, values[0]) text += '\n' + WelcomeEntity.get_greeting( self.possible_answers, values[1]) text += WelcomeEntity.check_weather(values[1]) else: text += WelcomeEntity.get_greeting(self.possible_answers, values[0]) text += WelcomeEntity.check_weather(values[0]) if text != '': return Response(text) return Response('Hi')
def file_mode(self): bothandler.send_question( Response('Was soll ich mit den Audiodateien machen?', self.message, { 'Übersetzen': "change_mode;translate", 'Befehl': "change_mode;command" }, type='question'))
def delete_timer(self): time_object = self._get_time_object() if time_object is not None: time_object.stop_timer() text = 'Dein Timer wurde gelöscht.' return Response(text) else: # es wurde keine Zeit angegeben, also nimmt man den ersten, wenn es nur einen Timer gibt oder man wird # gefragt welchen man löschen will if len(time_object_list) == 1: time_object_list[0].stop_timer() text = 'Dein Timer wurde gelöscht.' return Response(text) elif len(time_object_list) > 1: keyboard = {} for time_object in time_object_list: keyboard[time_object.name] = 'timer_delete;' + time_object.name return Response('Welchen Timer willst du löschen?', keyboard, type='question') return Response('Es gibt keinen Timer')
def sleep_funtion(self, stop_thread, duration, time_object): assert isinstance(time_object, TimerObject) for i in range(duration, 0, -1): time.sleep(1) time_object.set_time(i) if stop_thread(): return time_object.delete_from_list() text = 'Dein Timer ist vorbei.' MessageQueue.add(Response(text), self.client_type)
def get_date(self): date = self._get_specific_date() if date is None: date = datetime.now(timezone('Europe/Berlin')) weekday = self._get_week_day_by_number(date.weekday()) day = date.day month = self._get_month_name_by_number(date.month) text = random_answer(self.possible_answers).format( day=day, daynumber=weekday, month=month) return Response(text)
def sleep_funtion(self, stop_thread, duration, text_message, notification_object): assert isinstance(notification_object, NotificationObject) for i in range(duration, 0, -1): time.sleep(1) notification_object.set_time(i) if stop_thread(): notification_object.stop_timer() return notification_object.delete_from_list() text = 'Ich soll dich daran erinnern \n"' + text_message + '"' MessageQueue.add(Response(text), self.client_type)
def get_weather(self): set_location = self.check_location_in_message() url = self.url.format(self.location) set_date = self.check_date_in_message() response = self.do_request(url) if set_date: temperature, description = self.weather_forecast( response, self.date) else: temperature, description = self.weather_today(response) if temperature is None or description is None: return Response('Ich konnte das Wetter nicht laden...') description = description.lower() temperature = str(int(temperature)) if set_location: if set_date: return Response( random_answer(self.possible_answers, 'location_future').format( location=self.location, weather=description, temperature=temperature)) return Response( random_answer(self.possible_answers, 'location').format(location=self.location, weather=description, temperature=temperature)) else: if set_date: return Response( random_answer(self.possible_answers, 'no_location_future').format( weather=description, temperature=temperature)) return Response( random_answer(self.possible_answers, 'no_location').format( weather=description, temperature=temperature))
def status_to_time(status): def print_seconds(seconds): hour = int(seconds / 3600) seconds -= hour * 3600 minutes = int(seconds / 60) seconds -= minutes * 60 return hour, minutes, seconds hour, minutes, seconds = print_seconds(status) hour = ' ' + str(hour) + ' Stunden' if hour > 0 else '' minutes = ' ' + str(minutes) + ' Minuten' if minutes > 0 else '' seconds = ' ' + str(seconds) + ' Sekunden' if seconds > 0 else '' text = 'Noch' + hour + minutes + seconds return Response(text)
def get_notifications(self): return Response('status')
def get_help(self): return Response('Welche Hilfe möchtest du haben?', { 'Hilfe': 'show_help', 'Usage': 'show_usage' }, type='question')
def question_change_mode(self): return Response('Wie sollen Sprachnachrichten behandelt werden?', { 'als Befehl': 'change_mode;m', 'als Text asugeben': 'change_mode;t' }, type='question')
def help(self): bothandler.send_message( Response('Hier ist deine Hilfe...', self.message))
def get_time(self): time = datetime.now( timezone('Europe/Berlin')).time().strftime('%H:%M') return Response('Es ist ' + time)
def get_name(self): index = randint(0, len(self.possible_answers) - 1) text = self.possible_answers[index] return Response(text)