From a55a1456a9eb9e20561219ff9818a3e8413bda50 Mon Sep 17 00:00:00 2001 From: nitro2 Date: Mon, 1 May 2023 16:53:49 +0700 Subject: [PATCH] Support command `list` --- commands/command.py | 5 +++++ game/__init__.py | 10 ++++++++-- json/command_info.json | 8 ++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/commands/command.py b/commands/command.py index af478e35..085f6aa1 100644 --- a/commands/command.py +++ b/commands/command.py @@ -44,6 +44,11 @@ async def parse_command(client, game, message): await admin.send_embed_to_channel( message.guild, text_template.generate_help_embed(*parameters), message.channel.name, False ) + elif cmd == "list": + if game.is_started(): + await message.reply(game.get_role_list()) # prevent bug of name's or tag's type + else: + await message.reply("Game has not started yet") # prevent bug of name's or tag's type elif cmd == "version": tag = subprocess.check_output(["git", "describe", "--tags"]).decode('utf-8') # git describe --tags name = os.getenv("BOT_NAME") diff --git a/game/__init__.py b/game/__init__.py index 4d8143bb..75ce88bd 100644 --- a/game/__init__.py +++ b/game/__init__.py @@ -138,6 +138,12 @@ def dict_to_list(config, number=0): interface, id_, names_dict[id_]) for id_, role_name in zip(ids, game_role)} print("Player list:", r) return r + + def get_role_list(self): + role_list = dict(Counter(v.__class__.__name__ for v in self.players.values())) + if not self.modes.get("hidden_role"): + return text_templates.generate_text("role_list_text", roles_data=role_list) + return "Warning: hidden_role is ON. Cannot show list" async def start(self, init_players=None): if self.is_stopped and self.game_phase == GamePhase.NEW_GAME: @@ -152,13 +158,13 @@ async def start(self, init_players=None): else: self.players = init_players - role_list = dict(Counter(v.__class__.__name__ for v in self.players.values())) + await self.create_channel() await self.interface.send_text_to_channel(text_template.generate_modes(dict(zip(self.modes, map(lambda x: "True", self.modes.values())))), config.GAMEPLAY_CHANNEL) if not self.modes.get("hidden_role"): - await self.interface.send_action_text_to_channel("role_list_text", config.GAMEPLAY_CHANNEL, roles_data=role_list) + await self.interface.send_text_to_channel(self.get_role_list(), config.GAMEPLAY_CHANNEL) self.start_time = datetime.datetime.now() diff --git a/json/command_info.json b/json/command_info.json index 06de47de..3bb65924 100644 --- a/json/command_info.json +++ b/json/command_info.json @@ -183,5 +183,13 @@ }, "exclusive_roles": ["Cupid"], "required_params": ["player_id1", "player_id2"] + }, + "list": { + "description": { + "vi": "Hiển thị các nhân vật trong game hiện tại.", + "en": "List all roles in current game." + }, + "exclusive_roles": [], + "required_params": [] } } \ No newline at end of file