feat(chat): implement sleep pressure and insomnia system

This commit introduces a new sleep pressure and insomnia system to simulate more realistic character behavior.

Key features include:
- **Sleep Pressure**: A new metric that accumulates with each action the bot takes and decreases during scheduled sleep times.
- **Insomnia Mechanic**: When a sleep period begins, the system checks the current sleep pressure. Low pressure can lead to a higher chance of "insomnia," causing the bot to stay awake. There is also a small chance for random insomnia.
- **Insomnia State**: During insomnia, the bot enters a special state for a configurable duration. It can trigger unique proactive thoughts related to being unable to sleep, and its mood is adjusted accordingly.
- **Configuration**: All parameters, such as insomnia probability, duration, and pressure thresholds, are fully configurable.
This commit is contained in:
minecraft1024a
2025-08-27 21:02:21 +08:00
parent ff1007049d
commit ecf2df27fa
9 changed files with 231 additions and 28 deletions

View File

@@ -9,6 +9,7 @@ from src.chat.chat_loop.hfc_utils import CycleDetail
if TYPE_CHECKING:
from .wakeup_manager import WakeUpManager
from .energy_manager import EnergyManager
class HfcContext:
def __init__(self, chat_id: str):
@@ -40,6 +41,12 @@ class HfcContext:
self.loop_mode = ChatMode.NORMAL
self.energy_value = 5.0
self.sleep_pressure = 0.0
self.was_sleeping = False # 用于检测睡眠状态的切换
# 失眠状态
self.is_in_insomnia: bool = False
self.insomnia_end_time: float = 0.0
self.last_message_time = time.time()
self.last_read_time = time.time() - 10
@@ -53,4 +60,5 @@ class HfcContext:
self.current_cycle_detail: Optional[CycleDetail] = None
# 唤醒度管理器 - 延迟初始化以避免循环导入
self.wakeup_manager: Optional['WakeUpManager'] = None
self.wakeup_manager: Optional['WakeUpManager'] = None
self.energy_manager: Optional['EnergyManager'] = None