From 734cfc2eb337087eaf5b0821b67b21f858c92d0e Mon Sep 17 00:00:00 2001 From: YoursFunny Date: Sat, 8 Aug 2026 20:20:05 +0800 Subject: [PATCH] handlers: skip inline fetches for non-post queries Inline queries fire per keystroke and each fetch runs the 3-attempt retry loop; a user typing any text was pumping requests into X/Pixiv/BSky and risking rate-limit bans. Queries now pass only if cache_key recognizes them as a supported post URL. --- crates/xmedia-bot/src/handlers.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/xmedia-bot/src/handlers.rs b/crates/xmedia-bot/src/handlers.rs index e26ac86..e695dee 100644 --- a/crates/xmedia-bot/src/handlers.rs +++ b/crates/xmedia-bot/src/handlers.rs @@ -775,6 +775,12 @@ pub async fn inline_query_handler(bot: Bot, query: InlineQuery) -> Result<(), Re if query.query.is_empty() { return respond(()); } + // Telegram fires an inline query on every keystroke; only run a fetch + // (3 attempts!) for something that is actually a supported post URL, so + // typing does not hammer the source sites. + if x_media::site::cache_key(&query.query).is_none() { + return respond(()); + } log::info!("inline query: {}", query.query); match x_media::site::fetch(&query.query).await { Ok(Some(fetched)) => {