async def merge_tribes(ctx, tribe): """Merges players into a single tribe. (tribe)""" if not ext.host(ctx): await client.say("You are not a host.") return 1 players = ext.get_players() for player in players: # Change tribe to new merge tribe player.write(tribe=tribe) # Change roles role = ext.get_role_object(ctx, tribe) castaway = ext.get_role_object(ctx, "Castaway") user = ext.get_player_object(ctx, player) try: await client.replace_roles(user, role, castaway) except discord.errors.Forbidden: await client.say("Forbidden to add role.") except AttributeError: await client.say("Role {} does not exist.".format(tribe)) # Delete old tribes from tribes.csv ext.write("tribes.csv", ext.get("tribes.csv", 1)[1], True) # Write new tribe to tribes.csv ext.write("tribes.csv", [tribe])
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 sort_tribes(ctx, tribe1, tribe2, swap=''): """Sorts players into tribes. (tribe1, tribe2)""" if not ext.host(ctx): await client.say("You are not a host.") return 1 players = ext.get_players() tribes = [tribe1, tribe2] counter = {tribe1: 0, tribe2: 0} for player in players: # Choose a random tribe while True: choice = random.choice(tribes) if counter[choice] < len(players) / 2: counter[choice] += 1 break # Assign tribe to player player.write(tribe=choice) # Change roles role = ext.get_role_object(ctx, player.tribe) user = ext.get_player_object(ctx, player) try: await client.add_roles(user, role) except discord.errors.Forbidden: await client.say(("Unable to add {} role to {}. Forbidden." "").format(player.tribe, player.nick)) except AttributeError: await client.say(("Unable to add {} role to {}. Role does not " "exist.").format(player.tribe, player.nick)) # Write tribes to tribes.csv ext.write("tribes.csv", [tribe1, tribe2]) if not swap: player_count = len(ext.get("players.csv", 1)) with open("playernum", 'w') as f: f.write(str(player_count))
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`.")