From e8f6b4c5f40fe0191fe6f3dbbad9e58188cd302e Mon Sep 17 00:00:00 2001 From: fretuks Date: Tue, 16 Dec 2025 09:51:01 +0100 Subject: [PATCH] Fix the fucking bot #2 --- tars_bot.py | 112 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 72 insertions(+), 40 deletions(-) diff --git a/tars_bot.py b/tars_bot.py index 6fff2b4..083c896 100644 --- a/tars_bot.py +++ b/tars_bot.py @@ -49,6 +49,19 @@ ERROR_LOG: list[datetime] = [] COOLDOWN_UNTIL: datetime | None = None TOPIC_COUNTER = defaultdict(int) HOURLY_ACTIVITY = defaultdict(int) +TARS_COMMAND_CATEGORIES = { + "Moderation": { + "tarsreport", "clean", "lock", "unlock", "slowmode", + "addbannedword", "removebannedword", "listbannedwords" + }, + "Utility & Diagnostics": { + "userinfo", "roleinfo", "serverinfo", "status", + "config_view", "ai_stats", "remindme", "reactionrole", "setmotd" + }, + "Recreational Protocols": { + "8ball", "dice", "quote", "getquote", "ping" + } +} async def check_openai_health() -> bool: @@ -101,6 +114,38 @@ def is_dead_hour() -> bool: return current < (avg * 0.5) +async def tars_command_help(interaction: discord.Interaction, command_name: str): + cmd = next((c for c in tree.get_commands() if c.name == command_name), None) + if not cmd: + await interaction.response.send_message( + tars_text(f"Unknown command: `{command_name}`", "error"), + ephemeral=True + ) + return + if isinstance(cmd, app_commands.Command): + perms = cmd.checks + if perms and not interaction.user.guild_permissions.manage_messages: + pass + usage = f"/{cmd.name}" + if cmd.parameters: + for p in cmd.parameters: + usage += f" <{p.name}>" + embed = discord.Embed( + title=f"/{cmd.name}", + description=cmd.description or "No description provided.", + color=0x00ffcc + ) + embed.add_field(name="Usage", value=f"`{usage}`", inline=False) + if cmd.parameters: + params = "\n".join( + f"• **{p.name}** — {p.description or 'No description'}" + for p in cmd.parameters + ) + embed.add_field(name="Parameters", value=params, inline=False) + embed.set_footer(text="— T.A.R.S. Command Reference") + await interaction.response.send_message(embed=embed, ephemeral=True) + + CONFIG_SCHEMA = { "revive_interval": int, "motd_channel_id": (int, type(None)), @@ -788,54 +833,41 @@ async def on_message(message: discord.Message): await message.reply(tars_text(safe_reply)) -@tree.command(name="tars", description="Activate T.A.R.S. and show available commands") -async def slash_tars(interaction: discord.Interaction): +@tree.command(name="tars", description="T.A.R.S. command console and help") +@app_commands.describe(command="Optional command name for detailed help") +async def slash_tars(interaction: discord.Interaction, command: str | None = None): version = BOT_VERSION - + ai_status = "ONLINE" if FEATURE_FLAGS["ai_enabled"] else "OFFLINE" + revive_status = "ONLINE" if FEATURE_FLAGS["revive_enabled"] else "OFFLINE" + if command: + await tars_command_help(interaction, command) + return intro = tars_text( f"T.A.R.S. online. Systems nominal.\n" - f"**Current Version:** `{version}`\n\n" - "Address me directly or use the commands below.", + f"**Version:** `{version}`\n\n" + f"**Subsystem Status**\n" + f"• AI: `{ai_status}`\n" + f"• Chat Revive: `{revive_status}`\n\n" + "Use `/tars help ` for detailed command info.", "info" ) + embeds: list[discord.Embed] = [] + all_commands = {cmd.name: cmd for cmd in tree.get_commands()} + for category, names in TARS_COMMAND_CATEGORIES.items(): + lines = [] + for name in sorted(names): + cmd = all_commands.get(name) + if not cmd: + continue + lines.append(f"/{cmd.name} — {cmd.description}") - mod_embed = tars_embed( - "Moderation Systems", - "/tarsreport — report a user\n" - "/clean — delete the last N messages\n" - "/lock — lock the current channel\n" - "/unlock — unlock the current channel\n" - "/slowmode — set slowmode for a channel\n" - "/addbannedword — add a banned word\n" - "/removebannedword — remove a banned word\n" - "/listbannedwords — view banned words\n" - ) - - util_embed = tars_embed( - "Utility & Diagnostics", - "/userinfo — get user info\n" - "/roleinfo — role details\n" - "/serverinfo — server info\n" - "/status — system health & diagnostics\n" - "/config_view — view live configuration (owner)\n" - "/ai_stats — AI usage metrics (moderator)\n" - "/remindme — set a reminder\n" - "/reactionrole — create reaction roles\n" - "/setmotd — configure the message of the day\n" - ) - - fun_embed = tars_embed( - "Recreational Protocols", - "/8ball — Magic 8-ball\n" - "/dice — roll dice\n" - "/quote — save message quotes\n" - "/getquote — retrieve saved quotes\n" - "/ping — check responsiveness\n" - ) - + if lines: + embeds.append( + tars_embed(category, "\n".join(lines)) + ) await interaction.response.send_message( intro, - embeds=[mod_embed, util_embed, fun_embed], + embeds=embeds, ephemeral=False )