async def listplayers(ctx, *args): await asyncio.sleep(0.1) if len(args) > 0: # Mention players if args[0].lower() == "mention": if check_perms(ctx): await ctx.send( players.Player_Manager.list_players_raw(mention=True)) else: await insufficient_perms(ctx) # List with roles elif args[0].lower() == "roles" or args[0].lower() == "role": if check_perms(ctx): await ctx.send( embed=players.Player_Manager.list_players_with_roles()) else: await insufficient_perms(ctx) # No type specified/generic list else: await ctx.send(embed=players.Player_Manager.list_players()) # Generic list else: await ctx.send(embed=players.Player_Manager.list_players())
async def endgame(ctx): await asyncio.sleep(0.1) # Check permission if check_perms(ctx): # Cannot end game currently if not misc.game_in_progress(gameplay.game_phase): embed = discord.Embed( color=0xff0000, title="Failed to End Game", description= "The game is not in progress or is currently starting, and cannot be forcefully ended." ) await ctx.send(embed=embed) return # Send confirmation message embed = discord.Embed( color=0xffff00, title="⚠️ Forcefully End Game? ⚠️", description="Are you sure you want to forcefully end the game?") message = await ctx.send(embed=embed) await confirmations.confirm_end_game(ctx, message) # Insufficient permission else: await insufficient_perms(ctx)
async def listchannels(ctx): await asyncio.sleep(0.1) # Check permissions if check_perms(ctx): description = "" global channels for i, c in enumerate(channels): # Text channel if i <= 5: description += "{} = {}\n".format( c.capitalize(), "<#{}>".format(channels[c].id) if channels[c] != None else "None") # Voice channels: elif i == 6: description += "\nMeeting (Voice) = {}\n".format( "<#{}>".format(channels[c].id ) if channels[c] != None else "None") elif i == 7: description += "Wolves (Voice) = {}".format("<#{}>".format( channels[c].id) if channels[c] != None else "None") embed = discord.Embed(color=0x0080ff, title="Channel List", description=description) await ctx.send(embed=embed) # Insufficient perms else: await insufficient_perms(ctx)
async def timer(ctx, *args): await asyncio.sleep(0.1) if check_perms(ctx): try: if float(args[0]) > 0: await ctx.send( "**Starting a timer for {} minutes for {}...**".format( args[0], ctx.author.display_name)) await asyncio.sleep(float(args[0]) * 60) await ctx.send( "**TIMER FOR {} MINUTES BY {} HAS ENDED.**".format( args[0], ctx.author.mention)) else: raise Exception("Invalid argument.") except: embed = discord.Embed(color=0xff0000, title="Invalid Arguments", description="Please enter a valid number!") await ctx.send(embed=embed) else: await insufficient_perms(ctx)
async def pause(ctx): await asyncio.sleep(0.1) # Game not in progress if gameplay.game_phase < Game_Phase.Morning or gameplay.game_phase > Game_Phase.Night: embed = discord.Embed( color=0xff0000, title="Game Not In Progress", description="The game is not in progress, and cannot be paused.") await ctx.send(embed=embed) # Check permission elif check_perms(ctx): # Game is paused -> unpause if gameplay.pause_timer: gameplay.pause_timer = False embed = discord.Embed(color=0x0080ff, title="Game Unpaused", description="The game has been unpaused.") await ctx.send(embed=embed) # Game is not paused -> pause else: gameplay.pause_timer = True embed = discord.Embed(color=0xffff00, title="⚠️ Game Paused ⚠️", description="The game has been paused.") await ctx.send(embed=embed) # Insufficient permission else: await insufficient_perms(ctx)
async def next(ctx): await asyncio.sleep(0.1) # Check permission if check_perms(ctx): # Skip Starting phase if gameplay.game_phase == Game_Phase.Starting and not gameplay.end_setup: await ctx.send("Skipping pre-game timer...") await asyncio.sleep(1) gameplay.end_setup = True # Skip Day, Evening, or Night phase elif gameplay.game_phase >= 3 and gameplay.game_phase <= 5: await ctx.send("Skipping phase...") gameplay.next_phase = True # Cannot skip else: embed = discord.Embed( color=0xff0000, title="Cannot Skip", description= "Cannot skip the current phase, or the game is not in progress." ) await ctx.send(embed=embed) # Insufficient permission else: await insufficient_perms(ctx)
async def inu(ctx, *args): await asyncio.sleep(0.1) # Check permissions if check_perms(ctx): i = 0 if args[0].lower() == "inu": i = 1 try: if args[i].lower() == "true": Settings.inu_enabled = True await ctx.send("Shiba Inu has been enabled.") elif args[i].lower() == "false": Settings.inu_enabled = False await ctx.send("Shiba Inu has been disabled.") else: raise Exception("Invalid argument.") except: await ctx.send( "Please enter a valid argument: either `true` or `false`.") # Invalid permission else: await insufficient_perms(ctx)
async def wolves(ctx, *args): await asyncio.sleep(0.1) # Check permissions if check_perms(ctx): try: value = args[0] # Check "auto" try: if value.lower() == "auto" or value.lower() == "automatic": Settings.wolf_count = 0 await ctx.send( "Wolf count set to automatic (1 per 4 players).") return except: None # Set value value = int(value) if value > 0: Settings.wolf_count = value await ctx.send("Wolf count set to {}.".format(value)) else: raise Exception("Invalid argument.") except: await ctx.send( "Please enter a valid argument: either `auto` or a positive number." ) # Invalid permission else: await insufficient_perms(ctx)
async def start(ctx): await asyncio.sleep(0.1) # Can't start if waiting for confirmation global confirm_message, confirm_user if not confirm_message["start"] == None: embed = discord.Embed( color=0xff0000, title="Awaiting Confirmation", description="Already waiting on confirmation for game start.") await ctx.send(embed=embed) return # TODO - Can't start if game is in progress if gameplay.game_phase > Game_Phase.Null: embed = discord.Embed(color=0xff0000, title="Game in Progress", description="The game is already in progress!") await ctx.send(embed=embed) return # Check permission if check_perms(ctx): number_of_players = len(players.Player_Manager.players) global bypass_player_limit # Valid number of players if number_of_players >= Settings.get_min_player_count(): embed = discord.Embed( color=0x00ff00, title="Start Game", description= "The following {} players are in the game:\n\n{}\nStart the game?" .format(number_of_players, players.Player_Manager.list_players_raw(mention=True))) await confirmations.confirm_game_start(ctx, embed) # No players elif number_of_players == 0: embed = discord.Embed( color=0xff0000, title="Not Enough Players", description="No players are currently in the game.") await ctx.send(embed=embed) # Not enough players else: embed = discord.Embed( color=0xff0000, title="Not Enough Players", description= "There are only {} out of the minimum of {} players required for the game:\n\n{}" .format(number_of_players, players.Player_Manager.list_players_raw(mention=True), Settings.get_min_player_count())) await ctx.send(embed=embed) # Insufficient permission else: await insufficient_perms(ctx)
async def bypasslimit(ctx): await asyncio.sleep(0.1) # Only Sparkfire can use this command if check_perms(ctx) and ctx.author.id == 221115928933302272: global bypass_player_limit bypass_player_limit = not bypass_player_limit await ctx.send("Player limit has been {}.".format( "disabled" if bypass_player_limit else "enabled"))
async def allowduplicates(ctx): await asyncio.sleep(0.1) # Only Sparkfire can use this command if check_perms(ctx) and ctx.author.id == 221115928933302272: global allow_duplicate_players allow_duplicate_players = not allow_duplicate_players await ctx.send("Duplicate players have been {}.".format( "enabled" if allow_duplicate_players else "disabled"))
async def loadchannels(ctx): # Check permissions if check_perms(ctx): try: file = open("channels.txt", 'r') content = file.read() text = content.split("\n") file.close() count = 0 async with ctx.channel.typing(): for i, c in enumerate(channels): if text[i] != "None": try: channels[c] = client.get_channel(int(text[i])) count += 1 except: await ctx.send( "Failed to load the {} channel.".format(c)) else: await ctx.send( "There is no {} channel to load.".format(c)) await asyncio.sleep(0.25) if count == 0: embed = discord.Embed( color=0xff0000, title="Channel Setup Done", description="Could not load any channels.") else: embed = discord.Embed( color=0x00ff00, title="Channel Setup Done", description="Successfully loaded {} channels.".format( count)) await ctx.send(embed=embed) # Failed to load except: embed = discord.Embed( color=0xff0000, title="Error Loading Channels", description="There was an error in loading the channels. \ \nThis may occur if channels have never been previously stored before." ) await ctx.send(embed=embed) # Insufficient perms else: await insufficient_perms(ctx)
async def clearplayers(ctx): await asyncio.sleep(0.1) # Check if game is running if gameplay.game_phase > Game_Phase.Null: description = "Cannot edit players while the game is in progress." embed = discord.Embed(color=0xff0000, title="Cannot Edit Players", description=description) await ctx.send(embed=embed) # Check permissions elif check_perms(ctx): await ctx.send(players.Player_Manager.clear_players()) else: await insufficient_perms(ctx)
async def addplayer(ctx): await asyncio.sleep(0.1) # Check if game is running if gameplay.game_phase > Game_Phase.Null: description = "Cannot edit players while the game is in progress." embed = discord.Embed(color=0xff0000, title="Cannot Edit Players", description=description) await ctx.send(embed=embed) # Check permission elif check_perms(ctx): # Add player(s) names_str = "" global allow_duplicate_players for i, user in enumerate(ctx.message.mentions): # Convert mentioned player into player class new_player = players.Player(user, Player_Types.Human) # Attempt to add player if players.Player_Manager.add_player( new_player, allow_dupes=allow_duplicate_players): # Format name for output string names_str += "`{}`".format(new_player.name) if len(ctx.message.mentions) > 1 and i == len( ctx.message.mentions) - 2: names_str += " and " elif i < len(ctx.message.mentions) - 2: names_str += ", " # No players given if names_str == "": await ctx.send("No valid players given.") # Valid players added to list else: length = len(players.Player_Manager.players) await ctx.send("Added {} to the list of players.\nThere {} now {} player{}.".format(names_str, \ "are" if length > 1 else "is", \ length, \ "s" if length > 1 else "")) # Insufficient Perms else: await insufficient_perms(ctx)
async def resetgame(ctx): await asyncio.sleep(0.1) # Check permission if check_perms(ctx): # Send confirmation message embed = discord.Embed( color=0xffff00, title="⚠️ Reset Game? ⚠️", description= "Are you sure you want to reset the game?\nThis will remove all players and forcefully end the game if it is in progress." ) message = await ctx.send(embed=embed) await confirmations.confirm_reset_game(ctx, message) # Insufficient permission else: await insufficient_perms(ctx)
async def clearchat(ctx, *args): await asyncio.sleep(0.1) # Check permissions if check_perms(ctx, Perm_Level.Admin): # Get amount amount = 100 try: amount = int(args[0]) except: None # Send confirmation message message = await ctx.send("Clear {} message{} from chat?".format( amount, "" if amount == 1 else "s")) await confirmations.confirm_clear_chat(ctx, message, amount + 2) # Insufficient permissions else: await insufficient_perms(ctx)
async def quickstart(ctx): await asyncio.sleep(0.1) # Only Sparkfire can use this command if check_perms(ctx) and ctx.author.id == 221115928933302272: global bypass_player_limit bypass_player_limit = True global allow_duplicate_players allow_duplicate_players = True async with ctx.channel.typing(): await loadchannels(ctx) await asyncio.sleep(0.1) if len(ctx.message.mentions) > 0: await asyncio.sleep(0.1) for i in range(8): await addplayer(ctx) await asyncio.sleep(0.5) await start(ctx)
async def storechannels(ctx): await asyncio.sleep(0.1) # Check permissions if check_perms(ctx): file = open("channels.txt", 'w') global channels for channel in channels: if channels[channel] == None: file.write("None\n") else: file.write("{}\n".format(str(channels[channel].id))) file.close() embed = discord.Embed(color=0x00ff00, title="Channel Setup Success", description="Successfully stored channels.") await ctx.send(embed=embed) # Insufficient perms else: await insufficient_perms(ctx)
async def gettingstarted(ctx): await asyncio.sleep(0.1) if check_perms(ctx): description = """To start, you first must set up the channels for the game. See `$help channels` for more information. \ To check if the channels have already been setup, use the `$listchannels` command. Before the game starts, you can use the `$settings` command to fiddle with the game settings. Use `$help settings` for more info. To add players to the game, use the `$add` command, followed by mentions of the players you wish to add. Once all the desired players are added, use the `$start` command to start the game, which will automatically distribute roles and set everything up.""" embed = discord.Embed(color=0x555555, title="Getting Started with Shin'nai-sama", description=description) # ----- description = "Once the game is started, a timer will automatically run each phase of the game and open and close channels. \ \nYou can use the `$next` command to manually skip a phase, if you wish. \ \nUse the `$kill` command to kill off players. \ \nThe `$end` command will forcefully quit the game. This is important, as the game *will not automatically end itself*." embed.add_field(name="Running the Game", value=description, inline=False) # ----- description = "There is a `$poll` command that players can use to start polls, and a `$timer` command for moderators to use to create manual timers if needed." embed.add_field(name="Miscallaneous", value=description, inline=False) await ctx.send(embed=embed) else: await insufficient_perms(ctx)
async def badger(ctx, *args): await asyncio.sleep(0.1) # Check permissions if check_perms(ctx): try: # True/False try: if args[0].lower() == "true": Settings.badger_chance = 100 await ctx.send("Badger chance set to 100%") return elif args[0].lower() == "false": Settings.badger_chance = 0 await ctx.send("Badger chance set to 0%") return except: None # Number value value = int(args[0]) if value >= 0 and value <= 100: Settings.badger_chance = value await ctx.send("Badger chance set to {}%".format(value)) else: raise Exception("Invalid argument.") except: await ctx.send( "Please enter a valid argument: a number between 0 and 100, inclusive." ) # Invalid permission else: await insufficient_perms(ctx)
async def kill(ctx, *args): await asyncio.sleep(0.1) # Check if game is running or not # if not misc.game_in_progress(gameplay.game_phase): # description = "Cannot kill players if the game is not in progress." # embed = discord.Embed(color = 0xff0000, title = "Cannot Kill Player", description = description) # await ctx.send(embed = embed) # return # Check permission if check_perms(ctx): #players.Player_Manager.kill_player() for i, user in enumerate(ctx.message.mentions): if i == 0: # Successfull kill if await players.Player_Manager.kill_player(user.id): # TODO - send proper death message await ctx.send("Killed {}".format(user.mention)) # Could not kill else: description = "Failed to kill {}, as they are not alive in the game.".format( user.mention) embed = discord.Embed(color=0xff0000, title="Failed to Kill Player", description=description) await ctx.send(embed=embed) return # Insufficient permission else: await insufficient_perms(ctx)
async def monkey(ctx, *args): await asyncio.sleep(0.1) # Check permissions if check_perms(ctx): try: if args[0].lower() == "true": Settings.monkeys_enabled = True await ctx.send("Monkeys have been enabled.") elif args[0].lower() == "false": Settings.monkeys_enabled = False await ctx.send("Monkeys have been disabled.") else: raise Exception("Invalid argument.") except: await ctx.send( "Please enter a valid argument: either `true` or `false`.") # Invalid permission else: await insufficient_perms(ctx)
async def channel(ctx, *args): await asyncio.sleep(0.1) # Check permissions if check_perms(ctx): global channels # Grab arguments try: arg = args[0].lower() text_channel = ctx.message.channel_mentions[0] except: # Invalid arguments embed = discord.Embed( color=0xff0000, title="Invalid Arguments", description= "Invalid arguments supplied.\nUse `$help channel` for more details." ) await ctx.send(embed=embed) return # Setup text channel if arg in channels: try: channels[arg] = text_channel text = "Successfully setup <#{}> as the {} channel.".format( str(channels[arg].id), arg) embed = discord.Embed(color=0x00ff00, title="Channel Setup Success", description=text) await ctx.send(embed=embed) except: embed = discord.Embed( color=0xff0000, title="Channel Setup Failed", description="Failed to setup the given channel.") await ctx.send(embed=embed) return # Grab optional argument for voice channels try: arg_voice = args[1].lower() except: None # Setup voice channel if arg == "voice": # Meeting voice chat if arg_voice == "meeting": try: channels["voice_meeting"] = text_channel text = "Successfully setup <#{}> as the meeting voice channel.".format( str(channels["voice_meeting"].id)) embed = discord.Embed(color=0x00ff00, title="Channel Setup Success", description=text) await ctx.send(embed=embed) except: embed = discord.Embed( color=0xff0000, title="Channel Setup Failed", description= "Failed to setup the meeting voice channel.\nUse the format `<#channel_id>` to mention voice channels." ) await ctx.send(embed=embed) return # Wolf voice chat elif arg_voice == "wolves": try: channels["voice_wolves"] = text_channel text = "Successfully setup <#{}> as the wolves voice channel.".format( str(channels["voice_wolves"].id)) embed = discord.Embed(color=0x00ff00, title="Channel Setup Success", description=text) await ctx.send(embed=embed) except: embed = discord.Embed( color=0xff0000, title="Channel Setup Failed", description= "Failed to setup the wolves voice channel.\nUse the format `<#channel_id>` to mention voice channels." ) await ctx.send(embed=embed) return # Nothing happened embed = discord.Embed( color=0xff0000, title="Invalid Arguments", description= "Invalid arguments supplied.\nUse `$help channel` for more details." ) await ctx.send(embed=embed) # Invalid permission else: await insufficient_perms(ctx)
async def help(ctx): await asyncio.sleep(0.1) if ctx.invoked_subcommand is None: # Regular commands description = """`$poll` - Starts a poll with the given text. `$listplayers` - Lists all players currently in the game.""" embed = discord.Embed(color=0x555555, title="Shin'nai-sama Commands", description=description) description = """`$time` - Checks the current time remaining in the day. `$spectate` - Spectate the game.""" embed.add_field(name="In-Game Commands", value=description, inline=False) description = """`$help` - Lists all available bot comamnds. `$ping` - Test command that gives the bot\'s latency time.""" embed.add_field(name="Miscellaneous", value=description, inline=False) await ctx.send(embed=embed) # Moderator commands if check_perms(ctx): description = "`$gettingstarted` - Provides information on how to use the bot." embed = discord.Embed(color=0x555555, title="Shin'nai-sama Moderator Commands", description=description) description = """`$add` - Adds all given mentioned players to the game. `$remove` - Removes all given mentioned players from the game. `$listplayers` - Lists all players currently in the game. Use `$help listplayers` for more info. `$clearplayers` - Removes all players from the game.""" embed.add_field(name="Player Management", value=description, inline=False) description = """`$channel` - Sets up the channels for the game. Use `$help channel` for more info. `$listchannels` - Lists all the channels used for the game and their assigned channels.""" embed.add_field(name="Channel Management", value=description, inline=False) description = """`$settings` - Displays and sets up settings for the game. Use `$help settings` for more info. `$start` - Starts the game. `$next` - Skips to the next phase of the game, if possible. `$end` - Forcefully ends the game. Players remain in the game, with their roles. `$reset` - Forcefully ends and resets the game. Removes all players from the game.""" embed.add_field(name="Game Management", value=description, inline=False) description = """`$kill` - Kills the given player. `$pause` - Pause/unpauses the game timer.""" embed.add_field(name="Running the Game", value=description, inline=False) description = """`$timer` - Starts a timer for a specified amount of minutes. `$clearchat` - Removes a specified number of messages from the channel. Defaults to 100.""" embed.add_field(name="Miscellaneous", value=description, inline=False) await ctx.send(embed=embed) # Dev commands - only displays for developer if ctx.author.id == 221115928933302272: description = """`$test` - Test command for testing purposes. `$storechannels` - Stores the channels into a text document for later use. `$loadchannels` - Loads the stored channels from the text document for use. `$bypasslimit` - Toggles the player limit of 12 for the game on and off. `$allowdupes` - Toggles whether or not duplicate players are allowed. `$quickstart` - Quickly sets up the game for testing.""" embed = discord.Embed(color=0x555555, title="Shin'nai-sama Dev Commands", description=description) await ctx.send(embed=embed)