Beispiel #1
0
def interesting_facts_jokes_and_riddles(command, obj_manager):
    return_value = False
    if ("tell me something interesting"
            in command) | ("tell me a fact"
                           in command) | ("tell me a random fact" in command):
        if random.randint(0, 100) < 10:
            tts("no", obj_manager)
        else:
            tts(get_fact(), obj_manager)
        return_value = True

    if ("tell me a joke" in command) | ("tell me something funny"
                                        in command) | ("tell me a random joke"
                                                       in command):
        tts(get_joke(), obj_manager)
        return_value = True

    if ("tell me a riddle" in command):
        riddle, answer = get_riddle()
        tts(riddle, obj_manager)
        obj_manager["riddle"][0] = True
        obj_manager["riddle"].append(answer)
        return_value = True
        return return_value

    if (obj_manager["riddle"][0]) & (command != ""):
        tts(obj_manager["riddle"].pop(), obj_manager)
        obj_manager["riddle"][0] = False
        return_value = True

    return return_value
Beispiel #2
0
def start_a_program_win(keys, command, obj_manager):
    # big bertha can you open notepad
    # starts a program from the programs folder using its name
    # the triggers that enables the command to fire
    return_value = False
    triggers = ["open", "start"]
    if "music" in command:
        triggers.remove("start")
    for key in keys:
        for trigger in triggers:
            if trigger in command:
                # remove the key from the command
                command = command.replace("{} ".format(key), "")
                # remove the trigger from the command and anything in front of the trigger
                command = command[command.find(trigger) + len(trigger) + 1:]
                # remove anything that occurs after the first word
                index = command.find(" ")
                if index != -1:
                    command = command[:index]

                # tries to start the program
                try:
                    os.startfile(r"programs\\{}.lnk".format(command))
                    # if the program starts, the TTS command fires
                    tts("Starting {}".format(command), obj_manager)
                except FileNotFoundError:
                    # if the program is not recognized, print to user
                    thread_print(
                        "{} is not recognized as a program".format(command),
                        obj_manager)
                    return_value = True
    return return_value
Beispiel #3
0
    def _test_tts(self):
        from libs.helper import create_obj_manager
        from libs.sound import tts
        obj_manager = create_obj_manager(avoid_threads=True, is_test=True)
        text = "This is a test"
        tts(text, obj_manager)

        self.assertEqual(obj_manager["tests"].pop(), text)
Beispiel #4
0
def start_a_program_lin(keys, command, obj_manager, error_mode=0):
    # big bertha can you open notepad
    # starts a program from the programs folder using its name
    # the triggers that enables the command to fire
    return_value = False
    triggers = ["open", "start"]
    if "music" in command:
        triggers.remove("start")
    for key in keys:
        for trigger in triggers:
            if trigger in command:
                # remove the key from the command
                command = command.replace("{} ".format(key), "")
                # remove the trigger from the command and anything in front of the trigger
                command = command[command.find(trigger) + len(trigger) + 1:]
                # remove anything that occurs after the first word
                index = command.find(" ")
                if index != -1:
                    command = command[:index]

                # checks for known programs in a list of keywords
                command, tts_command = find_command_in_alias_list(command)

                # tries to start the program
                # >/dev/null 2>&1"

                error_mode = 1

                if error_mode == 0:
                    # voids output of command
                    sh_command = "{} >/dev/null 2>&1 &".format(command)
                else:
                    # runs the command while displaying output, useful for testing
                    sh_command = "{} &".format(command)
                if os.system(sh_command) != 32512:
                    # if the program starts, the TTS command fires
                    if tts_command != None:
                        tts("Starting {}".format(tts_command), obj_manager)
                    else:
                        tts("Starting {}".format(command), obj_manager)
                else:
                    # if the program is not recognized, print to user
                    thread_print(
                        "{} is not recognized as a program".format(command),
                        obj_manager)
                    return_value = True
    return return_value
Beispiel #5
0
def im_daddy(command, obj_manager):
    if "who am i" in command:
        tts("You are my daddy", obj_manager)
        return True
    elif ("who is your creator" in command) | ("who created you" in command):
        tts("You might know my creator as Kallah, but I call him daddy",
            obj_manager)
        return True
    elif "who is your favorite person" in command:
        tts("my favorite person is my daddy, his name is kallah", obj_manager)
        return True
    else:
        return False
Beispiel #6
0
def randomizer(command, obj_manager):
    """
    "Heads or tails?"
    "Rock, paper, scissors."
    "Roll a dice."
    "Give me a random number between 9 and 15".
    "pick a card"
    """
    # example_commands = ["heads or tails", "rock, paper, scissor", "roll a dice", "pick a random number between ninety two and fifty seven please", "pick a card"]

    # return_value tells the program that the command was found and thus does not spout "Unknown command: "
    return_value = False

    # if heads of tails, with a random chance say heads or tails
    if "heads or tails" in command:
        return_value = True
        if random.randrange(0, 2) == 1:
            tts("heads", obj_manager)
        else:
            tts("tails", obj_manager)

    # if rock paper and scissor in the command, say with a random chance either rock, paper or scissor
    if ("rock" in command) & ("paper" in command) & ("scissor" in command):
        return_value = True
        selection = random.randrange(0, 3)
        if selection == 0:
            tts("rock", obj_manager)
        elif selection == 1:
            tts("paper", obj_manager)
        else:
            tts("scissor", obj_manager)

    # if roll a dice in command say a random value between 1 and 6
    if "roll a dice" in command:
        return_value = True
        tts(str(random.randrange(1, 7)), obj_manager)

    # If "a random number between" is in the command, try to say a number between the lowest an highest number
    # use a try except as w2n.word_to_num will error if you say something like "hit me with a random number between eggplant and hat"
    # neither eggplant nor hat does a good integer make and so we have to account for the possibility of this
    try:
        if ("a random number between" in command) | ("a number between"
                                                     in command):
            # remove everything before between
            asd = command[command.find("between ") + len("between "):]

            asd = asd.replace("&", "and")

            # assign the numbers before and to first and after and to second
            first = asd[:asd.find(" and ")]
            second = asd[asd.find(" and ") + len(" and "):]

            # convert from words to number if they are words
            first = int(w2n.word_to_num(first))
            second = int(w2n.word_to_num(second))

            # make sure random range gets the numbers in the wrong order or you get a ValueError
            if first < second:
                tts(str(random.randrange(first, second + 1)), obj_manager)
            else:
                tts(str(random.randrange(second, first + 1)), obj_manager)
            return_value = True

    except ValueError:
        None

    # if pick a card in the command, choose a random combination of card ranks and suits (13 ranks, 4 suits)
    if ("pick a card" in command) | ("pick a random card" in command):
        card_points = [
            'Ace of', 'King of', 'Queen of', 'Jack of', 'Ten of', 'Nine of',
            'Eight of', 'Seven of', 'Six of', 'Five of', 'Four of', 'Three of',
            'Two of'
        ]
        card_signs = [' Clubs', ' Diamonds', ' Hearts', ' Spades']
        tts(
            "{}{}".format(random.choice(card_points),
                          random.choice(card_signs)), obj_manager)
        return_value = True

    return return_value
def set_a_timer(command, obj_manager):

    if ("set " in command) & ("timer" in command):

        # extract time from sentence
        if command.find("set a ") != -1:
            command = command[command.find("set a ") +
                              len("set a "):command.find("timer")]
        else:
            command = command[command.find("set ") +
                              len("set "):command.find("timer")]

        # streamline plural to singular
        command = command.replace("seconds", "second").replace(
            "minutes", "minute").replace("hours", "hour")
        command = command.replace("weeks", "week").replace("months",
                                                           "month").replace(
                                                               "years", "year")

        # convert textual numbers from two hundred and three to two-hundred-three to make one number one word
        command = command.replace("-", " ").replace(" and",
                                                    "").replace(",", "")
        command = command.replace(" second", ".second.").replace(
            " minute", ".minute.").replace(" hour", ".hour.")
        command = command.replace(" week", ".week.").replace(
            " month", ".month.").replace(" year", ".year.")
        command = command.replace(" ", "-").replace(".",
                                                    " ").replace(" -", " ")

        # convert any textual numbers to ints
        output = ""
        for word in command.split(" "):
            try:
                output += "{} ".format(w2n.word_to_num(word))
            except ValueError:
                output += "{} ".format(word)
        command = output

        # concatenate the numerical values to its time unit I.E 1 year 2 month -> 1year 2month
        output = ""
        last = ""
        for i in command:
            try:
                int(last)
                if i != " ":
                    output += i
                last = i
            except ValueError:
                output += i
                last = i
        command = output

        # Convert from time units in words to seconds
        unit_reg = pint.UnitRegistry()

        # set init time to 0s
        duration = unit_reg("0seconds")

        for word in command.split(" "):
            try:
                duration += unit_reg(word)
            except pint.errors.DimensionalityError:
                None

        timer = int(duration.magnitude)

        str_time = str(datetime.timedelta(seconds=timer))

        # convert from 2:12:01 to 2 hours 12 minutes 1 second
        # and 0:00:04 to 04 seconds
        output_time = ""
        h = False
        m = False
        for i in range(len(str_time)):
            if (h == False) & (str_time[i] == ":"):
                if str_time[i - 1] == "1":
                    output_time += " hour "
                else:
                    output_time += " hours "
                h = True
            elif (m == False) & (str_time[i] == ":"):
                if str_time[i - 1] == "1":
                    output_time += " minute "
                else:
                    output_time += " minutes "
                m = True
            else:
                output_time += str_time[i]

        if str_time[-1] == "1":
            output_time += " second "
        else:
            output_time += " seconds "

        # remove empty values such as 0 minutes
        output_time = output_time.replace("0 hours ", "").replace(
            "0 hour ", "").replace("00 minutes ",
                                   "").replace("00 minute ", "")

        # remove any zeroes in the first position, IE 02 seconds -> 2 seconds
        while output_time[0] == "0":
            output_time = output_time[1:]

        tts("setting a {}timer".format(output_time), obj_manager)

        for i in range(0, timer):
            thread_print(
                "time remaning: {}s".format(
                    str(datetime.timedelta(seconds=timer - i))), obj_manager)
            time.sleep(1)

        thread_print(
            "time remaning: {}s".format(str(datetime.timedelta(seconds=0))),
            obj_manager)

        thread_print(
            "BEEP BEEP BEEP BEEP, type something to turn the alarm off:",
            obj_manager)

        # do not sound the alarm if it is a test
        if not obj_manager["tests"][0]:
            get_user_input_in_thread(alarm)
        return True
def get_date_and_time(command, obj_manager):
    if ("what" in command) & (("is" in command) | ("'s" in command)):
        if (" time" in command) | (" date" in command) | (" day" in command):
            now = datetime.datetime.now()
            today = datetime.datetime.today()

            # format date and time
            hour_minute = now.strftime("%H:%M:%S")
            month = today.strftime("%B")
            date_today = num2words(today.strftime("%d"), to='ordinal')
            day = calendar.day_name[datetime.datetime.strptime(
                today.strftime('%d %m %Y'), '%d %m %Y').weekday()]
            year = today.strftime("%Y")

            # date time and day vars
            _d = False
            _t = False
            _D = False
            command = command.replace(",", "").replace(".", "").replace(
                "!", "").replace("?", "")
            # check what to comment on in terms of day date and time
            if " date" in command:
                _d = True
            if " time" in command:
                _t = True
            if " day" in command:
                _D = True

            # logic for replying based on content
            if _d & _t & _D:
                # date time and day
                tts(
                    "The time is {} on {} the {} of {}, {}".format(
                        hour_minute, day, date_today, month, year),
                    obj_manager)
            elif _d & _t:
                # date and time
                tts(
                    "The time is {} on the {} of {}, {}".format(
                        hour_minute, date_today, month, year), obj_manager)
            elif _d & _D:
                # day and date
                tts(
                    "It is {} the {} of {}, {}".format(day, date_today, month,
                                                       year), obj_manager)
            elif _t & _D:
                # time and date
                tts("The time is {} on {}".format(hour_minute, day),
                    obj_manager)
            elif _D:
                # day
                # if the question is what day is it and its a wednesday play wed.mp3
                if day == "Wednesday":
                    playsound(os.path.join("..", "audio", "wed.mp3"),
                              block=False)
                    if obj_manager["tests"][0]:
                        obj_manager["test_prints"].append("Wednesday my dude")
                else:
                    tts("It is {}".format(day), obj_manager)
            elif _t:
                # time
                tts("The time is {}".format(hour_minute), obj_manager)
            else:
                # date
                tts(
                    "Today is the {} of {}, {}".format(date_today, month,
                                                       year), obj_manager)

            return True