Files
doge_cogs/doge_alignment/core/messages.py
T
Ziad ArafatandClaude Opus 5.5 027f11c90f doge_alignment: server baseline, per-person time zones, profile hints
Guesses now see what's normal on the server: a weekly cached baseline from
24 random moments in the public channels (per-regular style numbers, message
shares, and a model-written culture summary from anonymised conversations),
and how the person compares with the regulars. `alignment baseline` rebuilds
and shows it; ALIGNMENT_BASELINE=off turns it off.

Each person's time zone comes from aikaterna's timezone cog (read from its
Config); Mountain Time otherwise. The dossier adds nickname, custom status
and roles, since bots can't read the About me bio.

scripts/experiments holds the harnesses and results: the baseline moved
Chaotic Neutral from 9/10 to 8/10; per-axis scores didn't repeat between
identical asks, so relative ranking of scores was dropped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GUebqhE8dK19vyn4Ct5g1L
2026-11-06 18:23:15 -07:00

51 lines
1.4 KiB
Python

"""Chat messages as plain data, for conversations and activity stats.
Front ends convert their own message objects into :class:`Message`. Times are
UTC; Discord ids carry their creation time (:func:`snowflake_time`).
"""
from dataclasses import dataclass
from datetime import UTC, datetime
DISCORD_EPOCH_MS = 1_420_070_400_000
def snowflake_time(snowflake: str | int) -> datetime:
"""Return when a Discord id was created (UTC)."""
ms = (int(snowflake) >> 22) + DISCORD_EPOCH_MS
return datetime.fromtimestamp(ms / 1000, tz=UTC)
def snowflake_at(when: datetime) -> int:
"""Return the smallest Discord id created at ``when``."""
ms = int(when.timestamp() * 1000) - DISCORD_EPOCH_MS
return max(ms, 0) << 22
@dataclass(frozen=True)
class Message:
"""One chat message."""
id: str
author_id: str
author_name: str
channel_id: str
channel_name: str
created: datetime
content: str
reply_to: str | None = None
edited: bool = False
attachments: int = 0
mentions: int = 0
bot: bool = False
def by_time(
messages: "list[Message] | tuple[Message, ...]",
) -> tuple[Message, ...]:
"""Return ``messages`` oldest first, without duplicate ids."""
unique = {m.id: m for m in messages}
return tuple(
sorted(unique.values(), key=lambda m: (m.created, int(m.id)))
)