Rebrand and personalize the bot as 'Bartender' - a companion for those who love deeply and feel intensely. Major changes: - Rename package: daemon_boyfriend -> loyal_companion - New default personality: Bartender - wise, steady, non-judgmental - Grief-aware system prompt (no toxic positivity, attachment-informed) - New relationship levels: New Face -> Close Friend progression - Bartender-style mood modifiers (steady presence) - New fact types: attachment_pattern, grief_context, coping_mechanism - Lower mood decay (0.05) for emotional stability - Higher fact extraction rate (0.4) - Bartender pays attention Updated all imports, configs, Docker files, and documentation.
60 lines
2.3 KiB
Python
60 lines
2.3 KiB
Python
"""Conversation and message database models."""
|
|
|
|
from datetime import datetime
|
|
from typing import TYPE_CHECKING
|
|
|
|
from sqlalchemy import BigInteger, Boolean, DateTime, ForeignKey, Integer, String, Text
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from .base import Base, PortableJSON, utc_now
|
|
|
|
if TYPE_CHECKING:
|
|
from .user import User
|
|
|
|
|
|
class Conversation(Base):
|
|
"""A conversation session with a user."""
|
|
|
|
__tablename__ = "conversations"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
user_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="CASCADE"), index=True)
|
|
guild_id: Mapped[int | None] = mapped_column(BigInteger)
|
|
channel_id: Mapped[int | None] = mapped_column(BigInteger, index=True)
|
|
started_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utc_now)
|
|
last_message_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True), default=utc_now, index=True
|
|
)
|
|
message_count: Mapped[int] = mapped_column(Integer, default=0)
|
|
is_active: Mapped[bool] = mapped_column(Boolean, default=True, index=True)
|
|
|
|
# Relationships
|
|
user: Mapped["User"] = relationship(back_populates="conversations")
|
|
messages: Mapped[list["Message"]] = relationship(
|
|
back_populates="conversation",
|
|
cascade="all, delete-orphan",
|
|
order_by="Message.created_at",
|
|
)
|
|
|
|
|
|
class Message(Base):
|
|
"""Individual chat message."""
|
|
|
|
__tablename__ = "messages"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
conversation_id: Mapped[int] = mapped_column(
|
|
ForeignKey("conversations.id", ondelete="CASCADE"), index=True
|
|
)
|
|
user_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="CASCADE"), index=True)
|
|
discord_message_id: Mapped[int | None] = mapped_column(BigInteger)
|
|
role: Mapped[str] = mapped_column(String(20)) # user, assistant, system
|
|
content: Mapped[str] = mapped_column(Text)
|
|
has_images: Mapped[bool] = mapped_column(Boolean, default=False)
|
|
image_urls: Mapped[list[str] | None] = mapped_column(PortableJSON, default=None)
|
|
token_count: Mapped[int | None] = mapped_column(Integer)
|
|
|
|
# Relationships
|
|
conversation: Mapped["Conversation"] = relationship(back_populates="messages")
|
|
user: Mapped["User"] = relationship(back_populates="messages")
|