Ejemplo n.º 1
0
def getVotes():
    userInfo = getUserInfo(request)
    if(not isValidUser(userInfo)):
        return pleaseRegister()
    if(inPoll):
        return grabVoting()
    else:
        return  wrapResponse().format(response_type="ephemeral", data='"We aren\'t in a poll right now."')
Ejemplo n.º 2
0
def listRestaurants():
    try:
        userInfo = getUserInfo(request)
        if(not isValidUser(userInfo)):
            return pleaseRegister()
        test = '"|hi|there|\\n|:-|:-|\\n|1|2|"'
        return wrapResponse().format(response_type="in_channel", data=getRestaurantList())
    except Exception as e:
        print(e)
        return wrapResponse().format(response_type="ephemeral", data='"Error, Cannot list restaurants at this time."')
Ejemplo n.º 3
0
def resetRestaurant(rest):
    try:
        userInfo = getUserInfo(request)
        if(not isValidUser(userInfo)):
            return pleaseRegister()
        restaurant = re.match("[a-zA-Z0-9']+", rest).string
        removePriority(restaurant)
        return wrapResponse().format(response_type="in_channel", data='"Weight reset for {0}. Hope it was good!"'.format(restaurant))
    except Exception as e:
        print(e)
        return wrapResponse().format(response_type="ephemeral", data='"Error, failed to modify weighting. Try again later."')
Ejemplo n.º 4
0
def vote():
    global votingSecret, inPoll
    userInfo = {"id":request.get_json().get('user_id')}
    if(not isValidUser(userInfo)):
        return app.response_class(response='{"ephemeral_text": "Please use ``/lunch regiser (username)`` before participating in the lunch polls"}', status=200, mimetype="application/json")
    if(votingSecret == request.get_json().get('context').get('secret') and checkPollID(int(request.get_json().get('context').get('pollID'))) and inPoll):
        if(request.get_json().get('context').get('choice') == remove)
            removeVote(request.get_json().get('user_id'))
            return app.response_class(response='{"ephemeral_text": "Removed your vote from the poll"}', status=200, mimetype="application/json")
        addVote(request.get_json().get('user_id'), request.get_json().get('context').get('choice'))
        return app.response_class(response='{{"ephemeral_text": "Your vote for {0} has been updated!"}}'.format(request.get_json().get('context').get('choice')), status=200, mimetype="application/json")
    else:
      return app.response_class(response='{"ephemeral_text": "This poll has closed. Please check to see if there is a newer poll"}', status=200, mimetype="application/json")
Ejemplo n.º 5
0
def addFood(restaurant):
    try:
        userInfo = getUserInfo(request)
        if(not isValidUser(userInfo)):
            return pleaseRegister()
        newRestaurant = re.match("[a-zA-Z0-9'&]+", restaurant).string
        if(not alreadyAdded(newRestaurant)):
            addRestaurant(newRestaurant)
            return wrapResponse().format(response_type="in_channel", data='"Added {0} from user {1}!"'.format(newRestaurant, request.form.get("user_name")))
        return wrapResponse().format(response_type="ephemeral", data='"It\'s already there!"')
    except Exception as e:
        print(e)
        return wrapResponse().format(response_type="ephemeral", data='"Error, failed to add eatery. Try again later."')
Ejemplo n.º 6
0
def killPoll():
    global inPoll
    try:
        userInfo = getUserInfo(request)
        if(not isValidUser(userInfo)):
            return pleaseRegister()
        if(inPoll):
            inPoll = False
            killPollHelper()
            return wrapResponse().format(response_type="in_channel", data='"{} has killed the poll. Brutal..."'.format(userInfo['name']))
        else:
            return wrapResponse().format(response_type="ephemeral", data='"We are not currently in a poll."')
    except Exception as e:
        return wrapResponse().format(response_type="ephemeral", data='"Error, failed to kill poll. Yell at the admin to fix it."')
Ejemplo n.º 7
0
def resetPoll():
    global inPoll
    try:
        userInfo = getUserInfo(request)
        if(not isValidUser(userInfo)):
            return pleaseRegister()
        if(inPoll):
          incrementPollID()
          return resetPollHelper(userInfo['name'])
        else:
          return wrapResponse().format(response_type="ephemeral", data='"We are not currently in a poll."')
    except Exception as e:
        print(e)
        return wrapResponse().format(response_type="ephemeral", data='"Error, failed to remove eatery. Try again later."')
Ejemplo n.º 8
0
def removeFood(rest):
    try:
        userInfo = getUserInfo(request)
        if(not isValidUser(userInfo)):
            return pleaseRegister()
        restaurant = re.match("[a-zA-Z0-9']+", rest).string
        success = removeRestaurant(restaurant)
        if(success):
            return wrapResponse().format(response_type="in_channel", data='"Sad to see {0} go..."'.format(restaurant))
        else:
            return wrapResponse().format(response_type="ephemeral", data='"Restaurant not found."')
    except Exception as e:
        print(e)
        return wrapResponse().format(response_type="ephemeral", data='"Error, failed to remove eatery. Try again later."')
Ejemplo n.º 9
0
def endPoll():
    global inPoll
    try:
        userInfo = getUserInfo(request)
        if(not isValidUser(userInfo)):
            return pleaseRegister()
        pollResults = displayVotes()
        userChoices = displayUserVotes()
        winner = endPollHelper()
        incrementWeights()
        removePriority(winner)
        inPoll = False
        return wrapResponse().format(response_type="in_channel", data='"Lunch is at: {place}\\n\\n{poll}\\n\\n{users}"'.format(place=winner, poll=pollResults, users=userChoices))
    except Exception as e:
        print(e)
        return wrapResponse().format(response_type="ephemeral", data='"Error, failed to modify weighting. Try again later."')
Ejemplo n.º 10
0
def gimmeLunch():
    global inPoll
    try:
        userInfo = getUserInfo(request)
        if(not isValidUser(userInfo)):
            return pleaseRegister()
        if(not inPoll):
            inPoll = True
            incrementPollID()
            poll = grabPoll()
            print(poll)
            return poll
        else:
            return wrapResponse().format(response_type="ephemeral", data='"Already deciding what is for lunch."')
    except Exception as e:
        inPoll = False
        return wrapResponse().format(response_type="ephemeral", data='"Error, failed to select a lunch place. Looks like you\'re on your own kid!. {error}"'.format(error=e))