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 bot.command_registry import register_module
import ai.parser as ai_parser
import pytz
def _get_nearest_scheduled_time(times, user_tz=None):
@@ -14,7 +15,7 @@ def _get_nearest_scheduled_time(times, user_tz=None):
Args:
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.
"""
@@ -25,6 +26,15 @@ def _get_nearest_scheduled_time(times, user_tz=None):
if user_tz is None:
# Default to UTC if no timezone provided
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_minutes = now.hour * 60 + now.minute
@@ -99,31 +109,37 @@ def _get_nearest_scheduled_time(times, user_tz=None):
return best_time
async def _get_user_timezone(bot, user_id):
"""Check if user has timezone set, ask for it if not.
async def _get_user_timezone(message, session, token):
"""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
user_data = await bot.api.get_user_data(user_id)
if user_data and user_data.get('timezone'):
return user_data['timezone']
# 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" +
"You can provide it in various formats:\n" +
"- Timezone name (e.g., 'America/New_York', 'Europe/London')\n" +
"- UTC offset (e.g., 'UTC+2', '-05:00')\n" +
"- Common abbreviations (e.g., 'EST', 'PST')\n\n" +
"Please reply with your timezone and I'll set it up for you!")
# 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
return None
await bot.send_dm(user_id, "I didn't understand that timezone format. Please say something like:\n"
# Check if there's a pending timezone confirmation
pending = session.get("pending_confirmations", {}).get("timezone")
if pending:
# User just replied with timezone info
user_response = message.content.strip()
# Try to parse common timezone formats
# Format: "UTC-8", "PST", "EST", "-8", "+5:30", etc.
offset = _parse_timezone(user_response)
if offset is not None:
# Save to API
resp, status = api_request(
"put", "/api/preferences", token, {"timezone_offset": offset}
)
if status == 200:
# Remove pending confirmation
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+1" or "+1" for Central European Time\n'
'- "PST", "EST", "CST", "MST" for US timezones')
'- "PST", "EST", "CST", "MST" for US timezones'
)
return None
# Check if user has timezone set in preferences