mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 07:27:15 +08:00
feat: conditionally save message history based on save_history flag
This commit is contained in:
+73
-56
@@ -4,18 +4,10 @@ from datetime import datetime
|
||||
from typing import List, Optional, Tuple, Union, Dict
|
||||
from urllib.parse import urljoin
|
||||
|
||||
from app.helper.sites import SitesHelper # noqa
|
||||
from lxml import etree
|
||||
|
||||
from app.chain import ChainBase
|
||||
from app.helper.interaction import (
|
||||
SlashInteractionManager,
|
||||
build_navigation_buttons,
|
||||
format_markdown_table,
|
||||
page_items,
|
||||
supports_interaction_buttons,
|
||||
supports_markdown,
|
||||
update_or_post_message,
|
||||
)
|
||||
from app.core.config import global_vars, settings
|
||||
from app.core.event import Event, eventmanager
|
||||
from app.db.models.site import Site
|
||||
@@ -25,8 +17,16 @@ from app.helper.browser import PlaywrightHelper
|
||||
from app.helper.cloudflare import under_challenge
|
||||
from app.helper.cookie import CookieHelper
|
||||
from app.helper.cookiecloud import CookieCloudHelper
|
||||
from app.helper.interaction import (
|
||||
SlashInteractionManager,
|
||||
build_navigation_buttons,
|
||||
format_markdown_table,
|
||||
page_items,
|
||||
supports_interaction_buttons,
|
||||
supports_markdown,
|
||||
update_or_post_message,
|
||||
)
|
||||
from app.helper.rss import RssHelper
|
||||
from app.helper.sites import SitesHelper # noqa
|
||||
from app.log import logger
|
||||
from app.schemas import MessageChannel, Notification, SiteUserData
|
||||
from app.schemas.types import EventType, NotificationType
|
||||
@@ -34,7 +34,6 @@ from app.utils.http import RequestUtils
|
||||
from app.utils.site import SiteUtils
|
||||
from app.utils.string import StringUtils
|
||||
|
||||
|
||||
site_interaction_manager = SlashInteractionManager()
|
||||
|
||||
|
||||
@@ -359,7 +358,7 @@ class SiteChain(ChainBase):
|
||||
if global_vars.is_system_stopped:
|
||||
logger.info("系统正在停止,中断CookieCloud同步")
|
||||
return False, "系统正在停止,同步被中断"
|
||||
|
||||
|
||||
# 索引器信息
|
||||
indexer = siteshelper.get_indexer(domain)
|
||||
# 数据库的站点信息
|
||||
@@ -642,11 +641,11 @@ class SiteChain(ChainBase):
|
||||
return True, "连接成功"
|
||||
|
||||
def remote_list(
|
||||
self,
|
||||
arg_str: str = "",
|
||||
channel: MessageChannel = None,
|
||||
userid: Union[str, int] = None,
|
||||
source: Optional[str] = None,
|
||||
self,
|
||||
arg_str: str = "",
|
||||
channel: MessageChannel = None,
|
||||
userid: Union[str, int] = None,
|
||||
source: Optional[str] = None,
|
||||
):
|
||||
"""
|
||||
/sites 统一入口。
|
||||
@@ -660,11 +659,11 @@ class SiteChain(ChainBase):
|
||||
)
|
||||
normalized_arg = (arg_str or "").strip()
|
||||
if normalized_arg and self.handle_text_interaction(
|
||||
channel=channel,
|
||||
source=source,
|
||||
userid=userid,
|
||||
username="",
|
||||
text=normalized_arg,
|
||||
channel=channel,
|
||||
source=source,
|
||||
userid=userid,
|
||||
username="",
|
||||
text=normalized_arg,
|
||||
):
|
||||
return
|
||||
self._render_site_interaction(
|
||||
@@ -688,14 +687,14 @@ class SiteChain(ChainBase):
|
||||
return parts[1], parts[2]
|
||||
|
||||
def handle_callback_interaction(
|
||||
self,
|
||||
callback_data: str,
|
||||
channel: MessageChannel,
|
||||
source: str,
|
||||
userid: Union[str, int],
|
||||
username: str,
|
||||
original_message_id: Optional[Union[str, int]] = None,
|
||||
original_chat_id: Optional[str] = None,
|
||||
self,
|
||||
callback_data: str,
|
||||
channel: MessageChannel,
|
||||
source: str,
|
||||
userid: Union[str, int],
|
||||
username: str,
|
||||
original_message_id: Optional[Union[str, int]] = None,
|
||||
original_chat_id: Optional[str] = None,
|
||||
) -> bool:
|
||||
"""
|
||||
处理 /sites 按钮交互。
|
||||
@@ -760,12 +759,12 @@ class SiteChain(ChainBase):
|
||||
return True
|
||||
|
||||
def handle_text_interaction(
|
||||
self,
|
||||
channel: MessageChannel,
|
||||
source: str,
|
||||
userid: Union[str, int],
|
||||
username: str,
|
||||
text: str,
|
||||
self,
|
||||
channel: MessageChannel,
|
||||
source: str,
|
||||
userid: Union[str, int],
|
||||
username: str,
|
||||
text: str,
|
||||
) -> bool:
|
||||
"""
|
||||
处理 /sites 文本补充输入。
|
||||
@@ -987,14 +986,14 @@ class SiteChain(ChainBase):
|
||||
return True
|
||||
|
||||
def _render_site_interaction(
|
||||
self,
|
||||
request,
|
||||
channel: MessageChannel,
|
||||
source: Optional[str],
|
||||
userid: Union[str, int],
|
||||
username: Optional[str],
|
||||
original_message_id: Optional[Union[str, int]] = None,
|
||||
original_chat_id: Optional[str] = None,
|
||||
self,
|
||||
request,
|
||||
channel: MessageChannel,
|
||||
source: Optional[str],
|
||||
userid: Union[str, int],
|
||||
username: Optional[str],
|
||||
original_message_id: Optional[Union[str, int]] = None,
|
||||
original_chat_id: Optional[str] = None,
|
||||
) -> None:
|
||||
"""
|
||||
渲染 /sites 当前页面。
|
||||
@@ -1202,7 +1201,8 @@ class SiteChain(ChainBase):
|
||||
self.post_message(Notification(
|
||||
channel=channel,
|
||||
title=f"站点编号 {site_id} 不存在!",
|
||||
userid=userid))
|
||||
userid=userid,
|
||||
save_history=False))
|
||||
return
|
||||
# 禁用站点
|
||||
siteoper.update(site_id, {
|
||||
@@ -1229,7 +1229,9 @@ class SiteChain(ChainBase):
|
||||
if not site:
|
||||
self.post_message(Notification(
|
||||
channel=channel,
|
||||
title=f"站点编号 {site_id} 不存在!", userid=userid))
|
||||
title=f"站点编号 {site_id} 不存在!",
|
||||
userid=userid,
|
||||
save_history=False))
|
||||
return
|
||||
# 禁用站点
|
||||
siteoper.update(site_id, {
|
||||
@@ -1280,7 +1282,9 @@ class SiteChain(ChainBase):
|
||||
self.post_message(Notification(
|
||||
channel=channel,
|
||||
source=source,
|
||||
title=err_title, userid=userid))
|
||||
title=err_title,
|
||||
userid=userid,
|
||||
save_history=False))
|
||||
return
|
||||
arg_str = str(arg_str).strip()
|
||||
args = arg_str.split()
|
||||
@@ -1292,14 +1296,18 @@ class SiteChain(ChainBase):
|
||||
self.post_message(Notification(
|
||||
channel=channel,
|
||||
source=source,
|
||||
title=err_title, userid=userid))
|
||||
title=err_title,
|
||||
userid=userid,
|
||||
save_history=False))
|
||||
return
|
||||
site_id = args[0]
|
||||
if not site_id.isdigit():
|
||||
self.post_message(Notification(
|
||||
channel=channel,
|
||||
source=source,
|
||||
title=err_title, userid=userid))
|
||||
title=err_title,
|
||||
userid=userid,
|
||||
save_history=False))
|
||||
return
|
||||
# 站点ID
|
||||
site_id = int(site_id)
|
||||
@@ -1309,12 +1317,16 @@ class SiteChain(ChainBase):
|
||||
self.post_message(Notification(
|
||||
channel=channel,
|
||||
source=source,
|
||||
title=f"站点编号 {site_id} 不存在!", userid=userid))
|
||||
title=f"站点编号 {site_id} 不存在!",
|
||||
userid=userid,
|
||||
save_history=False))
|
||||
return
|
||||
self.post_message(Notification(
|
||||
channel=channel,
|
||||
source=source,
|
||||
title=f"开始更新【{site_info.name}】Cookie&UA ...", userid=userid))
|
||||
title=f"开始更新【{site_info.name}】Cookie&UA ...",
|
||||
userid=userid,
|
||||
save_history=False))
|
||||
# 用户名
|
||||
username = args[1]
|
||||
# 密码
|
||||
@@ -1331,13 +1343,15 @@ class SiteChain(ChainBase):
|
||||
source=source,
|
||||
title=f"【{site_info.name}】 Cookie&UA更新失败!",
|
||||
text=f"错误原因:{msg}",
|
||||
userid=userid))
|
||||
userid=userid,
|
||||
save_history=False))
|
||||
else:
|
||||
self.post_message(Notification(
|
||||
channel=channel,
|
||||
source=source,
|
||||
title=f"【{site_info.name}】 Cookie&UA更新成功",
|
||||
userid=userid))
|
||||
userid=userid,
|
||||
save_history=False))
|
||||
|
||||
def remote_refresh_userdatas(self, channel: MessageChannel,
|
||||
userid: Union[str, int] = None, source: Optional[str] = None):
|
||||
@@ -1349,7 +1363,8 @@ class SiteChain(ChainBase):
|
||||
channel=channel,
|
||||
source=source,
|
||||
title="开始刷新站点数据 ...",
|
||||
userid=userid
|
||||
userid=userid,
|
||||
save_history=False,
|
||||
))
|
||||
# 刷新站点数据
|
||||
site_datas = self.refresh_userdatas()
|
||||
@@ -1392,12 +1407,14 @@ class SiteChain(ChainBase):
|
||||
source=source,
|
||||
title="【站点数据统计】",
|
||||
text="\n".join(sorted_messages),
|
||||
userid=userid
|
||||
userid=userid,
|
||||
save_history=False
|
||||
))
|
||||
else:
|
||||
self.post_message(Notification(
|
||||
channel=channel,
|
||||
source=source,
|
||||
title="没有刷新到任何站点数据!",
|
||||
userid=userid
|
||||
userid=userid,
|
||||
save_history=False,
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user