Fix: Optimize Twitter fetching to avoid Playwright hangs
- Replaced Playwright browser scraping with direct API media extraction - Both fetch_miku_tweets() and fetch_figurine_tweets_latest() now use twscrape's built-in media info - Reduced tweet fetching from 10-15 minutes to ~5 seconds - Eliminated browser timeout/hanging issues - Relaxed autonomous tweet sharing conditions: * Increased message threshold from 10 to 20 per hour * Reduced cooldown from 3600s to 2400s (40 minutes) * Increased energy threshold from 50% to 70% * Added 'silly' and 'flirty' moods to allowed sharing moods This makes both figurine notifications and tweet sharing much more reliable and responsive.
This commit is contained in:
@@ -408,19 +408,23 @@ class AutonomousEngine:
|
||||
|
||||
def _should_share_content(self, ctx: ContextSignals, profile: dict, debug: bool = False) -> bool:
|
||||
"""Decide if Miku should share a tweet/content"""
|
||||
# Quiet period + curious/excited mood
|
||||
quiet_check = ctx.messages_last_hour < 10
|
||||
cooldown_check = ctx.time_since_last_action > 3600
|
||||
# RELAXED CONDITIONS: Made tweet sharing more frequent
|
||||
# Old: quiet_check required < 10 messages, now < 20
|
||||
# Old: cooldown was 3600s (1 hour), now 2400s (40 minutes)
|
||||
# Old: energy threshold was 50%, now 70%
|
||||
quiet_check = ctx.messages_last_hour < 20 # Increased from 10
|
||||
cooldown_check = ctx.time_since_last_action > 2400 # Reduced from 3600
|
||||
energy_roll = random.random()
|
||||
energy_threshold = profile["energy"] * 0.5
|
||||
energy_threshold = profile["energy"] * 0.7 # Increased from 0.5
|
||||
energy_ok = energy_roll < energy_threshold
|
||||
mood_ok = ctx.current_mood in ["curious", "excited", "bubbly", "neutral"]
|
||||
# Added more moods that can share content
|
||||
mood_ok = ctx.current_mood in ["curious", "excited", "bubbly", "neutral", "silly", "flirty"]
|
||||
|
||||
result = quiet_check and cooldown_check and energy_ok and mood_ok
|
||||
|
||||
if debug:
|
||||
logger.debug(f" [Share] msgs_last_hour={ctx.messages_last_hour} < 10? {quiet_check}")
|
||||
logger.debug(f" [Share] cooldown={ctx.time_since_last_action:.0f}s > 3600s? {cooldown_check}")
|
||||
logger.debug(f" [Share] msgs_last_hour={ctx.messages_last_hour} < 20? {quiet_check}")
|
||||
logger.debug(f" [Share] cooldown={ctx.time_since_last_action:.0f}s > 2400s? {cooldown_check}")
|
||||
logger.debug(f" [Share] energy roll={energy_roll:.2f} < {energy_threshold:.2f}? {energy_ok}")
|
||||
logger.debug(f" [Share] mood '{ctx.current_mood}' appropriate? {mood_ok} | Result: {result}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user