diff --git a/werewolf/builder.py b/werewolf/builder.py index 0c3f5d1..03a84c7 100644 --- a/werewolf/builder.py +++ b/werewolf/builder.py @@ -218,6 +218,30 @@ async def prev_group(ctx: RedContext, pages: list, page=page, timeout=timeout) +def role_from_alignment(alignment): + return [role_embed(idx, role, ALIGNMENT_COLORS[role.alignment - 1]) + for idx, role in enumerate(ROLE_LIST) if alignment == role.alignment] + + +def role_from_category(category): + return [role_embed(idx, role, ALIGNMENT_COLORS[role.alignment - 1]) + for idx, role in enumerate(ROLE_LIST) if category in role.category] + + +def role_from_id(idx): + try: + role = ROLE_LIST[idx] + except IndexError: + return None + + return role_embed(idx, role, ALIGNMENT_COLORS[role.alignment - 1]) + + +def role_from_name(name: str): + return [role_embed(idx, role, ALIGNMENT_COLORS[role.alignment - 1]) + for idx, role in enumerate(ROLE_LIST) if name in role.__name__] + + def say_role_list(code_list): roles = [ROLE_LIST[idx] for idx in code_list] embed = discord.Embed(title="Currently selected roles") diff --git a/werewolf/game.py b/werewolf/game.py index 217bf5c..acc045a 100644 --- a/werewolf/game.py +++ b/werewolf/game.py @@ -26,8 +26,8 @@ class Game: day_vote_count = 3 - def __init__(self, guild: discord.Guild, role: discord.Role=None, - category: discord.CategoryChannel=None, village: discord.TextChannel=None, + def __init__(self, guild: discord.Guild, role: discord.Role = None, + category: discord.CategoryChannel = None, village: discord.TextChannel = None, game_code=None): self.guild = guild self.game_code = game_code diff --git a/werewolf/role.py b/werewolf/role.py index afede03..a2e0a52 100644 --- a/werewolf/role.py +++ b/werewolf/role.py @@ -46,6 +46,12 @@ class Role: "You win by testing the game\n" "Lynch players during the day with `[p]ww vote `" ) + description = ( + "This is the basic role\n" + "All roles are based on this Class" + "Has no special significance" + ) + icon_url = None # Adding a URL here will enable a thumbnail of the role def __init__(self, game): self.game = game diff --git a/werewolf/werewolf.py b/werewolf/werewolf.py index 89420d9..65760c0 100644 --- a/werewolf/werewolf.py +++ b/werewolf/werewolf.py @@ -4,8 +4,9 @@ from redbot.core import Config from redbot.core import RedContext from redbot.core.bot import Red -from werewolf.builder import GameBuilder +from werewolf.builder import GameBuilder, role_from_name, role_from_alignment, role_from_category, role_from_id from werewolf.game import Game +from werewolf.utils.menus import menu, DEFAULT_CONTROLS class Werewolf: @@ -103,8 +104,8 @@ class Werewolf: await ctx.send_help() @commands.guild_only() - @ww.command() - async def new(self, ctx: RedContext, game_code=None): + @ww.command(name="new") + async def ww_new(self, ctx: RedContext, game_code=None): """ Create and join a new game of Werewolf """ @@ -115,8 +116,8 @@ class Werewolf: await ctx.send("Game is ready to join! Use `[p]ww join`") @commands.guild_only() - @ww.command() - async def join(self, ctx: RedContext): + @ww.command(name="join") + async def ww_join(self, ctx: RedContext): """ Joins a game of Werewolf """ @@ -130,8 +131,8 @@ class Werewolf: await game.join(ctx.author, ctx.channel) @commands.guild_only() - @ww.command() - async def code(self, ctx: RedContext, code): + @ww.command(name="code") + async def ww_code(self, ctx: RedContext, code): """ Adjust game code """ @@ -145,8 +146,8 @@ class Werewolf: await game.set_code(ctx, code) @commands.guild_only() - @ww.command() - async def quit(self, ctx: RedContext): + @ww.command(name="quit") + async def ww_quit(self, ctx: RedContext): """ Quit a game of Werewolf """ @@ -156,8 +157,8 @@ class Werewolf: await game.quit(ctx.author, ctx.channel) @commands.guild_only() - @ww.command() - async def start(self, ctx: RedContext): + @ww.command(name="start") + async def ww_start(self, ctx: RedContext): """ Checks number of players and attempts to start the game """ @@ -168,8 +169,8 @@ class Werewolf: await game.setup(ctx) @commands.guild_only() - @ww.command() - async def stop(self, ctx: RedContext): + @ww.command(name="stop") + async def ww_stop(self, ctx: RedContext): """ Stops the current game """ @@ -186,8 +187,8 @@ class Werewolf: await ctx.send("Game has been stopped") @commands.guild_only() - @ww.command() - async def vote(self, ctx: RedContext, target_id: int): + @ww.command(name="vote") + async def ww_vote(self, ctx: RedContext, target_id: int): """ Vote for a player by ID """ @@ -226,8 +227,8 @@ class Werewolf: else: await ctx.send("Nothing to vote for in this channel") - @ww.command() - async def choose(self, ctx: RedContext, data): + @ww.command(name="choose") + async def ww_choose(self, ctx: RedContext, data): """ Arbitrary decision making Handled by game+role @@ -249,6 +250,54 @@ class Werewolf: await game.choose(ctx, data) + @ww.group(name="search") + async def ww_search(self, ctx: RedContext): + """ + Find custom roles by name, alignment, category, or ID + """ + if ctx.invoked_subcommand is None or ctx.invoked_subcommand == self.ww_search: + await ctx.send_help() + + @ww_search.command(name="name") + async def ww_search_name(self, ctx: RedContext, *, name): + """Search for a role by name""" + if name is not None: + from_name = role_from_name(name) + if from_name: + await menu(ctx, from_name, DEFAULT_CONTROLS) + else: + await ctx.send("No roles containing that name were found") + + @ww_search.command(name="alignment") + async def ww_search_alignment(self, ctx: RedContext, alignment: int): + """Search for a role by alignment""" + if alignment is not None: + from_alignment = role_from_alignment(alignment) + if from_alignment: + await menu(ctx, from_alignment, DEFAULT_CONTROLS) + else: + await ctx.send("No roles with that alignment were found") + + @ww_search.command(name="category") + async def ww_search_category(self, ctx: RedContext, category: int): + """Search for a role by category""" + if category is not None: + pages = role_from_category(category) + if pages: + await menu(ctx, pages, DEFAULT_CONTROLS) + else: + await ctx.send("No roles in that category were found") + + @ww_search.command(name="index") + async def ww_search_index(self, ctx: RedContext, idx: int): + """Search for a role by ID""" + if idx is not None: + idx_embed = role_from_id(idx) + if idx_embed is not None: + await ctx.send(embed=idx_embed) + else: + await ctx.send("Role ID not found") + async def _get_game(self, ctx: RedContext, game_code=None): if ctx.guild is None: # Private message, can't get guild @@ -277,8 +326,6 @@ class Werewolf: await ctx.send("Game role is invalid, cannot start new game") return None - - self.games[ctx.guild.id] = Game(ctx.guild, role, game_code) return self.games[ctx.guild.id]