switched from using the bot's local time instead of the message sent time for keyword replacement

This commit is contained in:
agessaman
2025-11-11 09:36:29 -08:00
parent 9ea71d5414
commit 46f04fbbe5
2 changed files with 43 additions and 18 deletions
+22 -9
View File
@@ -8,6 +8,8 @@ import re
import time
import asyncio
from typing import List, Dict, Tuple, Optional, Any
from datetime import datetime
import pytz
from meshcore import EventType
from .models import MeshMessage
@@ -98,15 +100,26 @@ class CommandManager:
try:
connection_info = self.build_enhanced_connection_info(message)
# Format timestamp
if message.timestamp and message.timestamp != 'unknown':
try:
from datetime import datetime
dt = datetime.fromtimestamp(message.timestamp)
time_str = dt.strftime("%H:%M:%S")
except:
time_str = str(message.timestamp)
else:
# Format timestamp - use bot's local time instead of message timestamp
# to avoid issues when sender's clock is wrong
try:
# Get configured timezone or use system timezone
timezone_str = self.bot.config.get('Bot', 'timezone', fallback='')
if timezone_str:
try:
# Use configured timezone
tz = pytz.timezone(timezone_str)
dt = datetime.now(tz)
except pytz.exceptions.UnknownTimeZoneError:
# Fallback to system timezone if configured timezone is invalid
dt = datetime.now()
else:
# Use system timezone
dt = datetime.now()
time_str = dt.strftime("%H:%M:%S")
except:
time_str = "Unknown"
# Format the response with available message data
+21 -9
View File
@@ -6,6 +6,8 @@ Provides common functionality and interface for command implementations
from abc import ABC, abstractmethod
from typing import Optional, List, Dict, Any, Tuple
from datetime import datetime
import pytz
from ..models import MeshMessage
@@ -154,15 +156,25 @@ class BaseCommand(ABC):
return connection_info
def format_timestamp(self, message: MeshMessage) -> str:
"""Format message timestamp for display"""
if message.timestamp and message.timestamp != 'unknown':
try:
from datetime import datetime
dt = datetime.fromtimestamp(message.timestamp)
return dt.strftime("%H:%M:%S")
except:
return str(message.timestamp)
else:
"""Format current bot time for display (not sender's timestamp to avoid clock issues)"""
try:
# Get configured timezone or use system timezone
timezone_str = self.bot.config.get('Bot', 'timezone', fallback='')
if timezone_str:
try:
# Use configured timezone
tz = pytz.timezone(timezone_str)
dt = datetime.now(tz)
except pytz.exceptions.UnknownTimeZoneError:
# Fallback to system timezone if configured timezone is invalid
dt = datetime.now()
else:
# Use system timezone
dt = datetime.now()
return dt.strftime("%H:%M:%S")
except:
return "Unknown"
def format_response(self, message: MeshMessage, response_format: str) -> str: