Exemple #1
0
 def run(self, connectionInfo, slots):
     # First run check
     if "wake" in self.dataStore.keys():
         self.dataStore["wake"]["awake"] = True
         return Response(random.choice(["Ta-da!", ""]), "happy")
     return Response(random.choice(["There's no alarm to turn off."]),
                     "neutral")
Exemple #2
0
 def getWakeUpResponse(self):
     responseText = ""
     responseMood = ""
     if (self.getData("totalRuns") == 0):
         return Response(random.choice(["Time to wake up!", "Rise and shine!"]), "happy")
     else:
         return Response(random.choice(["Hey, get up already!", "Don't make me repeat myself!"]), "annoyed")
Exemple #3
0
 def run(self, connectionInfo, slots):
     if self.dataStore["isUserHome"]:
         return Response(random.choice(["But you're already home?"]),
                         "neutral")
     else:
         self.dataStore["isUserHome"] = True
         return Response(
             random.choice(
                 ["Welcome home!", "How was it out?", "Welcome back."]),
             "happy")
Exemple #4
0
 def run(self, connectionInfo, slots):
     responseText = ""
     if connectionInfo.ip in self.dataStore["connectedClients"].keys():
         del self.dataStore["connectedClients"][connectionInfo.ip]
         responseText = "Disconnected"
     else:
         responseText = "Not connected"
     response = Response(responseText, "neutral")
     return response
Exemple #5
0
 def run(self, connectionInfo, slots):
     responseText = ""
     if connectionInfo.ip in self.dataStore["connectedClients"].keys():
         responseText = "Already connected"
     else:
         connectionInfo.name = slots[0]
         self.dataStore["connectedClients"][
             connectionInfo.ip] = connectionInfo
         responseText = "Connected as " + connectionInfo.name
     response = Response(responseText, "happy")
     return response
Exemple #6
0
    def run(self, connectionInfo, slots):
        location = ""

        if len(slots) > 0:
            location = slots[0]
        else:
            location = getClientLocation(connectionInfo.ip)

        yahooJson = getWeatherForLocation(location)
        responseText, mood = processJsonToResponse(yahooJson)
        response = Response(responseText, mood)

        return response
Exemple #7
0
    def run(self, connectionInfo, slots):
        # Reset existing alarm
        if "wake" in self.dataStore.keys():
            self.dataStore["wake"]["awake"] = False
            self.dataStore["wake"]["totalRuns"] = 0

        # Set the wake up event
        cron = Cron()
        cron.addJob("wakeUp", datetime.datetime.fromtimestamp(int(slots[0])))
        responseText = "Alarm set for " + slots[
            0] + " and " + connectionInfo.name
        response = Response(responseText, "neutral")
        return response
Exemple #8
0
    def _handle(self):
        self.commands = CommandList(self.server.joshu.dataStore).commands
        self.data = self.request.recv(102400).strip()
        print(self.data)
        dataType = self.data[0]
        self.data = self.data[1:]

        if dataType == 0:  # Text
            self.data = self.data.decode('utf-8')
            print("{} wrote: {}".format(self.client_address[0], self.data))
            print(len(self.data))
        else:  # Voice
            print("Voice command received")
            print(len(self.data))
            f = open("output.wav", 'wb')
            f.write(self.data)
            f.close()
            self.data = 'connect home'  # TODO Fix it

        parameters = self.data.split(" ")
        intent = parameters[0]
        slots = parameters[1:] if len(parameters) > 1 else []

        print(intent)
        print(slots)
        print(self.server.joshu.dataStore["connectedClients"])

        # 'Auth'
        connectionInfo = None
        if self.client_address[0] in self.server.joshu.dataStore[
                "connectedClients"].keys():
            connectionInfo = self.server.joshu.dataStore["connectedClients"][
                self.client_address[0]]
            print("Message from: {} at IP {}".format(connectionInfo.name,
                                                     connectionInfo.ip))
        elif intent == "connect":
            connectionInfo = ConnectionInfo(self.client_address[0], "")
        else:
            response = Response("Not authorised", "neutral")
            self.request.sendall(bytes(response.getJson(), "utf-8"))
            return

        # Run command
        if (intent in self.commands.keys()):
            response = self.commands[intent].run(connectionInfo, slots)
            self.request.sendall(bytes(response.getJson(), "utf-8"))
        else:
            response = Response("Command not found", "neutral")
            self.request.sendall(bytes(response.getJson(), "utf-8"))
Exemple #9
0
    def run(self, connectionInfo, slots):
        response = None

        # Determine if the user should be at work
        config = Config()
        workdays = config.config["work"]["workdays"]
        workTimes = (config.config["work"]["workStart"],
                     config.config["work"]["workEnd"])
        workTimes = (time.strptime(workTimes[0], "%H:%M"),
                     time.strptime(workTimes[1], "%H:%M"))
        workTimes = (datetime.datetime.today().replace(
            hour=workTimes[0].tm_hour,
            minute=workTimes[0].tm_min), datetime.datetime.today().replace(
                hour=workTimes[1].tm_hour, minute=workTimes[1].tm_min))
        halfwayThroughDay = workTimes[0] + datetime.timedelta(
            seconds=(workTimes[1] - workTimes[0]).total_seconds() / 2)
        currentTime = datetime.datetime.now()

        # If they're not in and they're meant to be at work, send encouragement halfway through the day
        userAtWork = datetime.datetime.today().weekday() in workdays and (
            workTimes[0] < currentTime and currentTime < workTimes[1])
        shouldSendEncouragement = not self.dataStore[
            "isUserHome"] and userAtWork

        # Have we already done this today?
        shouldSendEncouragement = shouldSendEncouragement and self.dataStore[
            "encouragement"]["lastCalled"] != datetime.datetime.today().date()

        # Is it the right time of day?
        shouldSendEncouragement = shouldSendEncouragement and (
            currentTime > halfwayThroughDay)

        if shouldSendEncouragement:
            # Update last called time
            self.dataStore["encouragement"][
                "lastCalled"] = datetime.datetime.today().date()

            # TODO Send encouragement via FCM to messenger
            # For now, return response
            response = Response(random.choice(["Hope work is going well!"]),
                                "happy")
        self.enqueue(60)
        return response
Exemple #10
0
 def run(self, connectionInfo, slots):
     if self.dataStore["isUserHome"]:
         self.dataStore["isUserHome"] = False
         return Response(random.choice(["See you soon!", "Have a pleasant day!", "Catch you later."]), "happy")
     else:
         return Response(random.choice(["But you're already out?"]), "neutral")
Exemple #11
0
 def callback(data):
     response = Response.decodeJson(data)
     voice.speak(response.text)
Exemple #12
0
from threading import RLock
from .client import runClientThread, sendCommand
from app.shared.response import Response
from app.speechsynth import voice

if __name__ == "__main__":
    host = sys.argv[1]

    def callback(data):
        response = Response.decodeJson(data)
        voice.speak(response.text)

    # Setup
    lock = RLock()
    clientThread, server = runClientThread(lock, callback)

    # Main loop
    while True:
        data = input(">")
        if data == "quit":
            with lock:
                server.shutdown()
                break

        received = sendCommand(host, data, lock)
        response = Response.decodeJson(received)
        voice.speak(response.text)

    # Cleanup
    clientThread.join()
Exemple #13
0
def processResponse(json):
    try:
        response = Response.decodeJson(json)
        voiceResponse(response.text, response.mood, character)
    except JSONDecodeError:
        voiceResponse("Oops, something went wrong.", "neutral", character)
Exemple #14
0
 def run(self, connectionInfo, slots):
     # TODO Try and work out what the user wants, and then do it
     return Response(
         random.choice(["Really?", "That's interesting", "lol"]), "neutral")