Skip to content

Commit

Permalink
Support command list
Browse files Browse the repository at this point in the history
  • Loading branch information
nitro2 committed May 1, 2023
1 parent d29e9e8 commit a55a145
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions commands/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 8 additions & 2 deletions game/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()

Expand Down
8 changes: 8 additions & 0 deletions json/command_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
}
}

0 comments on commit a55a145

Please sign in to comment.