Esempio n. 1
0
def webhook():
    """Listens for POSTs from Slack, which are requests for the current
    state of the teapot.

    Args:
        - None
    Returns
        - JSON payload
            - text (string) - Describing the current state of the teapot
    """
    latest_state = State.get_newest_state()
    if latest_state:
        return jsonify({'text': _human_teapot_state(latest_state)})
    else:
        return jsonify({'text': 'Theres no teapot data :('})
Esempio n. 2
0
def teaReady():
    """POST'ing to this endpoint triggers a message to be sent to Slack
    alerting everyone that a teapot is ready with X number of cups in it.

    Args:
        - num_of_cups (int) - The number of cups in the teapot
    Returns
        - 200
    """
    latest_state = State.get_newest_state()
    last_full_pot = State.get_latest_full_teapot()
    number_of_cups = latest_state.num_of_cups
    message = "The Teapot :teapot: is ready with %s" % (
        _cup_puraliser(number_of_cups))
    reaction_message = \
        "Want a cup of tea from the next teapot ? " + \
        "React to this message to let everyone know!"
    if last_full_pot.claimed_by:
        message += ", thanks to %s" % last_full_pot.claimed_by.name
    slack_communicator_wrapper.post_message_to_room(message)
    PotMaker.reset_teapot_requests()
    SlackMessages.clear_slack_message()
    slack_communicator_wrapper.post_message_to_room(reaction_message, True)
    return Response()