diff --git a/write-server/src/lib/bot/handlers.ts b/write-server/src/lib/bot/handlers.ts index 6fdc7a08..55bdd56c 100644 --- a/write-server/src/lib/bot/handlers.ts +++ b/write-server/src/lib/bot/handlers.ts @@ -97,21 +97,20 @@ handlers.start = async (chatId) => { await sendMain(chatId, [ `👋 欢迎使用写作后台!`, ``, - `📝 功能菜单:`, - `├─ /new - 新建文章`, - `├─ /edit - 编辑文章`, - `├─ /list - 文章列表`, - `├─ /deploy - 部署博客`, - `└─ /status - 服务器状态`, + `📝 快速开始:`, + `├─ /new 标题 - 新建文章`, + `├─ /edit slug - 编辑文章`, + `└─ /list - 查看文章列表`, + ``, + `🔗 友链 & 订阅:`, + `├─ /links - 友链管理`, + `└─ /feeds - 订阅管理`, ``, `🌐 访问地址:`, `├─ 📊 后台管理:https://post.usj.cc`, `└─ 🌍 博客首页:https://usj.cc`, ``, - `💡 提示:`, - `• 使用 /new 开始写作`, - `• 发送文字直接创建草稿`, - `• 发送语音自动转文字`, + `💡 帮助:输入 /help 查看所有命令`, ``, `🎯 开始写作吧!`, ].join("\n")); @@ -122,25 +121,6 @@ handlers.start = async (chatId) => { }); }; -handlers.stop = async (chatId) => { hugo.stop(); await sendMain(chatId, "⚡ Hugo 已停止。"); }; - -handlers.status = async (chatId) => { - const s = hugo.status(); - const statusEmoji = s.running ? "✅" : s.starting ? "⏳" : "⏸"; - const statusText = s.running ? "运行中" : s.starting ? "启动中..." : "已停止"; - - const msg = [ - `📊 服务器状态`, - ``, - `🖥️ Hugo 服务:`, - `├─ 状态:${statusEmoji} ${statusText}`, - `└─ 地址:https://post.usj.cc`, - ``, - s.running ? `🟢 服务正常运行中` : `🔴 服务未运行`, - ].join("\n"); - - await sendMain(chatId, msg); -}; handlers.ip = async (chatId) => { await sendMain(chatId, [ @@ -151,95 +131,69 @@ handlers.ip = async (chatId) => { ].join("\n")); }; -handlers.shutdown = async (chatId) => { - await tg("sendMessage", { - chat_id: chatId, - text: "⚠️ 确认关机?\n\n电脑将在确认后 10 秒关机。", - parse_mode: "HTML", - reply_markup: { - inline_keyboard: [[ - { text: "✅ 确认关机", callback_data: "confirm_shutdown" }, - { text: "❌ 取消", callback_data: "cancel_shutdown" }, - ]], - }, - }); -}; -handlers.confirm_shutdown = async (chatId) => { - await sendMessage(chatId, "⏻ 电脑将在 10 秒后关机..."); - const { exec } = await import("child_process"); - exec("shutdown /s /t 10", (err) => { - if (err) console.error("[shutdown]", err.message); - }); -}; -handlers.cancel_shutdown = async (chatId) => { - const { exec } = await import("child_process"); - exec("shutdown /a", () => {}); - await sendMain(chatId, "已取消关机。"); -}; -handlers.reboot = async (chatId) => { - await tg("sendMessage", { - chat_id: chatId, - text: "⚠️ 确认重启?\n\n电脑将在确认后 10 秒重启。", - parse_mode: "HTML", - reply_markup: { - inline_keyboard: [[ - { text: "✅ 确认重启", callback_data: "confirm_reboot" }, - { text: "❌ 取消", callback_data: "cancel_reboot" }, - ]], - }, - }); -}; -handlers.confirm_reboot = async (chatId) => { - await sendMessage(chatId, "🔄 电脑将在 10 秒后重启..."); - const { exec } = await import("child_process"); - exec("shutdown /r /t 10", (err) => { - if (err) console.error("[reboot]", err.message); - }); -}; -handlers.cancel_reboot = async (chatId) => { - const { exec } = await import("child_process"); - exec("shutdown /a", () => {}); - await sendMain(chatId, "已取消重启。"); -}; handlers.help = async (chatId) => { if (hasSession(chatId)) { - await sendWrite(chatId, - "✍ 写作中\n\n" + - "/publish 保存 /draft 草稿 /deploy 部署\n" + - "/preview 预览 /undo 撤销 /cancel 取消\n" + - "/title 标题 /categories 分类 /tags 标签\n\n" + - "直接发消息追加正文,发照片追加图片" - ); + await sendWrite(chatId, [ + `✍ 写作模式`, + ``, + `📝 编辑命令:`, + `├─ /publish - 保存并发布`, + `├─ /draft - 保存草稿`, + `├─ /deploy - 部署到服务器`, + `├─ /preview - 预览文章`, + `└─ /undo - 撤销最后一段`, + ``, + `⚙️ 设置命令:`, + `├─ /title 标题 - 设置标题`, + `├─ /categories 分类 - 设置分类`, + `├─ /tags 标签 - 设置标签`, + `└─ /author 作者 - 设置作者`, + ``, + `💡 提示:`, + `• 直接发送文字追加到正文`, + `• 发送图片添加到文章`, + `• 发送语音自动转文字`, + `• 输入 /cancel 取消写作`, + ].join("\n")); } else { - await sendMain(chatId, - "🤖 WriteBot 命令\n\n" + - "📝 文章\n" + - "/new 标题 — 新建\n" + - "/edit slug — 编辑\n" + - "/delete slug — 删除\n" + - "/list — 文章列表\n\n" + - "🔗 友链\n" + - "/links — 列表\n" + - "/link_add url 名称 — 添加\n" + - "/link_edit url — 编辑\n" + - "/link_del url — 删除\n" + - "/link_toggle url — 显示/隐藏\n\n" + - "📡 订阅\n" + - "/feeds — 列表\n" + - "/feed_add url — 添加\n" + - "/feed_edit url — 编辑\n" + - "/feed_del url — 删除\n" + - "/feed_health — 健康检查\n\n" + - "📰 /read — 友链最新文章\n" + - "📊 /stats — 网站数据\n\n" + - "⏻ /shutdown — 关机 🔄 /reboot — 重启" - ); + await sendMain(chatId, [ + `🤖 WriteBot 命令指南`, + ``, + `📝 文章管理:`, + `├─ /new 标题 - 新建文章`, + `├─ /edit slug - 编辑文章`, + `├─ /delete slug - 删除文章`, + `└─ /list - 文章列表`, + ``, + `🔗 友链管理:`, + `├─ /links - 查看友链列表`, + `├─ /link_add url 名称 - 添加友链`, + `├─ /link_edit url - 编辑友链`, + `├─ /link_del url - 删除友链`, + `└─ /link_toggle url - 显示/隐藏`, + ``, + `📡 订阅管理:`, + `├─ /feeds - 查看订阅列表`, + `├─ /feed_add url - 添加订阅`, + `├─ /feed_edit url - 编辑订阅`, + `├─ /feed_del url - 删除订阅`, + `└─ /feed_health - 健康检查`, + ``, + `📰 其他功能:`, + `├─ /read - 友链最新文章`, + `├─ /stats - 网站统计数据`, + `└─ /ip - 访问地址`, + ``, + `🌐 快速访问:`, + `├─ 📊 后台:https://post.usj.cc`, + `└─ 🌍 博客:https://usj.cc`, + ].join("\n")); } }; @@ -652,87 +606,4 @@ handlers.feed_edit = async (chatId, arg) => { handlers.handleFeedEditReply = async (chatId, newText) => { const s = getSession(chatId); const oldUrl = s.originalSlug; - if (!oldUrl) { await sendMain(chatId, "⚠️ 会话已过期,请重新执行 /feed_edit"); return; } - - try { - if (newText && newText.trim()) { - const parts = newText.trim().split(/\s+/); - const newUrl = parts[0] || oldUrl; - const feedTitle = parts.slice(1).join(" ") || ""; - - await updateFeed(oldUrl, newUrl, feedTitle); - await sendMain(chatId, "✅ 订阅源已更新:" + (feedTitle || newUrl)); - } else { - await sendMain(chatId, "ℹ️ 未做修改"); - } - // 清除保存的 URL - s.originalSlug = undefined; - invalidateByPrefix("feeds"); - } catch (e) { - await sendMain(chatId, "⚠️ 更新失败,请稍后再试"); - } -}; - -handlers.feed_del = async (chatId, url) => { - if (!url) { await sendMain(chatId, "格式:/feed_del url"); return; } - try { await deleteFeed(url); invalidateByPrefix("feeds"); await sendMain(chatId, "✅ 已删除:" + url); } - catch (e) { await sendMain(chatId, "⚠️ API 暂时不可用,请稍后再试"); } -}; - -handlers.feed_health = async (chatId) => { - try { - await sendMessage(chatId, "⏳ 正在检测订阅源..."); - const result = await cachedHealth(); - const lines = ["📊 订阅源健康报告\n", "✅ 存活:" + result.alive + " ❌ 异常:" + result.dead]; - const dead = (result.results || []).filter((r) => !r.ok); - if (dead.length > 0) { - lines.push("\n❌ 异常站点:"); - for (const d of dead.slice(0, 10)) { - lines.push("🔴 " + d.url + " — " + (d.error || String(d.status))); - } - } - await sendMain(chatId, lines.join("\n")); - } catch (e) { await sendMain(chatId, "⚠️ API 暂时不可用,请稍后再试"); } -}; - -// ---- Data ---- - -handlers.stats = async (chatId) => { - try { - const { total } = listPosts({ perPage: 1 }); - const allLinks = await cachedLinks(true); - const allFeeds = await cachedFeeds(); - const visibleLinks = allLinks.filter((l) => !l.hidden).length; - - let extra = ""; - try { - const healthRes = await cachedHealth(); - extra = "\n\n📰 友链博客:" + healthRes.total + " 个"; - } catch (e) { /* ignore */ } - - await sendMain(chatId, - "📊 网站数据\n\n" + - "📝 本地文章:" + total + " 篇\n" + - "🔗 友链:" + visibleLinks + " 个\n" + - "📡 订阅源:" + allFeeds.length + " 个" + - extra + "\n\n🌐 usj.cc" - ); - } catch (e) { await sendMain(chatId, "⚠️ API 暂时不可用,请稍后再试"); } -}; - -handlers.read = async (chatId, limitStr) => { - const limit = parseInt(limitStr || "10") || 10; - try { - const articles = await cachedArticles(Math.min(limit, 20)); - if (articles.length === 0) { await sendMain(chatId, "暂无最新文章。"); return; } - const lines = ["📰 友链最新文章(" + articles.length + " 篇)\n"]; - for (const a of articles) { - lines.push((a.feedName || "未知") + " — " + a.title + "\n " + a.link); - } - await tg("sendMessage", { - chat_id: chatId, text: lines.join("\n"), parse_mode: "HTML", disable_web_page_preview: true, - }); - } catch (e) { await sendMain(chatId, "⚠️ API 暂时不可用,请稍后再试"); } -}; - -export default handlers; + if (!oldUrl) { await sendMain(chatId, "⚠️ 会话已 \ No newline at end of file diff --git a/write-server/src/lib/bot/poll.ts b/write-server/src/lib/bot/poll.ts index 40192e1d..ae5ad16c 100644 --- a/write-server/src/lib/bot/poll.ts +++ b/write-server/src/lib/bot/poll.ts @@ -20,10 +20,6 @@ const CALLBACK_PREFIXES: Record = { feeds: "feeds", skip_cat: "skip_categories", skip_tag: "skip_tags", - confirm_shutdown: "confirm_shutdown", - cancel_shutdown: "cancel_shutdown", - confirm_reboot: "confirm_reboot", - cancel_reboot: "cancel_reboot", }; function sleep(ms: number): Promise { @@ -179,8 +175,6 @@ export async function startPolling(): Promise { { command: "feed_health", description: "订阅源健康检查" }, { command: "read", description: "友链最新文章" }, { command: "stats", description: "网站数据" }, - { command: "shutdown", description: "关机" }, - { command: "reboot", description: "重启" }, { command: "help", description: "帮助" }, ], });