This commit is contained in:
Vaica committed 2026-06-24 15:55:06 +08:00
1 parent 0b483a5c3a
commit 590409ed89
2 files changed
+64 -199

No files matched your search

+64 -193
View File
@@ -97,21 +97,20 @@ handlers.start = async (chatId) => {
await sendMain(chatId, [
`👋 <b>欢迎使用写作后台!</b>`,
``,
`📝 <b>功能菜单:</b>`,
`├─ /new - 新建文章`,
`├─ /edit - 编辑文章`,
`├─ /list - 文章列表`,
`├─ /deploy - 部署博客`,
`└─ /status - 服务器状态`,
`📝 <b>快速开始:</b>`,
`├─ /new 标题 - 新建文章`,
`├─ /edit slug - 编辑文章`,
`└─ /list - 查看文章列表`,
``,
`🔗 <b>友链 & 订阅:</b>`,
`├─ /links - 友链管理`,
`└─ /feeds - 订阅管理`,
``,
`🌐 <b>访问地址:</b>`,
`├─ 📊 后台管理:https://post.usj.cc`,
`└─ 🌍 博客首页:https://usj.cc`,
``,
`💡 <b>提示:</b>`,
`• 使用 /new 开始写作`,
`• 发送文字直接创建草稿`,
`• 发送语音自动转文字`,
`💡 <b>帮助:</b>输入 /help 查看所有命令`,
``,
`🎯 <b>开始写作吧!</b>`,
].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 = [
`📊 <b>服务器状态</b>`,
``,
`🖥️ <b>Hugo 服务:</b>`,
`├─ 状态:${statusEmoji} ${statusText}`,
`└─ 地址:https://post.usj.cc`,
``,
s.running ? `🟢 <b>服务正常运行中</b>` : `🔴 <b>服务未运行</b>`,
].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,
"✍ <b>写作中</b>\n\n" +
"/publish 保存 /draft 草稿 /deploy 部署\n" +
"/preview 预览 /undo 撤销 /cancel 取消\n" +
"/title 标题 /categories 分类 /tags 标签\n\n" +
"直接发消息追加正文,发照片追加图片"
);
await sendWrite(chatId, [
`✍ <b>写作模式</b>`,
``,
`📝 <b>编辑命令:</b>`,
`├─ /publish - 保存并发布`,
`├─ /draft - 保存草稿`,
`├─ /deploy - 部署到服务器`,
`├─ /preview - 预览文章`,
`└─ /undo - 撤销最后一段`,
``,
`⚙️ <b>设置命令:</b>`,
`├─ /title 标题 - 设置标题`,
`├─ /categories 分类 - 设置分类`,
`├─ /tags 标签 - 设置标签`,
`└─ /author 作者 - 设置作者`,
``,
`💡 <b>提示:</b>`,
`• 直接发送文字追加到正文`,
`• 发送图片添加到文章`,
`• 发送语音自动转文字`,
`• 输入 /cancel 取消写作`,
].join("\n"));
} else {
await sendMain(chatId,
"🤖 <b>WriteBot 命令</b>\n\n" +
"📝 <b>文章</b>\n" +
"/new 标题 — 新建\n" +
"/edit slug — 编辑\n" +
"/delete slug — 删除\n" +
"/list — 文章列表\n\n" +
"🔗 <b>友链</b>\n" +
"/links — 列表\n" +
"/link_add url 名称 — 添加\n" +
"/link_edit url — 编辑\n" +
"/link_del url — 删除\n" +
"/link_toggle url — 显示/隐藏\n\n" +
"📡 <b>订阅</b>\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, [
`🤖 <b>WriteBot 命令指南</b>`,
``,
`📝 <b>文章管理:</b>`,
`├─ /new 标题 - 新建文章`,
`├─ /edit slug - 编辑文章`,
`├─ /delete slug - 删除文章`,
`└─ /list - 文章列表`,
``,
`🔗 <b>友链管理:</b>`,
`├─ /links - 查看友链列表`,
`├─ /link_add url 名称 - 添加友链`,
`├─ /link_edit url - 编辑友链`,
`├─ /link_del url - 删除友链`,
`└─ /link_toggle url - 显示/隐藏`,
``,
`📡 <b>订阅管理:</b>`,
`├─ /feeds - 查看订阅列表`,
`├─ /feed_add url - 添加订阅`,
`├─ /feed_edit url - 编辑订阅`,
`├─ /feed_del url - 删除订阅`,
`└─ /feed_health - 健康检查`,
``,
`📰 <b>其他功能:</b>`,
`├─ /read - 友链最新文章`,
`├─ /stats - 网站统计数据`,
`└─ /ip - 访问地址`,
``,
`🌐 <b>快速访问:</b>`,
`├─ 📊 后台: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 = ["📊 <b>订阅源健康报告</b>\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,
"📊 <b>网站数据</b>\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 = ["📰 <b>友链最新文章</b>(" + 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, "⚠️ 会话已
-6
View File
@@ -20,10 +20,6 @@ const CALLBACK_PREFIXES: Record<string, string> = {
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<void> {
@@ -179,8 +175,6 @@ export async function startPolling(): Promise<void> {
{ command: "feed_health", description: "订阅源健康检查" },
{ command: "read", description: "友链最新文章" },
{ command: "stats", description: "网站数据" },
{ command: "shutdown", description: "关机" },
{ command: "reboot", description: "重启" },
{ command: "help", description: "帮助" },
],
});