diff --git a/gurt/cog.py b/gurt/cog.py index 15836d7..5f7004d 100644 --- a/gurt/cog.py +++ b/gurt/cog.py @@ -55,6 +55,8 @@ class GurtCog(commands.Cog, name="Gurt"): # Added explicit Cog name self.default_model = DEFAULT_MODEL # Use imported config self.fallback_model = FALLBACK_MODEL # Use imported config self.MOOD_OPTIONS = MOOD_OPTIONS # Make MOOD_OPTIONS available as an instance attribute + self.BASELINE_PERSONALITY = BASELINE_PERSONALITY # Store for commands + self.BASELINE_INTERESTS = BASELINE_INTERESTS # Store for commands self.current_channel: Optional[Union[discord.TextChannel, discord.Thread, discord.DMChannel]] = None # Type hint current channel # Ignored channels config diff --git a/gurt/commands.py b/gurt/commands.py index 0d70653..d34ade7 100644 --- a/gurt/commands.py +++ b/gurt/commands.py @@ -743,6 +743,44 @@ def setup_commands(cog: 'GurtCog'): command_functions.append(gurttenorapikey) + # --- Gurt Reset Personality Command (Owner Only) --- + @cog.bot.tree.command(name="gurtresetpersonality", description="Reset Gurt's personality and interests to baseline. (Owner only)") + async def gurtresetpersonality(interaction: discord.Interaction): + """Handles the /gurtresetpersonality command.""" + if interaction.user.id != cog.bot.owner_id: + await interaction.response.send_message("⛔ Only the bot owner can reset Gurt's personality.", ephemeral=True) + return + await interaction.response.defer(ephemeral=True) + try: + # Ensure the cog has access to baseline values, e.g., cog.BASELINE_PERSONALITY + # These would typically be loaded from gurt.config into the GurtCog instance + if not hasattr(cog, 'BASELINE_PERSONALITY') or not hasattr(cog, 'BASELINE_INTERESTS'): + await interaction.followup.send("⚠️ Baseline personality or interests not found in cog configuration. Reset aborted.", ephemeral=True) + return + + personality_result = await cog.memory_manager.reset_personality_to_baseline(cog.BASELINE_PERSONALITY) + interests_result = await cog.memory_manager.reset_interests_to_baseline(cog.BASELINE_INTERESTS) + + messages = [] + if personality_result.get("status") == "success": + messages.append("✅ Personality traits reset to baseline.") + else: + messages.append(f"⚠️ Error resetting personality: {personality_result.get('error', 'Unknown error')}") + + if interests_result.get("status") == "success": + messages.append("✅ Interests reset to baseline.") + else: + messages.append(f"⚠️ Error resetting interests: {interests_result.get('error', 'Unknown error')}") + + await interaction.followup.send("\n".join(messages), ephemeral=True) + + except Exception as e: + import traceback + traceback.print_exc() + await interaction.followup.send(f"❌ An unexpected error occurred while resetting personality: {e}", ephemeral=True) + + command_functions.append(gurtresetpersonality) + # Get command names safely - Command objects don't have __name__ attribute command_names = [] diff --git a/gurt_memory.py b/gurt_memory.py index fe491bf..4ffe885 100644 --- a/gurt_memory.py +++ b/gurt_memory.py @@ -647,6 +647,32 @@ class MemoryManager: except Exception as e: logger.error(f"Error loading baseline interests: {e}", exc_info=True) + async def reset_personality_to_baseline(self, baseline_traits: Dict[str, Any]): + """Clears all personality traits and reloads them from the provided baseline.""" + logger.info("Resetting personality traits to baseline...") + try: + await self._db_execute("DELETE FROM gurt_personality") + logger.info("Cleared all existing personality traits from the database.") + await self.load_baseline_personality(baseline_traits) + logger.info("Successfully reset personality traits to baseline.") + return {"status": "success", "message": "Personality traits reset to baseline."} + except Exception as e: + logger.error(f"Error resetting personality traits: {e}", exc_info=True) + return {"error": f"Database error resetting personality: {str(e)}"} + + async def reset_interests_to_baseline(self, baseline_interests: Dict[str, float]): + """Clears all interests and reloads them from the provided baseline.""" + logger.info("Resetting interests to baseline...") + try: + await self._db_execute("DELETE FROM gurt_interests") + logger.info("Cleared all existing interests from the database.") + await self.load_baseline_interests(baseline_interests) + logger.info("Successfully reset interests to baseline.") + return {"status": "success", "message": "Interests reset to baseline."} + except Exception as e: + logger.error(f"Error resetting interests: {e}", exc_info=True) + return {"error": f"Database error resetting interests: {str(e)}"} + # --- Interest Methods (SQLite) ---