i quit the wrong week the pick sniffing glue

This commit is contained in:
2026-02-16 13:29:44 -06:00
parent f140f8f75c
commit a395f221cc

View File

@@ -7,6 +7,7 @@ import re
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
from bot.command_registry import register_module from bot.command_registry import register_module
import ai.parser as ai_parser import ai.parser as ai_parser
import pytz
def _get_nearest_scheduled_time(times, user_tz=None): def _get_nearest_scheduled_time(times, user_tz=None):
@@ -14,7 +15,7 @@ def _get_nearest_scheduled_time(times, user_tz=None):
Args: Args:
times: List of time strings like ["08:00", "20:00"] times: List of time strings like ["08:00", "20:00"]
user_tz: pytz timezone object for the user user_tz: pytz timezone object or offset in minutes
Returns the time as HH:MM string, or None if no times provided. Returns the time as HH:MM string, or None if no times provided.
""" """
@@ -25,6 +26,15 @@ def _get_nearest_scheduled_time(times, user_tz=None):
if user_tz is None: if user_tz is None:
# Default to UTC if no timezone provided # Default to UTC if no timezone provided
user_tz = timezone.utc user_tz = timezone.utc
elif isinstance(user_tz, int):
# If user_tz is an offset in minutes, convert to timezone object
# Positive offset means behind UTC, so we need to use Etc/GMT+N
# where N = -offset_minutes/60 (because Etc/GMT+5 means 5 hours behind UTC)
from pytz import timezone as pytz_timezone
offset_hours = -user_tz // 60
user_tz = pytz_timezone(f"Etc/GMT+{offset_hours}")
now = datetime.now(user_tz) now = datetime.now(user_tz)
now_minutes = now.hour * 60 + now.minute now_minutes = now.hour * 60 + now.minute
@@ -99,31 +109,37 @@ def _get_nearest_scheduled_time(times, user_tz=None):
return best_time return best_time
async def _get_user_timezone(bot, user_id): async def _get_user_timezone(message, session, token):
"""Check if user has timezone set, ask for it if not. """Get user's timezone offset. Returns offset_minutes or None if not set.
Returns the timezone string or None if user cancels. Also checks for pending timezone confirmation in session.
""" """
# Check if user has timezone set # Check if there's a pending timezone confirmation
user_data = await bot.api.get_user_data(user_id) pending = session.get("pending_confirmations", {}).get("timezone")
if user_data and user_data.get('timezone'): if pending:
return user_data['timezone'] # User just replied with timezone info
user_response = message.content.strip()
# Ask user for their timezone
await bot.send_dm(user_id, "🕐 I don't have your timezone set yet. Could you please tell me your timezone?\n\n" + # Try to parse common timezone formats
"You can provide it in various formats:\n" + # Format: "UTC-8", "PST", "EST", "-8", "+5:30", etc.
"- Timezone name (e.g., 'America/New_York', 'Europe/London')\n" + offset = _parse_timezone(user_response)
"- UTC offset (e.g., 'UTC+2', '-05:00')\n" + if offset is not None:
"- Common abbreviations (e.g., 'EST', 'PST')\n\n" + # Save to API
"Please reply with your timezone and I'll set it up for you!") resp, status = api_request(
"put", "/api/preferences", token, {"timezone_offset": offset}
# Wait for user response (simplified - in real implementation this would be more complex) )
# For now, we'll just return None to indicate we need to handle this differently if status == 200:
return None # Remove pending confirmation
await bot.send_dm(user_id, "I didn't understand that timezone format. Please say something like:\n" del session["pending_confirmations"]["timezone"]
return offset
# Invalid timezone format
await message.channel.send(
"I didn't understand that timezone format. Please say something like:\n"
'- "UTC-8" or "-8" for Pacific Time\n' '- "UTC-8" or "-8" for Pacific Time\n'
'- "UTC+1" or "+1" for Central European Time\n' '- "UTC+1" or "+1" for Central European Time\n'
'- "PST", "EST", "CST", "MST" for US timezones') '- "PST", "EST", "CST", "MST" for US timezones'
)
return None return None
# Check if user has timezone set in preferences # Check if user has timezone set in preferences