- Created new logging infrastructure with per-component filtering - Added 6 log levels: DEBUG, INFO, API, WARNING, ERROR, CRITICAL - Implemented non-hierarchical level control (any combination can be enabled) - Migrated 917 print() statements across 31 files to structured logging - Created web UI (system.html) for runtime configuration with dark theme - Added global level controls to enable/disable levels across all components - Added timestamp format control (off/time/date/datetime options) - Implemented log rotation (10MB per file, 5 backups) - Added API endpoints for dynamic log configuration - Configured HTTP request logging with filtering via api.requests component - Intercepted APScheduler logs with proper formatting - Fixed persistence paths to use /app/memory for Docker volume compatibility - Fixed checkbox display bug in web UI (enabled_levels now properly shown) - Changed System Settings button to open in same tab instead of new window Components: bot, api, api.requests, autonomous, persona, vision, llm, conversation, mood, dm, scheduled, gpu, media, server, commands, sentiment, core, apscheduler All settings persist across container restarts via JSON config.
53 lines
1.9 KiB
Python
53 lines
1.9 KiB
Python
# utils/kindness.py
|
|
|
|
import random
|
|
import globals
|
|
from utils.llm import query_llama # Adjust path as needed
|
|
from utils.logger import get_logger
|
|
|
|
logger = get_logger('bot')
|
|
|
|
|
|
async def detect_and_react_to_kindness(message, after_reply=False, server_context=None):
|
|
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
|
|
logger.info("Kindness detected via keywords. Reacted immediately.")
|
|
except Exception as e:
|
|
logger.error(f"Error adding reaction: {e}")
|
|
return
|
|
|
|
# 2. If not after_reply, defer model-based check
|
|
if not after_reply:
|
|
logger.debug("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_llama(prompt, user_id="kindness-check", guild_id=None, response_type="dm_response")
|
|
|
|
if result.strip().lower().startswith("yes"):
|
|
await message.add_reaction(emoji)
|
|
globals.kindness_reacted_messages.add(message.id)
|
|
logger.info("Kindness detected via model. Reacted.")
|
|
else:
|
|
logger.debug("No kindness detected.")
|
|
except Exception as e:
|
|
logger.error(f"Error during kindness analysis: {e}")
|