Beispiel #1
0
def handle_addcrush(sender_psid, received_message, me):
    # Check if we have more than 5 crushes already
    if len(me.crushes) >= 5:
        Response(sender_psid, "You can't have more than 5 crushes!").send()
        # End the conversation
        me.conversation = None
        me.save()
        return "OK"

    msg_text = received_message['text']
    _, confidence, myCrush = models.Sender.fuzzySearch(
        msg_text)  # pylint: disable=unused-variable

    me.add_crush(myCrush)

    r = Response(sender_psid, f"Added {myCrush.full_name} to crush list")
    r.add_reply(Reply("Add another Crush", payload="ADDCRUSH"))
    r.send()

    if int(sender_psid) in [crush.crushee.psid for crush in myCrush.crushes]:
        # You are the crush of your crush. It's a match!
        msg = (f"Congrats! {myCrush.full_name} is crushing on you!" +
               " Matchmaker Baxtabot is here to match! You now have a date at" +
               f" {random.choice(DATE_LOCATIONS)} at {random.choice(range(1, 6))}pm tomorrow." +
               " Clear you calendar - this is your chance 😉😘😜")
        Response(sender_psid, msg).send()
        Response(myCrush.psid, msg).send()
    return 'OK'
Beispiel #2
0
def handle_dinowrong(sender_psid, received_message, me):
    print('The dino menu is wrong, should be', received_message)
    meal = functions.getCurrentDino()
    meal.description = received_message['text']
    meal.save()

    response = Response(sender_psid)
    response.text = handle_dino_message(sender_psid, response, 'dino')
    response.send()

    return 'Fixed!'
Beispiel #3
0
def handlePostback(sender_psid, received_postback, msg):
    """
        Handles a postback request to the webhook and determines what
        functionality / response to call
        """
    payload = received_postback["payload"]

    print("RECEIVED POSTBACK: ", received_postback)
    response = Response(sender_psid)

    if payload == "goodvote":
        response.text = "Sounds like a nice meal!"
        functions.makeDinoVote("goodvote")

    elif payload == "badvote":
        response.text = "Too bad it was gross :("
        functions.makeDinoVote("badvote")

    elif payload == "ADDCRUSH":
        start_conversation(sender_psid, "ADDCRUSH")
        response.text = "Enter your crush name:"

    elif payload == "REMOVECRUSH":
        start_conversation(sender_psid, "REMOVECRUSH")
        response.text = "Enter the crush name to remove:"

    elif payload == "DINOIMAGE":
        start_conversation(sender_psid, "DINOIMAGE")
        response.text = "Send me a photo of dino!"

    elif payload == 'DINOWRONG':
        start_conversation(sender_psid, 'DINOWRONG')
        response.text = 'What is the dino meal actually?'

    else:
        # response.text = "[DEBUG] Received postback for some reason..."
        handleMessage(sender_psid, msg)
        return "OK"

    response.send()
    return "OK"
Beispiel #4
0
def handleMessage(sender_psid, received_message):
    """
        Handles a plain message request and determines what to do with it
        By word matching the content and sender_psid
        """

    received_message = received_message.lower()
    response = Response(sender_psid)
    print(sender_psid)

    if "psid" in received_message:
        Response(sender_psid, text=str(sender_psid)).send()
    elif (
        "dinopoll" in received_message
        or "dino like" in received_message
        or "dino good" in received_message
    ):
        response.text = handle_dinopoll_message(response)
    elif (
        "what's on" in received_message
        or "what’s on" in received_message
        or "what is on" in received_message
        or "event" in received_message
        or "calendar" in received_message
    ):
        response.text = handle_calendar_message(sender_psid)

    elif 'dino is wrong' in received_message:
        response.text = handle_dinowrong_message(sender_psid, response)

    elif "nudes" in received_message or "noods" in received_message:
        # response.asset = "270145943837548"
        url = 'https://indomie.com.au/wp-content/uploads/2020/03/migorengjumbo-new.png'
        Response(sender_psid, image=url).send()
    elif (
        "dino is shit" in received_message
        or "dino is bad" in received_message
        or "dino is good" in received_message
        or "dinovote" in received_message
        or "vote" in received_message
    ):
        response.text = handle_dinovote_message(response)
    elif is_dino_message(received_message):
        response.text = handle_dino_message(
            sender_psid, response, received_message)
        # Response(sender_psid, text='Arc Board elections are currently underway. If you want someone to vote for, Nick Patrikeos who helps maintain me is running. Type "arc board" for more info!').send()
    elif "snazzy pic" in received_message:

        meal = functions.getCurrentDino()
        if meal is not None and meal.images:
            image = random.choice(list(meal.images))
            Response(sender_psid, image=image.url).send()
            Response(sender_psid, f"Photo by: {image.sender.full_name}").send()
        else:
            Response(sender_psid, "No snazzy pics :(").send()

    elif 'am i a ressiexd' in received_message:
        pass

    elif 'order me a late meal' in received_message:
        response.text = handle_latemeal_message(sender_psid, received_message)

    elif "room is" in received_message:
        response.text = handle_getroom_message(sender_psid, received_message)

    elif "crush list" in received_message:
        response.text = handle_crushlist_message(sender_psid, response)

    else:
        reply = bot.reply(str(sender_psid), received_message)
        response.text = str(reply)

    if sender_psid == "cmd":
        return response.payload

    print("sent back:")
    pprint(response.payload)
    response.send()

    return "OK"