async def eliminate(ctx, castaway=''): """Manually read the votes""" if not ext.host(ctx): await client.say("You are not a host.") return 1 if not castaway: await client.say("Please specify a player to eliminate.") return 1 # Toggle vote time ext.toggle() players = ext.get_players() for player in players: # Set vote to nobody player.write() player = ext.Player(ext.get("players.csv", 1, castaway)) obj = ext.get_player_object(ctx, player) 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, castaway, spec) # Reset tribal ext.set_tribal('none') await client.change_presence(game=discord.Game(name="j.help")) await client.say("{} has successfully been eliminated.".format(nick))
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.")
async def add(ctx, *args): """Adds a player, idol, or strike to the database""" if not ext.host(ctx): # Checks to see if user running the command is a host await client.say("You are not a host.") return 1 if len(args) != 2: # Check for valid amount of arguments if len(args) == 3: cmd, user_id, name = args else: await client.say("Please enter a valid amount of arguments.") return 1 else: cmd, player = args if not ext.exists("players.csv", player): await client.say("Player does not exist.") return 1 if cmd == "player": if ext.exists("players.csv", user_id): # Check if player already exists await client.say('Player already exists.') elif user_id[:-5] not in [ mem.name for mem in ctx.message.server.members ]: # Check for player in server await client.say("There is no {} in the server.".format(user_id)) else: # Write to players.csv with the player data player = discord.utils.get(ctx.message.server.members, name=user_id[:-5]) ext.Player(player.mention[2:-1]).write(name, 'no') # Change nickname and role user = ext.get_player_object(ctx, user_id) role = ext.get_role_object(ctx, "Castaway") await client.say("Added user *{}* as *{}*".format(user_id, name)) try: await client.change_nickname(user, name) except discord.errors.Forbidden: await client.say( "Unable to change nickname. Please manually change {}'s nickname to {}." .format(user_id, name)) except AttributeError: await client.say( "Unable to change nickname. Please manually change {}'s nickname to {}." .format(user_id, name)) try: await client.add_roles(user, role) except discord.errors.Forbidden: await client.say( "Unable to add role *Castaway*. Please manually add role to player {}." .format(user_id)) except AttributeError: await client.say( "Unable to add role *Castaway*. Please manually add role to player {}." .format(user_id)) elif cmd == "idol": if ext.exists("idols.csv", player): # Check if player already has an idol # TODO: Allow players to have as many idols as they have found await client.say("Player already has an idol.") else: # Add idol ext.write("idols.csv", [player, "no"]) await client.say("Added idol.") elif cmd == "strike": player = ext.Player(ext.get("players.csv", 1, player)) if player.strikes == 2: await client.say("{} has 3 strikes and is eliminated".format( player.nick)) if len(ext.get_players()) <= 10: role = "Juror" else: role = "Spectator" ext.remove_player(client, ctx, player.nick, role) else: player.write(strike=True) if player.strikes > 1: await client.say("{} now has {} strikes.".format( player.nick, player.strikes)) else: await client.say("{} now has {} strike.".format( player.nick, player.strikes)) nick = player.nick channel = ext.get_channel(ctx, "{}-confessional".format(nick.lower())) await client.edit_channel(channel, topic="Strikes: {}".format( player.strikes)) else: await client.say( "Invalid command. Commands are `player`, `idol`, and `strike`.")
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"))