()
| 53 | } |
| 54 | |
| 55 | export async function stopBot(): Promise<{ ok: boolean; message: string }> { |
| 56 | const cur = await botStatus(); |
| 57 | if (!cur.running || !cur.pid) { await fs.unlink(pidFilePath()).catch(() => {}); return { ok: false, message: 'Bot is not running.' }; } |
| 58 | try { |
| 59 | process.kill(cur.pid, 'SIGTERM'); |
| 60 | await fs.unlink(pidFilePath()).catch(() => {}); |
| 61 | return { ok: true, message: `Stopped the bot (pid ${cur.pid}).` }; |
| 62 | } catch (e: any) { |
| 63 | return { ok: false, message: `Couldn't stop pid ${cur.pid}: ${e?.message ?? e}` }; |
| 64 | } |
| 65 | } |
no test coverage detected