Files
miku-discord/backups/2025-12-07/old-bot-bak-80825/utils/kindness.py
koko210Serve 330cedd9d1 chore: organize backup files into dated directory structure
- Consolidated all .bak.* files from bot/ directory into backups/2025-12-07/
- Moved unused autonomous_wip.py to backups (verified not imported anywhere)
- Relocated old .bot.bak.80825/ backup directory into backups/2025-12-07/old-bot-bak-80825/
- Preserved autonomous_v1_legacy.py as it is still actively used by autonomous.py
- Created new backups/ directory with date-stamped subdirectory for better organization
2025-12-07 23:54:38 +02:00

50 lines
1.7 KiB
Python

# utils/kindness.py
import random
import globals
from utils.llm import query_ollama # Adjust path as needed
async def detect_and_react_to_kindness(message, after_reply=False):
if message.id in globals.kindness_reacted_messages:
return # Already reacted — skip
content = message.content.lower()
emoji = random.choice(globals.HEART_REACTIONS)
# 1. Keyword-based detection
if any(keyword in content for keyword in globals.KINDNESS_KEYWORDS):
try:
await message.add_reaction(emoji)
globals.kindness_reacted_messages.add(message.id)
message.kindness_reacted = True # Mark as done
print("✅ Kindness detected via keywords. Reacted immediately.")
except Exception as e:
print(f"⚠️ Error adding reaction: {e}")
return
# 2. If not after_reply, defer model-based check
if not after_reply:
print("🗝️ No kindness via keywords. Deferring...")
return
# 3. Model-based detection
try:
prompt = (
"The following message was sent to Miku the bot. "
"Does it sound like the user is being explicitly kind or affectionate toward Miku? "
"Answer with 'yes' or 'no' only.\n\n"
f"Message: \"{message.content}\""
)
result = await query_ollama(prompt, user_id="kindness-check")
if result.strip().lower().startswith("yes"):
await message.add_reaction(emoji)
globals.kindness_reacted_messages.add(message.id)
print("✅ Kindness detected via model. Reacted.")
else:
print("🧊 No kindness detected.")
except Exception as e:
print(f"⚠️ Error during kindness analysis: {e}")