def callback_vote():
     check_bool, yet_to_vote = check()
     print('checking vote')
     print(check_bool, yet_to_vote)
     if check_bool:
         check_g = get_game_state()
         send_message(player_vote(check_g, yet_to_vote, ['vote', 'pass'])[0])
    def check():
        check_game = get_game_state()

        result, message = mod_valid_action(user_id, 'countdown', check_game)
        if not result:
            return False, message

        all_alive = status.get_all_alive(game_state)
        yet_to_vote_list = [player_id for player_id in all_alive if not status.has_voted(game_state, player_id)]
        if len(yet_to_vote_list) > 1:
            return False, 'Countdown cannot start now.'

        yet_to_vote = yet_to_vote_list[0]
        return True, yet_to_vote
    def check():
        # who hasn't voted.
        # if round is still day
        check_g = get_game_state() # make sure state hasn't changed.
        result, message = mod_valid_action(user_id, 'countdown', check_g)
        if not result:
            return False, message

        all_alive = get_all_alive(g)
        yet_to_vote_list = [
                p_id for p_id in all_alive
                if not has_voted(g, p_id)]

        if len(yet_to_vote_list) > 1:
            return False, 'Countdown cannot start now.'

        yet_to_vote = yet_to_vote_list[0]
        return True, yet_to_vote
Example #4
0
def process_message(data, g=None): # g=None so we can tests.
    message = data.get('text', '')
    if message.startswith('!'): # trigger is "!"

        if not g: # if g is not set get game state.
            g_copy = copy.deepcopy(change_state.get_game_state())
        else:
            g_copy = copy.deepcopy(g)

        command = message[1:].split(" ") # everything after !

        # let the router deal with this nonsense
        game_response, channel = command_router(g_copy, command, data['user'])
        if channel:
            send_message(game_response, channel)
        else:
            send_message(game_response)
        return game_response
    return None
Example #5
0
def process_message(data, game_state=None):
    """Process messages from players and from the game actions."""
    message = data.get('text', '')

    if message.startswith('!'):
        if not game_state:
            game_state_copy = copy.deepcopy(change_state.get_game_state())
        else:
            game_state_copy = copy.deepcopy(game_state)

        game_action = message[1:].split(" ")
        game_response, channel = command_router(game_state_copy, game_action,
                                                data['user'])

        if channel:
            send_message(game_response, channel)
        else:
            send_message(game_response)

        return game_response

    return None
 def callback_vote():
     check_bool, yet_to_vote = check()
     if check_bool:
         check_game = get_game_state()
         send_message(player_vote(check_game, yet_to_vote, ['vote', 'pass'])[0])