Skip to content

Commit

Permalink
add discord command to list characters
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Jun 4, 2024
1 parent c7a020d commit 1c36bc8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
4 changes: 4 additions & 0 deletions prompts/discord-en-us.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
32 changes: 26 additions & 6 deletions taleweave/bot/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1c36bc8

Please sign in to comment.