From 0b483a5c3a4e5a4ac35e3b59dbe4842f303360c4 Mon Sep 17 00:00:00 2001 From: Vaica <94612053+zqlit@users.noreply.github.com> Date: Wed, 24 Jun 2026 15:48:11 +0800 Subject: [PATCH] 1578 --- write-server/src/lib/bot/handlers.ts | 47 ++++++++++++++++++++++++++++ write-server/src/lib/bot/poll.ts | 4 +-- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/write-server/src/lib/bot/handlers.ts b/write-server/src/lib/bot/handlers.ts index 08f8c33e..6fdc7a08 100644 --- a/write-server/src/lib/bot/handlers.ts +++ b/write-server/src/lib/bot/handlers.ts @@ -561,6 +561,28 @@ handlers.link_edit = async (chatId, arg) => { }); }; +// 处理友链编辑的回复 +handlers.handleLinkEditReply = async (chatId, newName) => { + const s = getSession(chatId); + const oldUrl = s.originalSlug; + if (!oldUrl) { await sendMain(chatId, "⚠️ 会话已过期,请重新执行 /link_edit"); return; } + + try { + // 如果用户输入了新名称,更新友链 + if (newName && newName.trim()) { + await updateLink(oldUrl, { name: newName.trim() }); + await sendMain(chatId, "✅ 友链已更新:" + newName.trim()); + } else { + await sendMain(chatId, "ℹ️ 未做修改"); + } + // 清除保存的 URL + s.originalSlug = undefined; + invalidateByPrefix("links"); + } catch (e) { + await sendMain(chatId, "⚠️ 更新失败,请稍后再试"); + } +}; + handlers.link_del = async (chatId, url) => { if (!url) { await sendMain(chatId, "格式:/link_del url"); return; } try { await deleteLink(url); invalidateByPrefix("links"); await sendMain(chatId, "✅ 已删除:" + url); } @@ -626,6 +648,31 @@ 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); } diff --git a/write-server/src/lib/bot/poll.ts b/write-server/src/lib/bot/poll.ts index 24b0440f..40192e1d 100644 --- a/write-server/src/lib/bot/poll.ts +++ b/write-server/src/lib/bot/poll.ts @@ -119,9 +119,9 @@ export async function startPolling(): Promise { if (original.includes("请输入分类")) { await handleCommand(chatId, "categories", fullText); continue; } if (original.includes("请输入标签")) { await handleCommand(chatId, "tags", fullText); continue; } if (original.includes("请输入友链信息")) { await handleCommand(chatId, "link_add", fullText); continue; } - if (original.includes("请输入新名称")) { await handleCommand(chatId, "link_edit", fullText); continue; } + if (original.includes("请输入新名称")) { await handlers.handleLinkEditReply(chatId, fullText); continue; } if (original.includes("请输入订阅源 URL")) { await handleCommand(chatId, "feed_add", fullText); continue; } - if (original.includes("请输入新的订阅信息")) { await handleCommand(chatId, "feed_edit", fullText); continue; } + if (original.includes("请输入新的订阅信息")) { await handlers.handleFeedEditReply(chatId, fullText); continue; } } const parts = fullText.split("@")[0].split(/\s+/);