예제 #1
0
async def on_ready():
    print("Bot online.")
    print("Username: {}".format(client.user.name))
    print("ID: {}".format(client.user.id))
    if ext.is_vote_time():
        await client.change_presence(game=discord.Game(
            name="{} tribal council".format(ext.get_tribal())))
    else:
        await client.change_presence(game=discord.Game(name="j.help"))
예제 #2
0
async def vote(ctx, player):
    """Vote for a player for Tribal Council (player's nickname)"""
    exists = ext.exists("players.csv", str(ctx.message.author.id))

    if not ext.is_vote_time():
        await client.say("You cannot vote at this time.")
        return 1

    if not exists:
        await client.say("You are not a player.")
        return 1

    user = ext.Player(str(ctx.message.author.id))
    tribe = ext.get_tribal()
    if "#" in player:
        await client.say("Please use a player's nickname, not their id.")
    elif tribe != user.tribe:
        await client.say("You are not in {} tribe.".format(tribe))
    elif tribe != ext.get("players.csv", 3, player):
        await client.say("{} is not in your tribe.".format(player))
    elif ext.voted(user.user_id):
        if ext.same(user.user_id, player):
            await client.say("Vote is already {}.".format(player))
        else:
            user.write(vote=player)
            await client.say("Vote changed to {}.".format(player))
    else:
        if ext.exists("players.csv", player):
            user.write(vote=player)
            await client.say("Voted for {}.".format(player))

            players = ext.get_players()
            voted = [player for player in players if ext.voted(player.user_id)]

            if len(players) == len(voted):
                await client.send_message(
                    ext.get_channel(ctx, "host-channel"),
                    content="{} Everyone has voted.".format(
                        ext.get_role_object(ctx, "Host").mention))
        else:
            await client.say("That is not a player you can vote for.")
예제 #3
0
async def read_votes(ctx):
    """Manually read the votes"""

    if not ext.host(ctx):
        await client.say("You are not a host.")
        return 1

    # Toggle vote time
    ext.toggle()

    # Store votes in a list
    votes = []
    players = ext.get_players()
    for player in players:
        if ext.voted(player.user_id):
            votes.append(player.vote)
        elif player.tribe == ext.get_tribal():
            votes.append(player.nick)
        # Set vote to nobody
        player.write()

    # Get the order to read the votes and who is out
    final, out = ext.sort_votes(votes)
    idols = ext.get_idols()

    # Read out idols
    if idols:
        msg = ""
        for player in idols:
            if player == idols[0]:
                msg += "A reminder that {}".format(player)
            elif player == idols[-1]:
                msg += " and {}".format(player)
            else:
                msg += ", {}".format(player)
        if len(idols) > 1:
            msg += " are using idols."
        else:
            msg += " is using an idol."
        await client.say(msg)

    # Read the votes
    count = 1
    for vote in final:
        if count == 1:
            read = "1st vote: {}".format(vote)
        elif count == 2:
            read = "2nd vote: {}".format(vote)
        elif count == 3:
            read = "3rd vote: {}".format(vote)
        else:
            read = "{}th vote: {}".format(count, vote)
        if vote in idols:
            read += ", does not count"
        if count == len(final) and out is not None:
            read = "{} person voted out of Survivor: {}".format(
                ext.get_placing(), vote)
        count += 1
        await client.say(read)

    # Remove any idols being used
    for player in ext.get("idols.csv", 1):
        if ext.get("idols.csv", 2, player) == "yes":
            ext.write("idols.csv", [player], True)

    if out is None:
        # Print tie if more than two people with the highest count
        await client.say("We have a tie!")
    else:
        player = ext.Player(ext.get("players.csv", 1, out))
        obj = ext.get_player_object(ctx, player)
        await client.say("{}, the tribe has spoken.".format(obj.mention))
        jury = False
        with open("tribes.csv") as f:
            tribes = f.read().split("\n")
            if "," not in tribes:
                jury = True
        if jury:
            spec = "Juror"
        else:
            spec = "Spectator"

        nick = player.nick
        channel = ext.get_channel(ctx, "{}-confessional".format(nick.lower()))
        channel_name = "{}-{}".format(nick.lower(), ext.get_final_place())
        await client.edit_channel(channel,
                                  name="{}-{}".format(nick.lower(),
                                                      ext.get_final_place()))

        # Remove the player
        await ext.remove_player(client, ctx, out, spec)

    # Reset tribal
    ext.set_tribal('none')
    await client.change_presence(game=discord.Game(name="j.help"))
예제 #4
0
async def show(ctx, *args):
    """Lists either the players in the player list, the players who have
    voted, or the players who haven't voted"""

    if not ext.host(ctx):
        await client.say("You are not a host.")
        return 1

    if len(args) < 1:
        await client.say("Please enter an argument.")
        return 1

    if args[0] == "players":
        # Store player ids and then print data
        players = ext.get_players()
        data = ''
        # Store all data in one string
        # makes it quicker to print in Discord
        for item in players:
            data += "{}: {}, {} tribe".format(
                discord.utils.get(ctx.message.server.members, id=item.user_id),
                item.nick, item.tribe)
            if players[-1] != item:
                data += '\n'
        await client.say(data)
    elif args[0] == "voted":
        # Get players who have voted
        players = ext.get_players()
        voted = [
            player.nick for player in players if ext.voted(player.user_id)
        ]
        if not voted:
            await client.say("Nobody has voted.")
        elif len(players) == len(voted):
            await client.say("Everybody has voted.")
        else:
            data = ''
            for player in voted:
                data += player
                if voted[-1] != player:
                    data += '\n'
            await client.say(data)
    elif args[0] == "not_voted":
        # Get players who haven't voted
        players = ext.get_players()
        not_voted = [
            player.nick for player in players
            if player.tribe == ext.get_tribal() and player.vote == "nobody"
        ]
        if not not_voted:
            await client.say("Everybody has voted.")
        # Check to see if nobody has voted
        # HACK: this only works because any new data written is added
        # to the bottom
        # However, it changes O(n) to O(1)
        elif players[-1].vote != "nobody":
            await client.say("Nobody has voted.")
        else:
            data = ''
            for player in not_voted:
                data += player
                if not_voted[-1] != player:
                    data += '\n'
            await client.say(data)
    elif args[0] == "tribe":
        # Show the players in a tribe
        if len(args) < 2:  # Check for a second argument
            await client.say("Please enter a tribe.")
        elif not ext.exists("tribes.csv", args[1]):
            await client.say("Tribe {} does not exist.".format(args[1]))
        else:
            data = ''
            players = ext.get_players()
            for player in players:
                # Add nickname to data if player is in the tribe
                if player.tribe == args[1]:
                    data += player.nick
                    if players[-1] != player:
                        # Add a new line char if not last player in list
                        data += '\n'
            await client.say(data)
    elif args[0] == "votes":
        # Get each player's vote
        players = ext.get_players()
        if ext.is_vote_time():
            # Check to see if anyone has voted
            # HACK: this only works because any new data written is added
            # to the bottom
            # However, it changes O(n) to O(1)
            if players[-1].vote != "nobody":
                data = ""
                for player in players:
                    if player.tribe == ext.get_tribal():
                        if player.vote == "nobody":
                            data += "{} hasn't voted yet.".format(player.nick)
                        else:
                            data += "{} is voting {}.".format(
                                player.nick, player.vote)
                        if player != players[-1]:
                            data += '\n'
                await client.say(data)
            else:
                await client.say("Nobody has voted.")
        else:
            await client.say("Players cannot vote.")
    elif args[0] == "idols":
        # Get all players with idols
        idols = ext.get("idols.csv", 1)
        if idols:
            data = ""
            for player in idols:
                using = ext.get("idols.csv", 2, player)
                if using == "yes":
                    data += "{}: using".format(player)
                else:
                    data += "{}: not using".format(player)
                if player != idols[-1]:
                    data += '\n'
            await client.say(data)
        else:
            await client.say("Nobody has an idol.")
    elif args[0] == "strikes":
        players = ext.get_players()
        data = ""
        for player in players:
            if player.strikes != 1:
                data += "{} has {} strikes.".format(player.nick,
                                                    player.strikes)
            else:
                data += "{} has 1 strike.".format(player.nick)
            if player != players[-1]:
                data += "\n"
        await client.say(data)