fix channel members tool, add debug commands
This commit is contained in:
+99
-2
@@ -49,6 +49,8 @@ logger = logging.getLogger(__name__)
|
||||
# Initialize the bot
|
||||
intents = discord.Intents.default()
|
||||
intents.message_content = True
|
||||
intents.members = True
|
||||
intents.presences = True
|
||||
bot = commands.Bot(command_prefix="!", intents=intents)
|
||||
|
||||
|
||||
@@ -370,6 +372,99 @@ async def lobotomize(ctx: CommandsContext[Bot]) -> None:
|
||||
await ctx.send("All conversation history and memory has been cleared. 🧠✨")
|
||||
|
||||
|
||||
@bot.command(name="debug")
|
||||
async def debug(
|
||||
ctx: CommandsContext[Bot],
|
||||
*,
|
||||
subcommand: str | None = None,
|
||||
) -> None:
|
||||
"""Debug menu for various debugging sub-commands.
|
||||
|
||||
Usage: !debug <subcommand>
|
||||
Available sub-commands:
|
||||
- members: List all members in the current channel
|
||||
- whoami: Show all information the bot has about you
|
||||
- tools: Show the LLM's available tools
|
||||
"""
|
||||
logger.info(
|
||||
"Debug command triggered by %s with subcommand %r", ctx.author.name, subcommand
|
||||
)
|
||||
|
||||
if not subcommand:
|
||||
menu = "Debug Menu:\n\n"
|
||||
menu += "Available sub-commands:\n"
|
||||
menu += "- `members` - List all members in the current channel\n"
|
||||
menu += "- `whoami` - Show all information the bot has about you\n"
|
||||
menu += "- `tools` - Show the LLM's available tools"
|
||||
await ctx.send(menu)
|
||||
return
|
||||
|
||||
if subcommand == "members":
|
||||
result = get_channel_members_impl(ctx.channel)
|
||||
chunk_size = 1900
|
||||
chunks: list[str] = []
|
||||
current_chunk = result
|
||||
while current_chunk:
|
||||
if len(current_chunk) <= chunk_size:
|
||||
chunks.append(current_chunk)
|
||||
break
|
||||
split_pos = current_chunk.rfind("\n", 0, chunk_size)
|
||||
if split_pos == -1:
|
||||
split_pos = chunk_size
|
||||
chunks.append(current_chunk[:split_pos])
|
||||
current_chunk = current_chunk[split_pos:].lstrip("\n")
|
||||
|
||||
for chunk in chunks:
|
||||
await ctx.send(chunk)
|
||||
return
|
||||
|
||||
if subcommand == "whoami":
|
||||
user_info = get_user_info(ctx.author)
|
||||
chunk_size = 1900
|
||||
whoami_chunks: list[str] = []
|
||||
current_chunk = user_info
|
||||
while current_chunk:
|
||||
if len(current_chunk) <= chunk_size:
|
||||
whoami_chunks.append(current_chunk)
|
||||
break
|
||||
split_pos = current_chunk.rfind("\n", 0, chunk_size)
|
||||
if split_pos == -1:
|
||||
split_pos = chunk_size
|
||||
whoami_chunks.append(current_chunk[:split_pos])
|
||||
current_chunk = current_chunk[split_pos:].lstrip("\n")
|
||||
|
||||
for chunk in whoami_chunks:
|
||||
await ctx.send(chunk)
|
||||
return
|
||||
|
||||
if subcommand == "tools":
|
||||
tool_list = "LLM Tools:\n\n"
|
||||
tool_list += f"- `{get_channel_members.name}`\n"
|
||||
tool_list += f" Description: {get_channel_members.description}\n"
|
||||
tool_list += f" Parameters: {get_channel_members.args_schema.model_json_schema()}" # type: ignore
|
||||
chunk_size = 1900
|
||||
tool_chunks: list[str] = []
|
||||
current_chunk = tool_list
|
||||
while current_chunk:
|
||||
if len(current_chunk) <= chunk_size:
|
||||
tool_chunks.append(current_chunk)
|
||||
break
|
||||
split_pos = current_chunk.rfind("\n", 0, chunk_size)
|
||||
if split_pos == -1:
|
||||
split_pos = chunk_size
|
||||
tool_chunks.append(current_chunk[:split_pos])
|
||||
current_chunk = current_chunk[split_pos:].lstrip("\n")
|
||||
|
||||
for chunk in tool_chunks:
|
||||
await ctx.send(chunk)
|
||||
return
|
||||
|
||||
await ctx.send(
|
||||
f"Unknown debug sub-command: `{subcommand}`\n\n"
|
||||
f"Use `!debug` to see available sub-commands.",
|
||||
)
|
||||
|
||||
|
||||
@bot.command(name="voices")
|
||||
async def voices(ctx: CommandsContext[Bot]) -> None:
|
||||
"""List all available TTS voices organized by category."""
|
||||
@@ -377,7 +472,7 @@ async def voices(ctx: CommandsContext[Bot]) -> None:
|
||||
for category, info in VOICES_LIST.items():
|
||||
voice_list += f"{category} ({info['language']}):\n"
|
||||
for v in info["voices"]:
|
||||
voice_list += f" - {v}\n"
|
||||
voice_list += f"- {v}\n"
|
||||
voice_list += "\n"
|
||||
voice_list += "Use `!speak <text> --voice <voice_name>` to choose a voice."
|
||||
|
||||
@@ -514,7 +609,9 @@ async def _speak_with_bot(
|
||||
return get_channel_members_impl(ctx.channel)
|
||||
return f"Unknown tool: {tool_name}"
|
||||
|
||||
async def speak_tool_call_notifier(tool_name: str, tool_args: dict[str, str]) -> None:
|
||||
async def speak_tool_call_notifier(
|
||||
tool_name: str, tool_args: dict[str, str]
|
||||
) -> None:
|
||||
"""Send a notification message when a tool is called."""
|
||||
if tool_name == "get_channel_members":
|
||||
await ctx.send(f"**{bot_name}** is looking at the channel members...")
|
||||
|
||||
Reference in New Issue
Block a user