Command to peek top three cards

This commit is contained in:
Elnath 2021-06-11 01:07:52 +02:00
parent ad439faed0
commit 3bc3077de8
2 changed files with 29 additions and 9 deletions

View File

@ -304,9 +304,13 @@ class Game:
@game_started @game_started
@save_on_success @save_on_success
async def draw_policies(self) -> List[Policy]: async def draw_policies(self) -> List[Policy]:
self.config["drawn"] = [self.config["deck"].pop() for _ in range(3)] self.config["drawn"] = [self.config["deck"].pop(0) for _ in range(3)]
return [Policy(p) for p in self.config["drawn"]] return [Policy(p) for p in self.config["drawn"]]
@game_started
async def peek_policies(self) -> List[Policy]:
return [Policy(self.config["deck"][i]) for i in range(3)]
@game_started @game_started
@save_on_success @save_on_success
async def enact_drawn_policy(self, index: int): async def enact_drawn_policy(self, index: int):

View File

@ -105,6 +105,15 @@ class SecretBot(commands.Cog):
await ctx.reply(":x: Game is not running") await ctx.reply(":x: Game is not running")
raise utils.CheckFailDoNotNotify raise utils.CheckFailDoNotNotify
@staticmethod
async def check_in_admin_channel_or_error_message(ctx: commands.Context, game: Game):
"""
If the message has not been sent in the game's admin channel, send an error message and raise utils.CheckFailDoNotNotify
"""
if ctx.channel != game.get_gm_channel():
await ctx.reply(":warning: You should do this in the admin channel!")
raise utils.CheckFailDoNotNotify
@commands.command(help = "See if I'm alive") @commands.command(help = "See if I'm alive")
async def ping(self, ctx: commands.Context): async def ping(self, ctx: commands.Context):
await ctx.reply(":ping_pong:", mention_author = True) await ctx.reply(":ping_pong:", mention_author = True)
@ -174,13 +183,11 @@ class SecretBot(commands.Cog):
await game.stop_vote() await game.stop_vote()
await ctx.message.delete() await ctx.message.delete()
@commands.command("Legislate") @commands.command("Legislate", help = "Start the legislative session by drawing three policies")
async def draw_policies(self, ctx: commands.Context): async def draw_policies(self, ctx: commands.Context):
game = await self.get_running_game_or_error_message(ctx) game = await self.get_running_game_or_error_message(ctx)
await self.check_is_administrator_or_gm(ctx) await self.check_is_administrator_or_gm(ctx)
if ctx.channel != game.get_gm_channel(): await self.check_in_admin_channel_or_error_message(ctx, game)
await ctx.reply(":warning: You should do this in your own channel!")
return
policies = await game.draw_policies() policies = await game.draw_policies()
message_content = [ message_content = [
"The following policies have been drawn:", "The following policies have been drawn:",
@ -189,17 +196,26 @@ class SecretBot(commands.Cog):
] ]
await ctx.reply("\n".join(message_content)) await ctx.reply("\n".join(message_content))
@commands.command("Enact") @commands.command("Enact", help = "Legislative session only: enact one of the previously drawn policies")
async def enact_drawn_policy(self, ctx: commands.Context, policy_number: int): async def enact_drawn_policy(self, ctx: commands.Context, policy_number: int):
game = await self.get_running_game_or_error_message(ctx) game = await self.get_running_game_or_error_message(ctx)
await self.check_is_administrator_or_gm(ctx) await self.check_is_administrator_or_gm(ctx)
if ctx.channel != game.get_gm_channel(): await self.check_in_admin_channel_or_error_message(ctx, game)
await ctx.reply(":warning: You should do this in your own channel!")
return
policy_number = policy_number - 1 policy_number = policy_number - 1
await game.enact_drawn_policy(policy_number) await game.enact_drawn_policy(policy_number)
await ctx.reply(":white_check_mark: Done") await ctx.reply(":white_check_mark: Done")
@commands.command("Peek", help = "Look at the top three cards of the deck without drawing them")
async def peek_policies(self, ctx: commands.Context):
game = await self.get_running_game_or_error_message(ctx)
await self.check_is_administrator_or_gm(ctx)
await self.check_in_admin_channel_or_error_message(ctx, game)
message_content = [
"The top three cards of the deck are the following:",
" ".join([":blue_square:" if policy == Policy.LIBERAL else ":red_square:" for policy in await game.peek_policies()])
]
await ctx.reply("\n".join(message_content))
if __name__ == '__main__': if __name__ == '__main__':
argparser = argparse.ArgumentParser(description = "Secret Hitler helper bot", formatter_class = argparse.ArgumentDefaultsHelpFormatter) argparser = argparse.ArgumentParser(description = "Secret Hitler helper bot", formatter_class = argparse.ArgumentDefaultsHelpFormatter)