feat: Add command to reset Gurt's personality and interests to baseline for owner
This commit is contained in:
parent
dddabd0b42
commit
f7a1a2134e
@ -55,6 +55,8 @@ class GurtCog(commands.Cog, name="Gurt"): # Added explicit Cog name
|
|||||||
self.default_model = DEFAULT_MODEL # Use imported config
|
self.default_model = DEFAULT_MODEL # Use imported config
|
||||||
self.fallback_model = FALLBACK_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.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
|
self.current_channel: Optional[Union[discord.TextChannel, discord.Thread, discord.DMChannel]] = None # Type hint current channel
|
||||||
|
|
||||||
# Ignored channels config
|
# Ignored channels config
|
||||||
|
@ -743,6 +743,44 @@ def setup_commands(cog: 'GurtCog'):
|
|||||||
|
|
||||||
command_functions.append(gurttenorapikey)
|
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
|
# Get command names safely - Command objects don't have __name__ attribute
|
||||||
command_names = []
|
command_names = []
|
||||||
|
@ -647,6 +647,32 @@ class MemoryManager:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error loading baseline interests: {e}", exc_info=True)
|
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) ---
|
# --- Interest Methods (SQLite) ---
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user