diff --git a/adapters/tg.py b/adapters/tg.py index 43eda7a..e1163ff 100644 --- a/adapters/tg.py +++ b/adapters/tg.py @@ -10,7 +10,6 @@ from aiogram.filters import CommandStart, Command from aiogram.client.session.aiohttp import AiohttpSession from aiogram import F -from core.inline import handle_inline_query from core.mc import handle_mc_status_command from core.middleware.rikki import RikkiMiddleware from core.post_to_fedi import router as fedi_router @@ -78,7 +77,6 @@ class TelegramAdapter: # repeater 模块 repeater_router.message(F.chat.type.in_({'group', 'supergroup'}))(MessageRepeater().handle_message) router.message(F.text == '我是笨蛋')(handle_baka) - router.inline_query()(handle_inline_query) # 捕获所有其他消息 dummy_router.message(F.chat.type.in_({'group', 'supergroup'}))(dummy_handler) diff --git a/core/inline.py b/core/inline.py deleted file mode 100644 index 9c48751..0000000 --- a/core/inline.py +++ /dev/null @@ -1,149 +0,0 @@ -from aiogram.enums import ParseMode -from aiogram.types import InlineQuery, InlineQueryResultArticle, InputTextMessageContent - - -async def handle_inline_query(query: InlineQuery): - """ - Handle inline queries. - This function is called when an inline query is received. - It can be used to provide inline results based on the query. - """ - print(f"Received inline query") - query_text = query.query - if query_text == "": - await query.answer(results=[ - InlineQueryResultArticle( - id="1", - title="你还没什么都没输入呢", - input_message_content=InputTextMessageContent( - message_text=f"难说!", - parse_mode=ParseMode.MARKDOWN - ), - description=f"或许你可以试试 'search' 什么的" - ), - ], cache_time=0) - return - - if query_text.startswith("search"): - search_query = query_text.replace("search", "").strip() - if search_query: - await query.answer(results=[ - InlineQueryResultArticle( - id="1", - title="丢一个 DuckDuckGo 的搜索结果", - input_message_content=InputTextMessageContent( - message_text=f"我建议你用 [DuckDuckGo 搜一下 {search_query}](https://duckduckgo.com/?q={search_query})", - parse_mode=ParseMode.MARKDOWN - ), - description=f"在 DuckDuckGo 上搜索 {search_query}" - ), - InlineQueryResultArticle( - id="2", - title="丢一个 Google 的搜索结果", - input_message_content=InputTextMessageContent( - message_text=f"我建议你用 [Google 搜一下 {search_query}](https://www.google.com/search?q={search_query})", - parse_mode=ParseMode.MARKDOWN - ), - description=f"在 Google 上搜索 {search_query}" - ) - ], cache_time=0) - else: - await query.answer(results=[ - InlineQueryResultArticle( - id="1", - title="输入搜索内容", - input_message_content=InputTextMessageContent( - message_text="ta 好像想让你用搜索引擎搜索这个问题,但 ta 没有输入任何内容。", - parse_mode=ParseMode.MARKDOWN - ), - description="请在 'search' 后输入你想要搜索的内容。" - ) - ], cache_time=0) - return - - if query_text.startswith("pg"): - text = query_text.replace("pg", "").strip() - import pangu - text = pangu.spacing_text(text) - await query.answer(results=[ - InlineQueryResultArticle( - id="1", - title="发送 Pangu 格式化之后的结果", - input_message_content=InputTextMessageContent( - message_text=text, - parse_mode=ParseMode.MARKDOWN - ), - description=f"格式化后的文本:{text}" - ) - ], cache_time=0) - return - if query_text == "你的头怎么尖尖的": - await query.answer(results=[ - InlineQueryResultArticle( - id="1", - title="阿诺模式", - input_message_content=InputTextMessageContent( - message_text="你的头怎么尖尖的,那我问你", - parse_mode=ParseMode.MARKDOWN - ), - description="我可能是阿诺,但我是阿诺不太可能" - ) - ], cache_time=0) - return - """ - if query_text.startswith("你的头怎么绿绿的"): - await query.answer(results=[ - InlineQueryResultArticle( - id="1", - title="头上总得有点绿", - input_message_content=InputTextMessageContent( - message_text="你说的对,我的头是绿的", - parse_mode=ParseMode.MARKDOWN - ), - description="说实话,你一般问出来这个问题的时候,我一般不建议你再继续下去了" - ) - ], cache_time=0) - return - """ - if query_text.startswith('anuo'): - main = query_text.replace("anuo", "").strip() - await query.answer(results=[ - InlineQueryResultArticle( - id="1", - title="阿诺的公式", - input_message_content=InputTextMessageContent( - message_text=f"{"我可能是阿诺,但我是阿诺不太可能" if not main else f"{main}有可能,但{main}不太可能"}", - parse_mode=ParseMode.MARKDOWN - ), - description=f"{"我可能是阿诺,但我是阿诺不太可能" if not main else f"{main}有可能,但{main}不太可能"}" - ) - ], cache_time=0) - return - if query_text.startswith("将军:"): - await query.answer(results=[ - InlineQueryResultArticle( - id="1", - title="这句话不用记", - input_message_content=InputTextMessageContent( - message_text=f"{query_text}\n\n旁边的手下:✍✍✍✍✍✍✍✍✍✍✍\n️围观的群众:\\o/\\o/\\o/\\o/\\o/\\o/\\o/\\o/\\o/\\o/\\o/\\o/\\o/\\o" - f"/\\o/\\o/\\o/", - parse_mode=ParseMode.MARKDOWN - ), - description=f"\\o/\\o/\\o/\\o/\\o/\\o/\\o/\\o/\\o/\\o/\\o/\\o/\\o/\\o/\\o/\\o/\\o/" - ), - ], cache_time=0) - return - # 如果没有匹配到任何内容,则返回一个默认的结果 - await query.answer(results=[ - InlineQueryResultArticle( - id="2", - title=f"嘿,你好啊 {query.from_user.full_name}!", - input_message_content=InputTextMessageContent( - message_text="小娜😭", - parse_mode=ParseMode.MARKDOWN - ), - description="很抱歉,我还不能理解你说的内容。" - ) - ], cache_time=0) - return - diff --git a/core/link.py b/core/link.py index e721e9d..83e103b 100644 --- a/core/link.py +++ b/core/link.py @@ -14,7 +14,7 @@ from config import config whitelist_param_links = ['www.iesdouyin.com','item.taobao.com', 'detail.tmall.com', 'h5.m.goofish.com', 'music.163.com', 'www.bilibili.com', 'm.bilibili.com', 'bilibili.com', 'mall.bilibili.com', 'space.bilibili.com', 'live.bilibili.com','item.m.jd.com','item.jd.com', - 'www.xiaohongshu.com','zhuanlan.zhihu.com','www.baidu.com','www.youtube.com'] + 'www.xiaohongshu.com','zhuanlan.zhihu.com'] has_self_redirection_links = ['www.cnbeta.com.tw','m.cnbeta.com.tw','www.landiannews.com', 'www.bilibili.com'] @@ -174,22 +174,6 @@ def reserve_whitelisted_params(url): # 重新构建URL cleaned_query = urlencode(new_query_params, doseq=True) return urlunparse(parsed_url._replace(query=cleaned_query)) - elif parsed_url.hostname in ['www.baidu.com','www.youtube.com']: - new_query_params = {} - if parsed_url.hostname == 'www.baidu.com' and 'wd' in query_params: - # 百度搜索链接保留 wd 参数 - new_query_params['wd'] = query_params['wd'] - if parsed_url.hostname == 'www.youtube.com': - # YouTube 视频链接保留 v 参数 - if 'v' in query_params: - new_query_params['v'] = query_params['v'] # 保留 v 参数 - if 't' in query_params: - new_query_params['t'] = query_params['t'] # 保留 t 参数 - if 'list' in query_params: - new_query_params['list'] = query_params['list'] # 保留 list 参数 - # 重新构建URL - cleaned_query = urlencode(new_query_params, doseq=True) - return urlunparse(parsed_url._replace(query=cleaned_query)) elif parsed_url.hostname in ['chatglm.cn'] and query_params: # 就你叫智谱啊 new_query_params = {'share_conversation_id': query_params['share_conversation_id']} @@ -266,7 +250,7 @@ async def handle_links(message: Message): final_urls = [url for url in final_urls if url is not None] # 回复处理后的链接 if final_urls: - await message.reply(f"
{"\n\n".join(final_urls)}\n
\n消息里有包含跟踪参数的链接,已经帮你转换了哦~\n\n" + await message.reply(f"
\n{"\n\n".join(final_urls)}\n
\n消息里有包含跟踪参数的链接,已经帮你转换了哦~\n\n" f"注意:这个功能是试验性的,可能会出现问题。" f"\n如果你找到了问题,欢迎" f"把它通过 /report_broken_links 链接 需要去除的参数等等 报告给开发者!") \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index dd38af7..842706d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,6 @@ dependencies = [ "mastodon-py==2.0.1", "matrix-nio==0.25.2", "mcstatus==12.0.2", - "pangu==4.0.6.1", "python-abp==0.2.0", "pyyaml>=6.0.2", "requests>=2.32.4", diff --git a/uv.lock b/uv.lock index 70a7733..9ee06ca 100644 --- a/uv.lock +++ b/uv.lock @@ -457,15 +457,6 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/d8/30/9aec301e9772b098c1f5c0ca0279237c9766d94b97802e9888010c64b0ed/multidict-6.6.3-py3-none-any.whl", hash = "sha256:8db10f29c7541fc5da4defd8cd697e1ca429db743fa716325f236079b96f775a", size = 12313, upload-time = "2025-06-30T15:53:45.437Z" }, ] -[[package]] -name = "pangu" -version = "4.0.6.1" -source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/78/dd/55a1e9d35ac17f49869359b2197fc09d17ee024ba545985b49b3e75a870a/pangu-4.0.6.1.tar.gz", hash = "sha256:f799d127709fe5ecff5d476945ac63d4be758b7bda02efb95715f1dc24472a2f", size = 6288, upload-time = "2019-02-08T18:17:30.527Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/48/77/b52fac2ca4e4596f22dd6200b99ad515fb64b1ae7d3a12325b45b11e2a67/pangu-4.0.6.1-py3-none-any.whl", hash = "sha256:5023dced34b48da7ec61a2847efcbb8cf4fb748f8e589e1e7dfb008b7ad00206", size = 6401, upload-time = "2019-02-08T18:17:28.142Z" }, -] - [[package]] name = "propcache" version = "0.3.2" @@ -688,7 +679,6 @@ dependencies = [ { name = "mastodon-py" }, { name = "matrix-nio" }, { name = "mcstatus" }, - { name = "pangu" }, { name = "python-abp" }, { name = "pyyaml" }, { name = "requests" }, @@ -702,7 +692,6 @@ requires-dist = [ { name = "mastodon-py", specifier = "==2.0.1" }, { name = "matrix-nio", specifier = "==0.25.2" }, { name = "mcstatus", specifier = "==12.0.2" }, - { name = "pangu", specifier = "==4.0.6.1" }, { name = "python-abp", specifier = "==0.2.0" }, { name = "pyyaml", specifier = ">=6.0.2" }, { name = "requests", specifier = ">=2.32.4" },