Ejemplo n.º 1
0
def hello():
    if 'text' not in request.form or request.form['text'] == "":
        logging.debug(f'Received invalid command')
        return api.error_response('Invalid command')
    command, _, _ = request.form['text'].strip().partition(' ')
    if command == 'new':
        new_kickup = st.new_kickup()
        logging.info(f'Created new kickup with identifier {new_kickup.num}')
        return api.respond(new_kickup)
    elif command == 'elo':
        leaderboard = elo.leaderboard(persistence.matches_sorted())
        return api.elo_leaderboard_resp(leaderboard)
    elif command.startswith('teams'):
        boards = inject.boards
        teamboard = None
        arguments = parse_arguments(command)
        if len(arguments) == 0:
            teamboard = boards.elo_by_team()
        elif isinstance(arguments[0], int):
            teamboard = boards.elo_by_teams_using_last_matches(arguments[0])
        elif isinstance(arguments[0], timedelta):
            teamboard = boards.elo_by_teams_using_matches_since(datetime.today(
            ).replace(hour=0, minute=0, second=0, microsecond=0) -
                                                                arguments[0])
        else:
            return api.error_response(f'Invalid parameters: "{command}"')

        return jsonify(inject.slack.from_teamboard(teamboard))
    else:
        return api.error_response(f'Invalid command: "{command}"')
Ejemplo n.º 2
0
def interactive():
    payload = json.loads(request.form['payload'])
    #pprint.pprint(payload)
    kickup_num = int(payload['callback_id'])
    kickup = st.get_kickup(kickup_num)
    if not kickup:
        logging.warning(f'Could not find kickup with id { kickup_num }')
        return api.respond(None)
    logging.debug(f'Retrieved kickup with id { kickup_num }')
    action = payload['actions'][0]
    try:
        if action['type'] == 'select':
            handle_select(kickup, action)
        else:
            handle_button(payload, kickup, action)
    except KickupException as ke:
        delayed.delayed_error(ke, payload['response_url'])
        logging.error(ke)
    finally:
        return api.respond(kickup)
Ejemplo n.º 3
0
def hello():
    if not 'text' in request.form or request.form['text'] == "":
        logging.debug(f'Received invalid command')
        return api.error_response('Invalid command')
    command, _, _ = request.form['text'].strip().partition(' ')
    if command == 'new':
        new_kickup = st.new_kickup()
        logging.info(f'Created new kickup with identifier { new_kickup.num }')
        return api.respond(new_kickup)
    elif command == 'elo':
        leaderboard = elo.leaderboard(persistence.matches_sorted())
        return api.elo_leaderboard_resp(leaderboard)
    else:
        return api.error_response(f'Invalid command: "{ command }"')
Ejemplo n.º 4
0
def hello():
    if not 'text' in request.form or request.form['text'] == "":
        logging.debug(f'Received invalid command')
        return api.error_response('Invalid command')
    command, _, args = request.form['text'].strip().partition(' ')
    if command == 'new':
        g.context_player = get_player_from_request()

        new_kickup = st.new_kickup()
        new_kickup.add_player(g.context_player())
        logging.info(f'Created new kickup with identifier { new_kickup.num }')
        return api.respond(new_kickup)
    elif command == 'elo':
        leaderboard = elo.leaderboard()
        return api.elo_leaderboard_resp(leaderboard)
    else:
        return api.error_response(f'Invalid command: "{ command }"')
Ejemplo n.º 5
0
def hello():
    if not 'text' in request.form or request.form['text'] == "":
        return api.error_response('Invalid command')
    command, _, args = request.form['text'].strip().partition(' ')
    if command == 'new':
        new_kickup = st.new_kickup()
        logging.info(f'Created new kickup with identifier { new_kickup.num }')
        return api.respond(new_kickup)
    elif command == 'leaderboard':
        leaderboard = pack.packeroo_leaderboard()
        return api.leaderboard_resp(leaderboard)
    elif command == 'elo':
        leaderboard = elo.leaderboard()
        return api.elo_leaderboard_resp(leaderboard)
    elif command == 'elogd100':
        leaderboard = elo.leaderboard_gd100()
        return api.elo_leaderboard_resp(leaderboard)
    elif command == 'elogd400':
        leaderboard = elo.leaderboard_gd400()
        return api.elo_leaderboard_resp(leaderboard)
    else:
        return api.error_response(f'Invalid command: "{ command }"')