Merge branch 'werewolf_develop' of https://github.com/bobloy/Fox-V3 into werewolf_develop

pull/5/head
bobloy 7 years ago
commit 5694a61edb

@ -218,6 +218,30 @@ async def prev_group(ctx: RedContext, pages: list,
page=page, timeout=timeout) 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): def say_role_list(code_list):
roles = [ROLE_LIST[idx] for idx in code_list] roles = [ROLE_LIST[idx] for idx in code_list]
embed = discord.Embed(title="Currently selected roles") embed = discord.Embed(title="Currently selected roles")

@ -46,6 +46,12 @@ class Role:
"You win by testing the game\n" "You win by testing the game\n"
"Lynch players during the day with `[p]ww vote <ID>`" "Lynch players during the day with `[p]ww vote <ID>`"
) )
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): def __init__(self, game):
self.game = game self.game = game

@ -4,8 +4,9 @@ from redbot.core import Config
from redbot.core import RedContext from redbot.core import RedContext
from redbot.core.bot import Red 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.game import Game
from werewolf.utils.menus import menu, DEFAULT_CONTROLS
class Werewolf: class Werewolf:
""" """
@ -102,8 +103,8 @@ class Werewolf:
await ctx.send_help() await ctx.send_help()
@commands.guild_only() @commands.guild_only()
@ww.command() @ww.command(name="new")
async def new(self, ctx: RedContext, game_code=None): async def ww_new(self, ctx: RedContext, game_code=None):
""" """
Create and join a new game of Werewolf Create and join a new game of Werewolf
""" """
@ -114,8 +115,8 @@ class Werewolf:
await ctx.send("Game is ready to join! Use `[p]ww join`") await ctx.send("Game is ready to join! Use `[p]ww join`")
@commands.guild_only() @commands.guild_only()
@ww.command() @ww.command(name="join")
async def join(self, ctx: RedContext): async def ww_join(self, ctx: RedContext):
""" """
Joins a game of Werewolf Joins a game of Werewolf
""" """
@ -129,8 +130,8 @@ class Werewolf:
await game.join(ctx.author, ctx.channel) await game.join(ctx.author, ctx.channel)
@commands.guild_only() @commands.guild_only()
@ww.command() @ww.command(name="code")
async def code(self, ctx: RedContext, code): async def ww_code(self, ctx: RedContext, code):
""" """
Adjust game code Adjust game code
""" """
@ -144,8 +145,8 @@ class Werewolf:
await game.set_code(ctx, code) await game.set_code(ctx, code)
@commands.guild_only() @commands.guild_only()
@ww.command() @ww.command(name="quit")
async def quit(self, ctx: RedContext): async def ww_quit(self, ctx: RedContext):
""" """
Quit a game of Werewolf Quit a game of Werewolf
""" """
@ -155,8 +156,8 @@ class Werewolf:
await game.quit(ctx.author, ctx.channel) await game.quit(ctx.author, ctx.channel)
@commands.guild_only() @commands.guild_only()
@ww.command() @ww.command(name="start")
async def start(self, ctx: RedContext): async def ww_start(self, ctx: RedContext):
""" """
Checks number of players and attempts to start the game Checks number of players and attempts to start the game
""" """
@ -167,8 +168,8 @@ class Werewolf:
await game.setup(ctx) await game.setup(ctx)
@commands.guild_only() @commands.guild_only()
@ww.command() @ww.command(name="stop")
async def stop(self, ctx: RedContext): async def ww_stop(self, ctx: RedContext):
""" """
Stops the current game Stops the current game
""" """
@ -185,8 +186,8 @@ class Werewolf:
await ctx.send("Game has been stopped") await ctx.send("Game has been stopped")
@commands.guild_only() @commands.guild_only()
@ww.command() @ww.command(name="vote")
async def vote(self, ctx: RedContext, target_id: int): async def ww_vote(self, ctx: RedContext, target_id: int):
""" """
Vote for a player by ID Vote for a player by ID
""" """
@ -225,8 +226,8 @@ class Werewolf:
else: else:
await ctx.send("Nothing to vote for in this channel") await ctx.send("Nothing to vote for in this channel")
@ww.command() @ww.command(name="choose")
async def choose(self, ctx: RedContext, data): async def ww_choose(self, ctx: RedContext, data):
""" """
Arbitrary decision making Arbitrary decision making
Handled by game+role Handled by game+role
@ -247,6 +248,54 @@ class Werewolf:
await game.choose(ctx, data) 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): async def _get_game(self, ctx: RedContext, game_code=None):
guild: discord.Guild = ctx.guild guild: discord.Guild = ctx.guild

Loading…
Cancel
Save