From 1c36bc8386cc30c619fcb207e7faa82b2ebc1f44 Mon Sep 17 00:00:00 2001 From: Sean Sube Date: Mon, 3 Jun 2024 22:00:14 -0500 Subject: [PATCH] add discord command to list characters --- prompts/discord-en-us.yml | 4 ++++ taleweave/bot/discord.py | 32 ++++++++++++++++++++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/prompts/discord-en-us.yml b/prompts/discord-en-us.yml index c65dd7a..191c618 100644 --- a/prompts/discord-en-us.yml +++ b/prompts/discord-en-us.yml @@ -1,4 +1,8 @@ prompts: + discord_characters_none: There are no characters available to play. + discord_characters_list: | + **Characters:** + {{ characters | and_list }} discord_help: | **Commands:** - `!help` - Show this help message diff --git a/taleweave/bot/discord.py b/taleweave/bot/discord.py index d1ce317..15eaa71 100644 --- a/taleweave/bot/discord.py +++ b/taleweave/bot/discord.py @@ -37,6 +37,7 @@ ) from taleweave.render.comfy import render_event from taleweave.utils.prompt import format_prompt +from taleweave.utils.search import list_characters logger = getLogger(__name__) client = None @@ -103,15 +104,13 @@ async def on_message(self, message): await message.channel.send(world_message) return - # TODO: command to list available characters - - if content.startswith("!help"): + if content.startswith(config.bot.discord.command_prefix + "help"): await message.channel.send( format_prompt("discord_help", bot_name=config.bot.discord.name_command) ) return - if content.startswith("!join"): + if content.startswith(config.bot.discord.command_prefix + "join"): character_name = content.replace("!join", "").strip() if has_player(character_name): await channel.send( @@ -149,14 +148,35 @@ def prompt_player(event: PromptEvent): join_event = PlayerEvent("join", character_name, user_name) return broadcast(join_event) - if content.startswith("!players"): + if content.startswith(config.bot.discord.command_prefix + "characters"): + world = get_current_world() + if not world: + await channel.send( + format_prompt( + "discord_characters_none", + bot_name=config.bot.discord.name_title, + ) + ) + return + + characters = [character.name for character in list_characters(world)] + await channel.send( + format_prompt( + "discord_characters_list", + bot_name=config.bot.discord.name_title, + characters=characters, + ) + ) + return + + if content.startswith(config.bot.discord.command_prefix + "players"): players = list_players() await channel.send(embed=format_players(players)) return player = get_player(user_name) if isinstance(player, RemotePlayer): - if content.startswith("!leave"): + if content.startswith(config.bot.discord.command_prefix + "leave"): remove_player(user_name) # revert to LLM agent