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"))
async def vote_time(ctx, tribe=''): """Manually toggle if players can vote or not""" if not ext.host(ctx): await client.say("You are not a host.") return 1 if not tribe and not ext.is_vote_time(): await client.say("Specify a tribe to allow players to vote.") elif not ext.is_vote_time() and ext.exists("tribes.csv", tribe): # Toggle vote time and set tribal to tribe await client.change_presence(game=discord.Game( name="{} tribal council".format(tribe))) ext.toggle() ext.set_tribal(tribe) await client.say("Players can now vote.") elif not ext.is_vote_time() and not ext.exists("tribes.csv", tribe): await client.say("Tribe {} does not exist.".format(tribe)) else: await client.change_presence(game=discord.Game(name="j.help")) ext.toggle() ext.set_tribal('none') await client.say("Players can now no longer vote.")
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 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)