[WORK] v3: встречи в календарь детерминированно; логирование ответов агента
lint / hygiene (push) Successful in 11s
lint / hygiene (push) Successful in 11s
This commit is contained in:
1 parent
1cd6e38adc
commit
51d994abdc
4 files changed
+119
-3
No files matched your search
+49
-1
@@ -197,6 +197,8 @@ def sync_item(iid):
|
||||
"""Зеркалит задачу в Nextcloud (список «Работа»)."""
|
||||
try:
|
||||
it = store.get(iid)
|
||||
if it and it.get("type") == "встреча":
|
||||
return
|
||||
if it:
|
||||
caldav.put_todo(it, done=(it.get("status") == "done"))
|
||||
else:
|
||||
@@ -239,6 +241,36 @@ def apply_actions(actions):
|
||||
if iid and store.get(iid):
|
||||
store.delete_item(iid)
|
||||
touched.append(iid)
|
||||
elif op == "event":
|
||||
import datetime as _dt
|
||||
start_s = (a.get("start") or "").strip()
|
||||
start = None
|
||||
for fmt in ("%Y-%m-%dT%H:%M", "%Y-%m-%dT%H:%M:%S", "%Y-%m-%d %H:%M",
|
||||
"%d.%m.%Y %H:%M", "%d.%m %H:%M", "%Y-%m-%dT%H:%M:%S%z"):
|
||||
try:
|
||||
start = _dt.datetime.strptime(start_s, fmt)
|
||||
break
|
||||
except Exception:
|
||||
continue
|
||||
if start is None:
|
||||
try:
|
||||
start = _dt.datetime.fromisoformat(start_s)
|
||||
except Exception:
|
||||
start = None
|
||||
if start is None:
|
||||
payload = {"type": "встреча", "partner": a.get("partner") or None, "due": None}
|
||||
iid = store.add_item((a.get("text") or "Встреча").strip(), payload)
|
||||
touched.append(iid)
|
||||
if start:
|
||||
payload = {"type": "встреча", "partner": a.get("partner") or None,
|
||||
"due": start.date().isoformat()}
|
||||
iid = store.add_item((a.get("text") or "Встреча").strip(), payload)
|
||||
end = start + _dt.timedelta(hours=int(a.get("hours") or 1))
|
||||
try:
|
||||
caldav.put_event(store.get(iid), start, end, a.get("place"))
|
||||
except Exception as e:
|
||||
print("caldav event:", e, flush=True)
|
||||
touched.append(iid)
|
||||
for i in touched:
|
||||
sync_item(i)
|
||||
return touched
|
||||
@@ -312,8 +344,24 @@ def handle(text, room, mx):
|
||||
sync_item(iid)
|
||||
return "Задача #%d теперь на %s" % (iid, due.strftime("%d.%m"))
|
||||
|
||||
|
||||
# Встречи разбираем детерминированно, без модели: дата/время + слово-триггер.
|
||||
if any(k in low for k in ("встреча", "созвон", "приезд", "приеду", "демо в", "покажу в", "созвонимся")):
|
||||
start = parse_when(t)
|
||||
if start:
|
||||
payload = {"type": "встреча", "partner": parse.parse_partner(t),
|
||||
"due": start.date().isoformat()}
|
||||
iid = store.add_item(t, payload)
|
||||
end = start + dt.timedelta(hours=1)
|
||||
try:
|
||||
caldav.put_event(store.get(iid), start, end, None)
|
||||
except Exception as e:
|
||||
print("caldav event:", e, flush=True)
|
||||
return ("Встреча #%d: %s — %s. Записал в календарь «Работа»."
|
||||
% (iid, start.strftime("%d.%m в %H:%M"), t[:100]))
|
||||
|
||||
items = store.open_items(20)
|
||||
history = store.recent_messages(8)
|
||||
history = store.recent_messages(4)
|
||||
reply, actions = agent.respond(t, items, history)
|
||||
if reply is None and (not actions or actions[0].get("op") == "error"):
|
||||
p = parse.parse(t)
|
||||
|
||||
Reference in new issue
Block a user