發佈 0.2.0:改名 telegram-bot,新增 Claude Code 引擎(新增 bot 時可選 Codex / Claude),start 自動從 0.1.x 遷移
This commit is contained in:
+25
-15
@@ -1,24 +1,25 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
// telegram-codex-bot CLI:start 把 web 控制台掛上 pm2;
|
||||
// bot 的新增(token、工作目錄、權限)與啟停全部在網頁控制台操作。
|
||||
// telegram-bot CLI:start 把 web 控制台掛上 pm2;
|
||||
// bot 的新增(引擎、token、工作目錄、權限)與啟停全部在網頁控制台操作。
|
||||
const { execSync, spawn } = require('child_process');
|
||||
const pm2 = require('../src/pm2util');
|
||||
|
||||
const HELP = `telegram-codex-bot — 用 Telegram 操控本機 Codex CLI 的 bot
|
||||
const HELP = `telegram-bot — 用 Telegram 操控本機 AI CLI(Codex / Claude Code)的 bot
|
||||
|
||||
用法:
|
||||
telegram-codex-bot start 檢查環境(codex/pm2/git)並啟動 web 控制台(掛 pm2)
|
||||
telegram-codex-bot start --port 3799 指定控制台 port(會記住)
|
||||
telegram-codex-bot doctor 只做環境檢查
|
||||
telegram-codex-bot stop 停止控制台(bot 不受影響)
|
||||
telegram-codex-bot restart 重啟控制台
|
||||
telegram-codex-bot delete 從 pm2 移除控制台
|
||||
telegram-codex-bot status 顯示控制台與所有 bot 狀態
|
||||
telegram-codex-bot logs [--name <bot>] 跟看 log(不帶 --name 看控制台)
|
||||
telegram-codex-bot web 前景執行控制台(不經 pm2,除錯用)
|
||||
telegram-bot start 檢查環境(codex/claude/pm2/git)並啟動 web 控制台(掛 pm2)
|
||||
telegram-bot start --port 3799 指定控制台 port(會記住)
|
||||
telegram-bot doctor 只做環境檢查
|
||||
telegram-bot stop 停止控制台(bot 不受影響)
|
||||
telegram-bot restart 重啟控制台
|
||||
telegram-bot delete 從 pm2 移除控制台
|
||||
telegram-bot status 顯示控制台與所有 bot 狀態
|
||||
telegram-bot logs [--name <bot>] 跟看 log(不帶 --name 看控制台)
|
||||
telegram-bot web 前景執行控制台(不經 pm2,除錯用)
|
||||
|
||||
bot 的新增 / token / 工作目錄 / 允許名單 / 啟停,都在控制台網頁的「🤖 Bot 管理」分頁設定。
|
||||
bot 的新增 / 引擎(Codex 或 Claude)/ token / 工作目錄 / 啟停,都在控制台網頁的「🤖 Bot 管理」分頁設定。
|
||||
短別名:tgbot
|
||||
`;
|
||||
|
||||
function parseArgs(argv) {
|
||||
@@ -51,7 +52,7 @@ function requirePm2() {
|
||||
}
|
||||
|
||||
async function cmdStart(args) {
|
||||
// 環境檢查:codex CLI / 登入 / pm2 / git
|
||||
// 環境檢查:codex / claude(至少一個)/ 登入 / pm2 / git
|
||||
if (!args.flags['skip-checks']) {
|
||||
const { runChecks, printChecks, hasBlocker } = require('../src/doctor');
|
||||
const checks = runChecks();
|
||||
@@ -62,6 +63,13 @@ async function cmdStart(args) {
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
requirePm2();
|
||||
// 從 telegram-codex-bot(0.1.x)升級:搬家目錄、把 bot 程序切到新套件
|
||||
const { migrateLegacy } = require('../src/migrate');
|
||||
const notes = await migrateLegacy();
|
||||
for (const n of notes) console.log(n);
|
||||
if (notes.length) console.log('');
|
||||
|
||||
if (args.flags.port) {
|
||||
const settings = pm2.loadConsoleSettings();
|
||||
settings.port = Number(args.flags.port);
|
||||
@@ -76,7 +84,7 @@ async function cmdStart(args) {
|
||||
console.log(`✅ 控制台${alreadyRunning ? '已在執行' : '已掛上 pm2'}(${pm2.CONSOLE_NAME})`);
|
||||
console.log('');
|
||||
console.log(`📊 控制台:${url}`);
|
||||
console.log(' 在「🤖 Bot 管理」分頁新增 bot(token、工作目錄、權限都在裡面設定)。');
|
||||
console.log(' 在「🤖 Bot 管理」分頁新增 bot(選 Codex 或 Claude 引擎,token、工作目錄都在裡面設定)。');
|
||||
}
|
||||
|
||||
async function cmdConsoleAction(action) {
|
||||
@@ -96,6 +104,7 @@ async function cmdStatus() {
|
||||
const settings = pm2.loadConsoleSettings();
|
||||
const consoleProc = list.find((p) => p.name === pm2.CONSOLE_NAME);
|
||||
console.log(`控制台(${pm2.CONSOLE_NAME}):${consoleProc ? consoleProc.pm2_env?.status : '未啟動'} ${pm2.consoleUrl(settings)}`);
|
||||
console.log(`設定目錄:${pm2.TGBOT_HOME}`);
|
||||
|
||||
const bots = await listBots();
|
||||
if (bots.length === 0) {
|
||||
@@ -104,6 +113,7 @@ async function cmdStatus() {
|
||||
}
|
||||
console.table(bots.map((b) => ({
|
||||
name: b.name,
|
||||
engine: b.engine,
|
||||
status: b.status,
|
||||
workDir: b.workDir,
|
||||
sandbox: b.sandbox,
|
||||
|
||||
Reference in New Issue
Block a user