From 1b76f1c85135c4b2d0bf46ec4a1bd072e1eb02e5 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Fri, 25 Oct 2024 13:10:35 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E7=AB=99=E7=82=B9=E6=9C=AA?= =?UTF-8?q?=E8=AF=BB=E6=B6=88=E6=81=AF=E5=8F=91=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chain/site.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/chain/site.py b/app/chain/site.py index 2fe48e98..11a125fe 100644 --- a/app/chain/site.py +++ b/app/chain/site.py @@ -22,7 +22,7 @@ from app.helper.rss import RssHelper from app.helper.sites import SitesHelper from app.log import logger from app.schemas import MessageChannel, Notification, SiteUserData -from app.schemas.types import EventType +from app.schemas.types import EventType, NotificationType from app.utils.http import RequestUtils from app.utils.site import SiteUtils from app.utils.string import StringUtils @@ -65,9 +65,27 @@ class SiteChain(ChainBase): self.siteoper.update_userdata(domain=StringUtils.get_url_domain(site.get("domain")), name=site.get("name"), payload=userdata.dict()) + # 发送事件 EventManager().send_event(EventType.SiteRefreshed, { "site_id": site.get("id") }) + # 发送站点消息 + if userdata.message_unread: + if userdata.message_unread_contents and len(userdata.message_unread_contents) > 0: + for head, date, content in userdata.message_unread_contents: + msg_title = f"【站点 {site.get('name')} 消息】" + msg_text = f"时间:{date}\n标题:{head}\n内容:\n{content}" + self.post_message(Notification( + mtype=NotificationType.SiteMessage, + title=msg_title, text=msg_text, link=site.get("url") + )) + else: + self.post_message(Notification( + mtype=NotificationType.SiteMessage, + title=f"站点 {site.get('name')} 收到 " + f"{userdata.message_unread} 条新消息,请登陆查看", + link=site.get("url") + )) return userdata def refresh_userdatas(self) -> None: