local lang = jarvis.context.language local userprofile = jarvis.system.env("USERPROFILE") or "C:\\Users\\Public" local config_path = userprofile .. "\\Documents\\jarvis-games.json" if not jarvis.fs.exists(config_path) then local sample = [[[ {"name": "dota", "aliases": ["доту", "доту 2", "dota 2"], "steam_appid": 570}, {"name": "cs2", "aliases": ["кс", "контру", "контр страйк"], "steam_appid": 730}, {"name": "elden ring", "aliases": ["элден", "элден ринг"], "steam_appid": 1245620}, {"name": "witcher 3", "aliases": ["ведьмак", "ведьмака 3"], "steam_appid": 292030}, {"name": "factorio", "aliases": ["факторио"], "steam_appid": 427520}, {"name": "minecraft", "aliases": ["майнкрафт", "майн"], "path": "C:\\Program Files (x86)\\Minecraft Launcher\\MinecraftLauncher.exe"}, {"name": "fortnite", "aliases": ["фортнайт"], "epic_uri": "com.epicgames.launcher://apps/Fortnite?action=launch&silent=true"} ] ]] jarvis.fs.write(config_path, sample) jarvis.system.notify( lang == "ru" and "Игры" or "Games", lang == "ru" and "Создан шаблон ~/Documents/jarvis-games.json — добавь свои игры и повтори" or "Template at Documents/jarvis-games.json — edit and retry" ) jarvis.system.open(config_path) jarvis.audio.play_not_found() return { chain = false } end local content = jarvis.fs.read(config_path) local entries = {} local cursor = 1 while true do local s, e, block = content:find("({[^{}]+})", cursor) if not s then break end cursor = e + 1 local name = block:match('"name"%s*:%s*"([^"]+)"') if name then local entry = { name = name, name_lower = name:lower(), aliases = {} } for alias in block:gmatch('"([^"]+)"') do entry.aliases[#entry.aliases + 1] = alias:lower() end entry.steam_appid = tonumber(block:match('"steam_appid"%s*:%s*(%d+)')) entry.path = block:match('"path"%s*:%s*"([^"]+)"') entry.epic_uri = block:match('"epic_uri"%s*:%s*"([^"]+)"') table.insert(entries, entry) end end if #entries == 0 then jarvis.system.notify("Games", lang == "ru" and "Пусто в конфиге" or "Empty config") jarvis.audio.play_not_found() return { chain = false } end local phrase = (jarvis.context.phrase or ""):lower() local triggers = { "запусти игру", "включи игру", "хочу поиграть", "поиграем", "запусти", "включи", "launch game", "play game", "launch", "запусти гру", "увімкни гру", } local query = phrase for _, t in ipairs(triggers) do local s, e = string.find(query, t, 1, true) if s == 1 then query = query:sub(e + 1) break end end query = query:gsub("^%s+", ""):gsub("%s+$", "") local function name_matches(e, q) if e.name_lower == q then return true end if string.find(e.name_lower, q, 1, true) then return true end for _, a in ipairs(e.aliases) do if a == q or string.find(q, a, 1, true) then return true end end return false end local match for _, e in ipairs(entries) do if name_matches(e, query) then match = e; break end end if not match then jarvis.system.notify("Games", (lang == "ru" and "Не нашёл: " or "Not found: ") .. query) jarvis.audio.play_not_found() return { chain = false } end local launched = false if match.steam_appid then jarvis.system.open("steam://rungameid/" .. tostring(match.steam_appid)) launched = true elseif match.epic_uri then jarvis.system.open(match.epic_uri) launched = true elseif match.path and jarvis.fs.exists(match.path) then jarvis.system.exec(string.format('start "" "%s"', match.path)) launched = true end if launched then jarvis.system.notify(lang == "ru" and "Запускаю" or "Launching", match.name) jarvis.speak((lang == "ru" and "Запускаю " or "Launching ") .. match.name .. ".", { lang = lang }) jarvis.audio.play_ok() else jarvis.system.notify("Games", (lang == "ru" and "Не настроен запуск: " or "No launch info: ") .. match.name) jarvis.audio.play_error() end return { chain = false }