From 6d1d512fca3838d080d9baad97bd6fca7f4eb6b8 Mon Sep 17 00:00:00 2001 From: v6ole Date: Tue, 12 May 2026 17:21:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9C=80=E6=96=B0=E5=85=AC=E5=91=8A?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E5=85=A8=E6=9D=A5=E6=BA=90=E6=9C=80=E6=96=B0?= =?UTF-8?q?6=E6=9D=A1=E6=8C=89=E6=97=B6=E9=97=B4=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 去掉关键词过滤限制,两个来源的公告统一按 publish_date 倒序取6条。 Co-Authored-By: Claude Sonnet 4.6 --- app/wechat/handler.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/app/wechat/handler.py b/app/wechat/handler.py index 599bc7e..a9e0902 100644 --- a/app/wechat/handler.py +++ b/app/wechat/handler.py @@ -243,27 +243,26 @@ class WeChatMessageHandler: try: async for db in get_db(): - stmt = ( + result = await db.execute( select(Announcement) - .where(Announcement.keyword_matched == True) # noqa: E712 .order_by(desc(Announcement.publish_date)) - .limit(5) + .limit(6) ) - result = await db.execute(stmt) items = result.scalars().all() if not items: await self.client.send_text("暂无公告", from_user) return None - lines = ["最新公告(最近5条):"] - for i, ann in enumerate(items, 1): - date_str = ann.publish_date.strftime("%m-%d %H:%M") if ann.publish_date else "?" - title = ann.title[:28] + "..." if len(ann.title) > 28 else ann.title - source = ann.source_name or ann.source_code - lines.append(f"{i}. [{date_str}] {source}") - lines.append(f" {title}") - await self.client.send_text("\n".join(lines), from_user) + for ann in items: + title = ann.title if len(ann.title) <= 128 else ann.title[:125] + "..." + purchase_name = ann.purchase_name or "" + if len(purchase_name) > 25: + purchase_name = purchase_name[:22] + "..." + time_str = ann.publish_date.strftime("%Y-%m-%d %H:%M") if ann.publish_date else "时间未知" + source_name = ann.source_name or ann.source_code or "" + description = f"{source_name} | {purchase_name} | {time_str}" + await self.client.send_textcard(title, description, ann.content_url or "", from_user) except Exception as e: logger.error(f"查询最新公告失败: {e}") await self.client.send_text("查询失败,请稍后再试", from_user)