Continue AI features and improve protocol support

This commit is contained in:
2026-02-15 16:57:32 +00:00
parent 2d3b8fdac6
commit 85e97e895d
62 changed files with 5472 additions and 441 deletions

View File

@@ -2,13 +2,26 @@ from asgiref.sync import sync_to_async
from django.utils import timezone
def messages_to_string(messages: list):
def messages_to_string(messages: list, author_rewrites: dict | None = None):
"""
Converts message objects to a formatted string, showing custom_author if set.
"""
author_rewrites = {
str(key).strip().upper(): str(value)
for key, value in (author_rewrites or {}).items()
}
def _author_label(message):
author = (
message.custom_author
if message.custom_author
else message.session.identifier.person.name
)
mapped = author_rewrites.get(str(author).strip().upper())
return mapped if mapped else author
message_texts = [
f"[{msg.ts}] <{msg.custom_author if msg.custom_author else msg.session.identifier.person.name}> {msg.text}"
for msg in messages
f"[{msg.ts}] <{_author_label(msg)}> {msg.text}" for msg in messages
]
return "\n".join(message_texts)