def vote():
        # 1) Make sure player who made the command
        # is in the game
        if not player_in_game(g, user_id):
            return False, MSG['u_not_in_game']
        # is alive
        if not is_player_alive(g, user_id):
            return False, MSG['u_not_alive']
        # only valid during day
        if get_current_round(g) != 'day':
            return False, MSG['not_day']

        # if target_name=pass is okay
        if target_name == 'pass':
            return True, user_name + ' wants to pass.'

        # target is in game
        if not player_in_game(g, target_id):
            return False, MSG['t_not_in_game']
        # target is alive
        if not is_player_alive(g, target_id):
            return False, MSG['t_not_alive']

        # voting again just changes your vote.
        if has_voted(g, user_id):
            return True, user_name + ' changed vote to ' + '*'+target_name + '.*'

        # after each success vote should list all votes.
        return True, user_name + ' voted for ' + '*' + target_name + '.*'
def vote(user_id, action, game_state, target_name):
    user_map = UserMap()
    target_id = user_map.get(name=target_name)
    user_name = user_map.get(user_id)

    if not status.player_in_game(game_state, user_id):
        return False, RESPONSE['u_not_in_game']

    if not status.is_player_alive(game_state, user_id):
        return False, RESPONSE['u_not_alive']

    if status.get_current_round(game_state) != 'day':
        return False, RESPONSE['not_day']

    if target_name == 'pass':
        return True, user_name + RESPONSE['pass']

    if not status.player_in_game(game_state, target_id):
        return False, RESPONSE['t_not_in_game']

    if not status.is_player_alive(game_state, target_id):
        return False, RESPONSE['t_not_alive']

    if status.has_voted(game_state, user_id):
        return True, user_name + ' changed vote to ' + '*' + target_name + '*'

    return True, user_name + ' voted for ' + '*' + target_name + '*'
def message_everyone_roles(g):
    """
    for every player in game.
    DM them their roles.

    """
    u = UserMap()
    # player_role(g, player_id)

    all_alive = [(u.get(user_id=p_id, DM=True), player_role(g, p_id))
                for p_id in players_in_game(g)
                    if is_player_alive(g, p_id)]

    print(all_alive)

    for im, role in all_alive:
        if role=='v':
            nice=" Plain Villager"
        elif role=='w':
            nice=" Werewolf. *Awoooo!*"
        elif role=='s':
            nice=" Seer."
        elif role=='b':
            nice=" Bodyguard."
        send_message(nice, channel=im)
def peek(user_id, action, game_state, target_name):
    user_map = UserMap()
    role_map = {
        's': "the Seer",
        'w': "a wolf",
        'v': "a vanilla villa",
        'a': "the Angel"
    }

    target_id = user_map.get(name=target_name)

    user_name = user_map.get(user_id)

    if not status.player_in_game(game_state, user_id):
        return False, RESPONSE['noop']

    if not status.is_player_alive(game_state, user_id):
        return False, RESPONSE['dead_villa']

    #if status.get_current_round(game_state) != 'night':
    #    return False, RESPONSE['noop']

    if status.player_role(game_state, user_id) != 's':
        return False, RESPONSE['not_seer']

    target_role = status.player_role(game_state, target_id)
    target_str = RESPONSE['peek']

    return True, target_name + "'s role is " + role_map[target_role]
    def kill():
        # 1) Make sure player who made the command
        # is in the game
        if not player_in_game(g,user_id):
            return False, 'Not allowed.'
        # 1a) is a werewolf
        # Only werewolf can use kill. (for now)
        if player_role(g, user_id) != 'w':
            return False, 'Not allowed.'
        # 1c) is alive
        if not is_player_alive(g, user_id):
            return False, 'Dead wolves can not kill.'
        # 2) Kill command only valid at night.
        if get_current_round(g) != 'night':
            return False, 'Not allowed.'
        # 3) Target must be in game.
        if not player_in_game(g, target_id):
            return False, 'Not allowed.'
        # 4) Target must be alive.
        if not is_player_alive(g, target_id):
            return False, 'Not allowed.'

        return True, '' # no message
def night_kill(user_id, action, game_state, target_name):
    user_map = UserMap()
    target_id = user_map.get(name=target_name)
    user_name = user_map.get(user_id)

    if not status.player_in_game(game_state, user_id):
        return False, RESPONSE['noop']

    #if status.player_role(game_state, user_id) != 'w':
    #    return False, RESPONSE['noop']

    if not status.is_player_alive(game_state, user_id):
        return False, 'Dead wolves can not kill.'

    #if status.get_current_round(game_state) != 'night':
    #    return False, RESPONSE['noop']

    if not status.player_in_game(game_state, target_id):
        return False, RESPONSE['noop']

    if not status.is_player_alive(game_state, target_id):
        return False, RESPONSE['noop']

    return True, ""
def should_countdown(user_id, action, game_state):
    """Check if we can start a countdown. To do so it must be day and the command must come
   from a player in the game.
   """
    if status.get_current_round(game_state) != "day":
        return False, RESPONSE['not_day']

    elif not status.is_player_alive(game_state, user_id):
        return False, RESPONSE['no_countdown']

    elif len(status.get_all_alive(game_state)) - 1 == len(
            status.get_all_votes(game_state).keys()):
        return True, None

    else:
        return False, RESPONSE['no_countdown']
 def can_countdown():
    """
    Must be day.
    Must be one player left to vote.
    """
    if get_current_round(g) != "day":
        return False, 'It is not day.'
    elif not is_player_alive(g, user_id):
        return False, 'You are not in the game.'
    # get list of all alive
    # get list of votes
    # if list of votes == all alive - 1
    elif len(get_all_alive(g))- 1 == len(get_all_votes(g).keys()):
        return True, None
    else:
        return False, 'Can not start countdown now.'
def message_everyone_roles(game_state):
    """Ping players with their roles."""
    user_map = UserMap()

    role_message_mapping = {
        'v': " Vanilla Villa\nhttps://media.giphy.com/media/26ufgQWWT3BUtSRq0/giphy.gif",
        'w': " Werewolf\nhttps://media.giphy.com/media/VTGEse4Pt422I/giphy.gif",
        's': " Seer\nhttps://media.giphy.com/media/bpIWfYfOiHR3G/giphy.gif",
        'a': " Angel\nhttps://media.giphy.com/media/xbbq3NUIOtTVu/giphy.gif"
    }

    def _player_tuple(player_id, game_state):

        return (user_map.get(user_id=player_id, DM=True), status.player_role(game_state, player_id))

    all_alive = [_player_tuple(player_id, game_state) for player_id in status.players_in_game(game_state) if status.is_player_alive(game_state, player_id)]

    for im, role in all_alive:
        dm_message = role_message_mapping[role]
        send_message(dm_message, channel=im)