Spaces:
Sleeping
Sleeping
Upload telegram_bot.py with huggingface_hub
Browse files- telegram_bot.py +24 -9
telegram_bot.py
CHANGED
|
@@ -179,18 +179,33 @@ def _parse_cloud_reminder(text):
|
|
| 179 |
due_ts = now + delta
|
| 180 |
task = re.sub(r"in \d+\s*[\w]+s?", "", body).strip(" .")
|
| 181 |
else:
|
| 182 |
-
|
|
|
|
| 183 |
if m:
|
| 184 |
# "at HH:MM" means the user's wall clock (WAT = UTC+1); server runs UTC.
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
if due_ts is None:
|
| 193 |
-
return "
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
if not task:
|
| 195 |
task = "reminder"
|
| 196 |
db = _init_firestore()
|
|
|
|
| 179 |
due_ts = now + delta
|
| 180 |
task = re.sub(r"in \d+\s*[\w]+s?", "", body).strip(" .")
|
| 181 |
else:
|
| 182 |
+
# Absolute time: "at" optional, colon optional ("at 10:48", "10 48pm", "10:48pm").
|
| 183 |
+
m = re.search(r"(?:\bat\s+)?(\d{1,2})\s*[:.]?\s*(\d{2})\s*(am|pm|a\.m\.|p\.m\.)?\b", body)
|
| 184 |
if m:
|
| 185 |
# "at HH:MM" means the user's wall clock (WAT = UTC+1); server runs UTC.
|
| 186 |
+
hh, mm, ap = int(m.group(1)), int(m.group(2)), (m.group(3) or "")
|
| 187 |
+
if 0 <= hh <= 23 and 0 <= mm <= 59:
|
| 188 |
+
if "p" in ap and hh < 12:
|
| 189 |
+
hh += 12
|
| 190 |
+
if "a" in ap and hh == 12:
|
| 191 |
+
hh = 0
|
| 192 |
+
wat = _dt.datetime.now(_dt.timezone.utc) + _dt.timedelta(hours=1)
|
| 193 |
+
target = wat.replace(hour=hh, minute=mm, second=0, microsecond=0)
|
| 194 |
+
if target.timestamp() <= now + 3600:
|
| 195 |
+
target = target + _dt.timedelta(days=1)
|
| 196 |
+
due_ts = target.timestamp() - 3600
|
| 197 |
+
task = re.sub(r"(?:\bat\s+)?\d{1,2}\s*[:.]?\s*\d{2}\s*(?:am|pm|a\.m\.|p\.m\.)?\b",
|
| 198 |
+
"", body).strip(" .")
|
| 199 |
+
# Strip leftover fragments like "I." from speech-to-text garble.
|
| 200 |
+
task = re.sub(r"\bif\s+something\b", "something", task).strip(" .")
|
| 201 |
+
if due_ts is None and not task:
|
| 202 |
+
return "What should I remind you about, and when, sir?"
|
| 203 |
if due_ts is None:
|
| 204 |
+
return f"Remind you {task} — when, sir? (e.g. in 30 minutes, or at 10:48 PM)"
|
| 205 |
+
if not task:
|
| 206 |
+
when_q = (_dt.datetime.fromtimestamp(due_ts, _dt.timezone.utc)
|
| 207 |
+
+ _dt.timedelta(hours=1)).strftime("%I:%M %p").lstrip("0")
|
| 208 |
+
return f"At {when_q} WAT — remind you of what, sir?"
|
| 209 |
if not task:
|
| 210 |
task = "reminder"
|
| 211 |
db = _init_firestore()
|