Example #1
0
def process(sentence):
    """ Process the sentence """

    keywords = sentence.keywords(include=["VB", "NS"])
    paul.log("KEYWORDS:", keywords)

    if paul.has_one_of(keywords, ["mute", "silence", "silent, " "unmute"]):
        mute()
        return "Toggling mute."
    elif paul.has_one_of(keywords, ["volume", "louder", "quieter"]):
        return change_volume(keywords)
    elif paul.has_one_of(keywords, ["brightness", "brighter", "dimmer"]):
        return change_brightness(keywords)
    elif paul.has_word(keywords, "screensaver"):
        screensaver()
        return "Done!"
    elif paul.has_word(keywords, "desktop"):
        desktop()
        return "Done!"
    elif paul.has_one_of(keywords, ["lock", "sleep"]):
        sleep()
        return "Done!"
    elif paul.has_one_of(keywords, ["more", "again"]):
        return repeat()
    else:
        return "I couldn't manage that."
Example #2
0
def change_volume(keywords):
    """ Change the volume up or down, depending on the keywords """

    code = "set volume output volume (output volume of (get volume settings) {} 6.25)"
    if paul.has_one_of(keywords, VERBS_UP + ["turn up", "adjust up", "louder"]):
        code = code.format("+")
    elif paul.has_one_of(keywords, VERBS_DOWN + ["turn down", "adjust down", "quieter"]):
        code = code.format("-")
    else:
        return "I'm not sure how you wanted me adjust the volume."
    paul.set_it(code)
    paul.run_script(code, language="applescript")
    return "Done!"
Example #3
0
def change_brightness(keywords):
    """ Change the brightness up or down, depending on the keywords """
    code = 'tell application "System Events" to key code {}'
    up = "113"
    down = "107"

    if paul.has_one_of(keywords, VERBS_UP + ["turn up", "adjust up", "brighter"]):
        code = code.format(up)
    elif paul.has_one_of(keywords, VERBS_DOWN + ["turn down", "adjust down", "dimmer"]):
        code = code.format(down)
    else:
        return "I can't tell how you wanted the brightness changed."
    paul.set_it(code)
    paul.run_script(code, language="applescript")
    return "Done!"
Example #4
0
def say_hello(name):
    ''' Ask the use to say hello. '''
    greetings = [
        "hi",
        "hello",
        "morning",
        "afternoon",
        "evening",
    ]
    welcome = ("Hi there, {}!".format(name) 
             + " Lets start with something easy. Say hello!")
    continuing = True
    i = 0
    while continuing:
        recieved = paul.interact(welcome, response="arb")
        if paul.has_one_of(paul.Sentence(recieved), greetings):
            continuing = False
            paul.interact("Fantastic! Moving on...")
        elif i > 3:
            continuing = False
            paul.interact("Never mind! Moving on...")
        else:
            i += 1
            welcome = "Hmmm, I couldn't understand that,"
            welcome += " lets give it another shot."
    ask_weather()
Example #5
0
def get_val(keywords, key, sentence):
    ''' Determine the value to set. '''
    val = ''
    flag = True
    confirm = "Done."
    
    if paul.has_one_of(keywords, ["off", "false", "stop"]):
        val = "False"
    elif paul.has_one_of(keywords, ["on", "true", "start", "begin"]):
        val = "True"
    elif key == "title":
        if paul.has_word(keywords, "sir"):
            val = "sir"
        elif paul.has_word(keywords, "ma'am"):
            val = "ma'am"
        else:
            return ("I don't understand which title " 
                    + "you want to go by, sir or ma'am.", False)
        val = '"{}"'.format(val)
    elif key == "search_engine":
        engines = ["Google", "Bing", "Yahoo", "DuckDuckGo", "Baidu"]
        for engine in engines:
            if paul.has_word(keywords, engine.lower()):
                val = '"{}"'.format(engine)
        if val == '':
            return ("Sorry, I couldn't work out which " 
                    + "search engine you want to use.\n"
                    + "Please choose from Google, Bing, Yahoo, "
                    + "DuckDuckGo and Baidu next time.", False)
    elif key == "name":
        if sentence.has_one_of(["i", "me"]):
            val = paul.join_lists(sentence.get_part("??"), 
                                  sentence.get_part("XO"))
            paul.log("VAL[0]", val[0])
            val = '"{}"'.format(val[0].capitalize())
            confirm = ("Ok, I'll call you " + 
                       "{} from now on.".format(val[1:-1]))
        elif sentence.has_word("you"):
            return ("My name is Paul.", False)
        else:
            return ("Not really sure what you're getting at...", False)
    else:
        paul.log("PARAMETER NOT FOUND")
        return ("I'm not sure how you" 
                + " wanted '{}' set.".format(key), False)
    return (confirm, flag, val)
Example #6
0
def process(sentence):
    ''' Process the sentence, act as necessary '''
    
    paul.loading()
    ignore = [
        "weather",
        "forecast",
        "rainy",
        "rain",
        "raining",
        "sunny",
        "temperature",
        "cold",
        "hot",
        "humid",
    ]
    
    keywords = sentence.keywords()
    paul.log("KEYWORDS: " + str(keywords))
    
    today = datetime.date.today().weekday()
    paul.log("TODAY: " + str(today))
    
    day_index = 0
    
    weekdays = ['monday', 'tuesday', 'wednesday', 
                'thursday', 'friday', 'saturday', 'sunday']
    
    if (len(keywords) == 0 
        or paul.has_one_of(keywords, ['today', 'now', "today's"])):
        day_index = 0
    elif paul.has_one_of(keywords, ['tomorrow', "tomorrow's"]):
        day_index = 2
    elif paul.has_one_of(keywords, weekdays):
        for day in weekdays:
            if paul.has_word(keywords, day):
                paul.log("DAY:", day)
                day_index = (weekdays.index(day) + today) % 7 + 1
            if day_index == 1:
                day_index = 0
    
    paul.log("DAY: " + str(day_index))
    
    return weather(day_index, sentence)
Example #7
0
def process(sentence):
    ''' Process the input sentence '''
    
    keywords = sentence.keywords(include=["NS", "VB"])
    
    takeback = "I'm still learning!"
    
    if paul.has_one_of(keywords, GREETINGS):
        takeback = greet()
    elif paul.has_one_of(keywords, THANKS):
        takeback = thank()
    elif paul.has_one_of(keywords, FEELING):
        takeback = feeling()
    elif paul.has_word(keywords, "yourself"):
        takeback = about_me()
    elif paul.has_one_of(keywords, RANDOM):
        takeback = random(sentence)
    elif paul.has_one_of(keywords, ["name", "call", "called", "named"]):
        return sentence.forward("settings")
    return takeback
Example #8
0
def process(sentence):
    ''' Process the sentence '''
    global mb
    username = ''
    password = ''
    provider = ''
    if not mb:
        try:
            mb = Mailbox(provider)
        except ConnectionRefusedError:
            return "Oh no! Check your settings, I couldn't connect for some reason."
        try:
            mb.login(username, password)
        except:
            return "Hmmm... Check your username and password are correct."
    keywords = sentence.keywords(include=["VB"])
    paul.log("KEYWORDS:", keywords)
    if paul.has_one_of(keywords, ["read", "check", "have"]):
        r = mb.get_unread()
        return r if r else ""
    elif paul.has_one_of(keywords, ["write", "send", "compose"]):
        return "I can't quite do that yet. Working on it!"
Example #9
0
def get_key(keywords):
    ''' Decide on the key to use '''
    key = ''
    flag = True
    if paul.has_one_of(keywords, ["noisy", "noisiness", "talk", "talking"]):
        key = "NOISY"
    elif paul.has_one_of(keywords, ["verbose", "verbosity", 
                                    "debug", "debugging"]):
        key = "VERBOSE"
    elif paul.has_word(keywords, "logging"):
        key  = "LOGGING"
    elif paul.has_one_of(keywords, ["name", "call", "called"]):
        key = "name"
    elif paul.has_word(keywords, "title"):
        key = "title"
    elif paul.has_word(keywords, "prompt"):
        return ("You have to change the prompt in settings"
                + " manually, I'm afraid.", False)
    elif paul.has_one_of(keywords, ["search", "engine", "search engine"]):
        key = "search_engine"
    else:
        paul.log("FOUND NO FLAG")
        return ("I'm not sure what you wanted me to set.", False)
    return (key, flag)
Example #10
0
def make_equations(sentence):
    ''' Create a set of equations to work with '''
    eqn_string = []
    index = 0
    for word, _ in sentence:
        is_eq = (paul.has_one_of(word, "+/^*-=1234567890") 
                 or word in list("abcdefghijklmnopqrstuvwxyz"))
        if not is_eq:
            if len(eqn_string) != index:
                index += 1
        else:
            try:
                eqn_string[index] += word
            except IndexError:
                eqn_string.append(word)
    if eqn_string == []:
        eqn_string = [make_from_words(sentence.sentence_string)]
    paul.log("EQN_STRING:", eqn_string, "INDEX:", index)
    return eqn_string
Example #11
0
def is_math(sentence):
    """ Determines if any part of the sentence is math """
    for word, _ in sentence:
        if paul.has_one_of(word, "+/^*-=") and not word.startswith("http"):
            return True
    return False