1601
This commit is contained in:
1 parent
590409ed89
commit
8aa52a0dc1
1 file changed
+75
-1
@@ -606,4 +606,78 @@ handlers.feed_edit = async (chatId, arg) => {
|
||||
handlers.handleFeedEditReply = async (chatId, newText) => {
|
||||
const s = getSession(chatId);
|
||||
const oldUrl = s.originalSlug;
|
||||
if (!oldUrl) { await sendMain(chatId, "⚠️ 会话已
|
||||
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, "ℹ️ 未做修改");
|
||||
}
|
||||
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) {
|
||||
lines.push("🔴 " + d.url + " — " + (d.error || String(d.status)));
|
||||
}
|
||||
}
|
||||
await sendMain(chatId, lines.join("\n"));
|
||||
} catch (e) { await sendMain(chatId, "⚠️ API 暂时不可用,请稍后再试"); }
|
||||
};
|
||||
|
||||
// ---- Read ----
|
||||
|
||||
handlers.read = async (chatId) => {
|
||||
try {
|
||||
await sendMessage(chatId, "📰 正在获取友链最新文章...");
|
||||
const articles = await getArticles(10);
|
||||
if (articles.length === 0) { await sendMain(chatId, "暂时没有新文章。"); return; }
|
||||
const lines = ["📰 <b>友链最新文章</b>\n"];
|
||||
for (const a of articles) {
|
||||
const date = new Date(a.pubDate).toLocaleDateString("zh-CN", { timeZone: "Asia/Shanghai" });
|
||||
lines.push("• <a href=\"" + a.link + "\">" + escapeHtml(a.title) + "</a>");
|
||||
lines.push(" " + (a.feedName || a.siteUrl) + " · " + date);
|
||||
}
|
||||
await tg("sendMessage", {
|
||||
chat_id: chatId, text: lines.join("\n"), parse_mode: "HTML", disable_web_page_preview: true,
|
||||
});
|
||||
} catch (e) { await sendMain(chatId, "⚠️ 获取失败,请稍后再试"); }
|
||||
};
|
||||
|
||||
// ---- Stats ----
|
||||
|
||||
handlers.stats = async (chatId) => {
|
||||
try {
|
||||
const res = await fetch(BLOG_ROOT + "/index.xml");
|
||||
const data = await getStats();
|
||||
const lines = ["📊 <b>网站数据</b>\n"];
|
||||
lines.push("📝 文章总数:" + data.totalPosts + " 篇");
|
||||
lines.push("💬 评论总数:" + data.totalComments + " 条");
|
||||
await sendMain(chatId, lines.join("\n"));
|
||||
} catch (e) { await sendMain(chatId, "⚠️ 获取失败,请稍后再试"); }
|
||||
};
|
||||
|
||||
export default handlers;
|
||||
Reference in new issue
Block a user