(cwd: string)
| 38 | } |
| 39 | |
| 40 | export async function startBot(cwd: string): Promise<{ ok: boolean; message: string }> { |
| 41 | const cur = await botStatus(); |
| 42 | if (cur.running) return { ok: false, message: `Bot already running (pid ${cur.pid}).` }; |
| 43 | try { |
| 44 | await fs.mkdir(QODEX_HOME, { recursive: true }); |
| 45 | const child = spawn(resolveCliPath(), ['bot'], { cwd, detached: true, stdio: 'ignore' }); |
| 46 | child.unref(); |
| 47 | if (!child.pid) return { ok: false, message: 'Could not spawn the bot process.' }; |
| 48 | await fs.writeFile(pidFilePath(), String(child.pid), 'utf-8'); |
| 49 | return { ok: true, message: `Bot started (pid ${child.pid}). It needs a token + allowlist in config to actually connect.` }; |
| 50 | } catch (e: any) { |
| 51 | return { ok: false, message: `Failed to start bot: ${e?.message ?? e}` }; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | export async function stopBot(): Promise<{ ok: boolean; message: string }> { |
| 56 | const cur = await botStatus(); |
no test coverage detected