56 lines
1.9 KiB
Lua
56 lines
1.9 KiB
Lua
|
|
-- Voice-controlled Outlook: report number of unread emails in default Inbox.
|
||
|
|
-- The PowerShell helper talks to Outlook via COM; if Outlook is closed or
|
||
|
|
-- COM fails we degrade gracefully with an explanatory message.
|
||
|
|
|
||
|
|
local lang = jarvis.context.language
|
||
|
|
local helper = jarvis.context.command_path .. "\\_outlook.ps1"
|
||
|
|
local cmd = string.format(
|
||
|
|
'powershell -NoProfile -ExecutionPolicy Bypass -File "%s" -Action unread_count',
|
||
|
|
helper
|
||
|
|
)
|
||
|
|
|
||
|
|
local res = jarvis.system.exec(cmd)
|
||
|
|
local out = (res.stdout or ""):gsub("\r", "")
|
||
|
|
|
||
|
|
if not res.success or out == "" then
|
||
|
|
jarvis.log("error", "outlook unread_count exec failed: " .. tostring(res.stderr))
|
||
|
|
return jarvis.cmd.error(lang == "ru"
|
||
|
|
and "Outlook недоступен — запусти Outlook сначала."
|
||
|
|
or "Outlook is unavailable — start Outlook first.")
|
||
|
|
end
|
||
|
|
|
||
|
|
local first_line, rest = out:match("^([^\n]*)\n?(.*)$")
|
||
|
|
first_line = first_line or ""
|
||
|
|
|
||
|
|
if first_line:sub(1, 3) == "ERR" then
|
||
|
|
jarvis.log("warn", "outlook unread_count: " .. first_line)
|
||
|
|
return jarvis.cmd.error(lang == "ru"
|
||
|
|
and "Outlook недоступен — запусти Outlook сначала."
|
||
|
|
or "Outlook is unavailable — start Outlook first.")
|
||
|
|
end
|
||
|
|
|
||
|
|
local count_str = (rest or ""):match("(%d+)") or "0"
|
||
|
|
local count = tonumber(count_str) or 0
|
||
|
|
|
||
|
|
local speech
|
||
|
|
if lang == "ru" then
|
||
|
|
if count == 0 then
|
||
|
|
speech = "Непрочитанных писем нет."
|
||
|
|
elseif count == 1 then
|
||
|
|
speech = "Одно непрочитанное письмо."
|
||
|
|
else
|
||
|
|
speech = string.format("Непрочитанных писем: %d.", count)
|
||
|
|
end
|
||
|
|
else
|
||
|
|
if count == 0 then
|
||
|
|
speech = "No unread emails."
|
||
|
|
elseif count == 1 then
|
||
|
|
speech = "One unread email."
|
||
|
|
else
|
||
|
|
speech = string.format("You have %d unread emails.", count)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
jarvis.system.notify(lang == "ru" and "Outlook" or "Outlook", speech)
|
||
|
|
return jarvis.cmd.ok(speech)
|