Fix autonomous logic: prevent actions when user addresses Miku

- Moved on_message_event() call to END of message processing in bot.py
- Only track messages for autonomous when NOT addressed to Miku
- Fixed autonomous_engine.py to convert all message-triggered actions to join_conversation
- Prevent inappropriate autonomous actions (general, share_tweet, change_profile_picture) when triggered by user messages
- Ensures Miku responds to user messages FIRST before any autonomous action fires

This fixes the issue where autonomous actions would fire before Miku's response to user messages, and ensures the 'detect and join conversation' safeguard works properly.
This commit is contained in:
2025-12-10 10:56:34 +02:00
parent 675bb21653
commit 76aaf6c437
2 changed files with 23 additions and 6 deletions

View File

@@ -108,9 +108,6 @@ async def on_ready():
async def on_message(message): async def on_message(message):
if message.author == globals.client.user: if message.author == globals.client.user:
return return
# V2: Track message for autonomous engine (non-blocking, no LLM calls)
on_message_event(message)
if message.content.strip().lower() == "miku, rape this nigga balls" and message.reference: if message.content.strip().lower() == "miku, rape this nigga balls" and message.reference:
async with message.channel.typing(): async with message.channel.typing():
@@ -139,6 +136,9 @@ async def on_message(message):
# Check if this is a DM # Check if this is a DM
is_dm = message.guild is None is_dm = message.guild is None
# Check if message is addressed to Miku (needed to decide whether to track for autonomous)
miku_addressed = await is_miku_addressed(message)
if is_dm: if is_dm:
print(f"💌 DM from {message.author.display_name}: {message.content[:50]}{'...' if len(message.content) > 50 else ''}") print(f"💌 DM from {message.author.display_name}: {message.content[:50]}{'...' if len(message.content) > 50 else ''}")
@@ -150,7 +150,7 @@ async def on_message(message):
# Log the user's DM message # Log the user's DM message
dm_logger.log_user_message(message.author, message, is_bot_message=False) dm_logger.log_user_message(message.author, message, is_bot_message=False)
if await is_miku_addressed(message): if miku_addressed:
prompt = text # No cleanup — keep it raw prompt = text # No cleanup — keep it raw
user_id = str(message.author.id) user_id = str(message.author.id)
@@ -521,6 +521,12 @@ async def on_message(message):
elif is_dm: elif is_dm:
print("💌 DM message - no mood detection (DM mood only changes via auto-rotation)") print("💌 DM message - no mood detection (DM mood only changes via auto-rotation)")
# V2: Track message for autonomous engine (non-blocking, no LLM calls)
# IMPORTANT: Only call this if the message was NOT addressed to Miku
# This prevents autonomous actions from firing when the user is directly talking to Miku
if not miku_addressed:
on_message_event(message)
# Note: Autonomous reactions are now handled by V2 system via on_message_event() # Note: Autonomous reactions are now handled by V2 system via on_message_event()
# Manual Monday test command (only for server messages) # Manual Monday test command (only for server messages)

View File

@@ -265,6 +265,10 @@ class AutonomousEngine:
# --- Decision Logic --- # --- Decision Logic ---
# CRITICAL: If triggered by a message, we should ONLY do join_conversation
# This ensures Miku responds to what's being said, not random autonomous actions
# Exception: Reactions are handled separately and are allowed
# 1. CONVERSATION JOIN (high priority when momentum is high) # 1. CONVERSATION JOIN (high priority when momentum is high)
if self._should_join_conversation(ctx, profile, debug): if self._should_join_conversation(ctx, profile, debug):
if debug: if debug:
@@ -273,6 +277,11 @@ class AutonomousEngine:
# 2. USER ENGAGEMENT (someone interesting appeared) # 2. USER ENGAGEMENT (someone interesting appeared)
if self._should_engage_user(ctx, profile, debug): if self._should_engage_user(ctx, profile, debug):
if triggered_by_message:
# Convert to join_conversation when message-triggered
if debug:
print(f"✅ [V2 Debug] DECISION: join_conversation (engage_user converted due to message trigger)")
return "join_conversation"
if debug: if debug:
print(f"✅ [V2 Debug] DECISION: engage_user") print(f"✅ [V2 Debug] DECISION: engage_user")
return "engage_user" return "engage_user"
@@ -298,13 +307,15 @@ class AutonomousEngine:
return "general" return "general"
# 5. SHARE TWEET (low activity, wants to share something) # 5. SHARE TWEET (low activity, wants to share something)
if self._should_share_content(ctx, profile, debug): # Skip this entirely when triggered by message - would be inappropriate to ignore user's message
if not triggered_by_message and self._should_share_content(ctx, profile, debug):
if debug: if debug:
print(f"✅ [V2 Debug] DECISION: share_tweet") print(f"✅ [V2 Debug] DECISION: share_tweet")
return "share_tweet" return "share_tweet"
# 6. CHANGE PROFILE PICTURE (very rare, once per day) # 6. CHANGE PROFILE PICTURE (very rare, once per day)
if self._should_change_profile_picture(ctx, profile, debug): # Skip this entirely when triggered by message
if not triggered_by_message and self._should_change_profile_picture(ctx, profile, debug):
if debug: if debug:
print(f"✅ [V2 Debug] DECISION: change_profile_picture") print(f"✅ [V2 Debug] DECISION: change_profile_picture")
return "change_profile_picture" return "change_profile_picture"