chat history with the NPC modal
This commit is contained in:
@@ -12,6 +12,7 @@ import structlog
|
||||
import yaml
|
||||
import os
|
||||
from pathlib import Path
|
||||
from datetime import datetime, timezone
|
||||
|
||||
|
||||
logger = structlog.get_logger(__name__)
|
||||
@@ -61,6 +62,34 @@ def create_app():
|
||||
app.register_blueprint(character_bp)
|
||||
app.register_blueprint(game_bp)
|
||||
|
||||
# Register Jinja filters
|
||||
def format_timestamp(iso_string: str) -> str:
|
||||
"""Convert ISO timestamp to relative time (e.g., '2 mins ago')"""
|
||||
if not iso_string:
|
||||
return ""
|
||||
try:
|
||||
timestamp = datetime.fromisoformat(iso_string.replace('Z', '+00:00'))
|
||||
now = datetime.now(timezone.utc)
|
||||
diff = now - timestamp
|
||||
|
||||
seconds = diff.total_seconds()
|
||||
if seconds < 60:
|
||||
return "Just now"
|
||||
elif seconds < 3600:
|
||||
mins = int(seconds / 60)
|
||||
return f"{mins} min{'s' if mins != 1 else ''} ago"
|
||||
elif seconds < 86400:
|
||||
hours = int(seconds / 3600)
|
||||
return f"{hours} hr{'s' if hours != 1 else ''} ago"
|
||||
else:
|
||||
days = int(seconds / 86400)
|
||||
return f"{days} day{'s' if days != 1 else ''} ago"
|
||||
except Exception as e:
|
||||
logger.warning("timestamp_format_failed", iso_string=iso_string, error=str(e))
|
||||
return iso_string
|
||||
|
||||
app.jinja_env.filters['format_timestamp'] = format_timestamp
|
||||
|
||||
# Register dev blueprint only in development
|
||||
env = os.getenv("FLASK_ENV", "development")
|
||||
if env == "development":
|
||||
|
||||
Reference in New Issue
Block a user