78 lines
2.5 KiB
Lua
78 lines
2.5 KiB
Lua
|
|
-- "Добавь встречу завтра в 15:00 обсудить проект"
|
||
|
|
-- Heuristic parsing: extracts time + body, defaults to tomorrow.
|
||
|
|
local phrase = (jarvis.context.phrase or "")
|
||
|
|
local body = jarvis.text.strip_trigger(phrase:lower(), {
|
||
|
|
"добавь встречу",
|
||
|
|
"создай событие",
|
||
|
|
"создай встречу",
|
||
|
|
"запиши встречу",
|
||
|
|
"новая встреча",
|
||
|
|
"add meeting",
|
||
|
|
"create event",
|
||
|
|
})
|
||
|
|
body = body:gsub("^[%s,:%.]+", ""):gsub("%s+$", "")
|
||
|
|
|
||
|
|
if body == "" then
|
||
|
|
return jarvis.cmd.error("Опишите встречу.")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- Find time HH:MM or "в HH"
|
||
|
|
local h, m = body:match("(%d%d?)[:%-%s](%d%d)")
|
||
|
|
if not h then
|
||
|
|
h = body:match("в%s+(%d%d?)")
|
||
|
|
m = "00"
|
||
|
|
end
|
||
|
|
local hh = tonumber(h) or 9
|
||
|
|
local mm = tonumber(m) or 0
|
||
|
|
|
||
|
|
-- Date: "сегодня" / "завтра" / default to tomorrow
|
||
|
|
local today = jarvis.context.time
|
||
|
|
local year, month, day = today.year, today.month, today.day
|
||
|
|
if body:find("сегодня") then
|
||
|
|
-- leave as-is
|
||
|
|
elseif body:find("послезавтра") then
|
||
|
|
day = day + 2
|
||
|
|
else
|
||
|
|
-- default tomorrow
|
||
|
|
day = day + 1
|
||
|
|
end
|
||
|
|
|
||
|
|
-- ICS uses UTC if Z suffix or local with TZID. We'll use local naive.
|
||
|
|
local dt_start = string.format("%04d%02d%02dT%02d%02d00", year, month, day, hh, mm)
|
||
|
|
local dt_end = string.format("%04d%02d%02dT%02d%02d00", year, month, day, hh + 1, mm)
|
||
|
|
local now_stamp = string.format("%04d%02d%02dT%02d%02d00",
|
||
|
|
today.year, today.month, today.day, today.hour, today.minute)
|
||
|
|
|
||
|
|
-- Clean summary (strip the time tokens)
|
||
|
|
local summary = body:gsub("%d%d?[:%-%s]%d%d", ""):gsub("в%s+%d%d?", "")
|
||
|
|
:gsub("сегодня", ""):gsub("послезавтра", ""):gsub("завтра", "")
|
||
|
|
:gsub("^[%s,]+", ""):gsub("%s+$", "")
|
||
|
|
if summary == "" then summary = "Встреча" end
|
||
|
|
|
||
|
|
local uid = string.format("jarvis-%s-%d", now_stamp, math.random(1000, 9999))
|
||
|
|
local ics = string.format(
|
||
|
|
[[BEGIN:VCALENDAR
|
||
|
|
VERSION:2.0
|
||
|
|
PRODID:-//J.A.R.V.I.S.//EN
|
||
|
|
BEGIN:VEVENT
|
||
|
|
UID:%s
|
||
|
|
DTSTAMP:%s
|
||
|
|
DTSTART:%s
|
||
|
|
DTEND:%s
|
||
|
|
SUMMARY:%s
|
||
|
|
END:VEVENT
|
||
|
|
END:VCALENDAR]],
|
||
|
|
uid, now_stamp, dt_start, dt_end, summary
|
||
|
|
)
|
||
|
|
|
||
|
|
local userprofile = jarvis.system.env("USERPROFILE") or "C:\\Users\\Public"
|
||
|
|
local dir = userprofile .. "\\Documents\\jarvis-events"
|
||
|
|
jarvis.fs.mkdir(dir)
|
||
|
|
local path = dir .. "\\event-" .. now_stamp .. ".ics"
|
||
|
|
jarvis.fs.write(path, ics)
|
||
|
|
|
||
|
|
-- Open via default handler (Outlook / Mail).
|
||
|
|
jarvis.system.open(path)
|
||
|
|
|
||
|
|
return jarvis.cmd.ok(string.format("Встреча создана: %s в %02d:%02d.", summary, hh, mm))
|