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:
|
try:
|
||||||
async for db in get_db():
|
async for db in get_db():
|
||||||
stmt = (
|
result = await db.execute(
|
||||||
select(Announcement)
|
select(Announcement)
|
||||||
.where(Announcement.keyword_matched == True) # noqa: E712
|
|
||||||
.order_by(desc(Announcement.publish_date))
|
.order_by(desc(Announcement.publish_date))
|
||||||
.limit(5)
|
.limit(6)
|
||||||
)
|
)
|
||||||
result = await db.execute(stmt)
|
|
||||||
items = result.scalars().all()
|
items = result.scalars().all()
|
||||||
|
|
||||||
if not items:
|
if not items:
|
||||||
await self.client.send_text("暂无公告", from_user)
|
await self.client.send_text("暂无公告", from_user)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
lines = ["最新公告(最近5条):"]
|
for ann in items:
|
||||||
for i, ann in enumerate(items, 1):
|
title = ann.title if len(ann.title) <= 128 else ann.title[:125] + "..."
|
||||||
date_str = ann.publish_date.strftime("%m-%d %H:%M") if ann.publish_date else "?"
|
purchase_name = ann.purchase_name or ""
|
||||||
title = ann.title[:28] + "..." if len(ann.title) > 28 else ann.title
|
if len(purchase_name) > 25:
|
||||||
source = ann.source_name or ann.source_code
|
purchase_name = purchase_name[:22] + "..."
|
||||||
lines.append(f"{i}. [{date_str}] {source}")
|
time_str = ann.publish_date.strftime("%Y-%m-%d %H:%M") if ann.publish_date else "时间未知"
|
||||||
lines.append(f" {title}")
|
source_name = ann.source_name or ann.source_code or ""
|
||||||
await self.client.send_text("\n".join(lines), from_user)
|
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:
|
except Exception as e:
|
||||||
logger.error(f"查询最新公告失败: {e}")
|
logger.error(f"查询最新公告失败: {e}")
|
||||||
await self.client.send_text("查询失败,请稍后再试", from_user)
|
await self.client.send_text("查询失败,请稍后再试", from_user)
|
||||||
|
|||||||
Reference in New Issue
Block a user