feat: 最新公告改为全来源最新6条按时间排序
去掉关键词过滤限制,两个来源的公告统一按 publish_date 倒序取6条。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+11
-12
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user