From dfe0d9d221ce468e0bbbd00dfab181f48b5e73b3 Mon Sep 17 00:00:00 2001 From: Slipstream Date: Wed, 30 Apr 2025 11:45:18 -0600 Subject: [PATCH] aaa --- gurt/commands.py | 21 +++++++++++++++++++++ gurt_memory.py | 14 ++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/gurt/commands.py b/gurt/commands.py index 5fe5bfe..28c4a74 100644 --- a/gurt/commands.py +++ b/gurt/commands.py @@ -361,6 +361,27 @@ def setup_commands(cog: 'GurtCog'): command_functions.append(gurtforceauto) # Add gurtforceauto to the list + # --- Gurt Clear Action History Command (Owner Only) --- + @cog.bot.tree.command(name="gurtclearhistory", description="Clear Gurt's internal autonomous action history. (Owner only)") + async def gurtclearhistory(interaction: discord.Interaction): + """Handles the /gurtclearhistory command.""" + if interaction.user.id != cog.bot.owner_id: + await interaction.response.send_message("⛔ Only the bot owner can clear the action history.", ephemeral=True) + return + await interaction.response.defer(ephemeral=True) + try: + result = await cog.memory_manager.clear_internal_action_logs() + if "error" in result: + await interaction.followup.send(f"⚠️ Error clearing action history: {result['error']}", ephemeral=True) + else: + await interaction.followup.send("✅ Gurt's autonomous action history has been cleared.", ephemeral=True) + except Exception as e: + import traceback + traceback.print_exc() + await interaction.followup.send(f"❌ An unexpected error occurred while clearing history: {e}", ephemeral=True) + + command_functions.append(gurtclearhistory) # Add the new command + # --- Gurt Goal Command Group --- gurtgoal_group = app_commands.Group(name="gurtgoal", description="Manage Gurt's long-term goals (Owner only)") diff --git a/gurt_memory.py b/gurt_memory.py index 8a13556..c8546b8 100644 --- a/gurt_memory.py +++ b/gurt_memory.py @@ -1091,3 +1091,17 @@ class MemoryManager: except Exception as e: logger.error(f"Error retrieving internal action logs: {e}", exc_info=True) return [] + + # --- Add the new method below --- + async def clear_internal_action_logs(self) -> Dict[str, Any]: + """Deletes all records from the internal_actions table.""" + logger.info("Attempting to clear all internal action logs.") + try: + await self._db_execute("DELETE FROM internal_actions") + # Optionally, reset the autoincrement sequence if using SQLite + # await self._db_execute("DELETE FROM sqlite_sequence WHERE name='internal_actions'") + logger.info("Successfully cleared all internal action logs.") + return {"status": "cleared"} + except Exception as e: + logger.error(f"Error clearing internal action logs: {e}", exc_info=True) + return {"error": f"Database error clearing internal action logs: {str(e)}"}