From c726864412f01721d0137d6cc06ea2f5b192ddbc Mon Sep 17 00:00:00 2001 From: jxxghp Date: Wed, 14 Jun 2023 16:48:55 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E7=AB=99=E7=82=B9=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chain/site_manage.py | 54 ++++++++++++++++++++++++++++++++ app/chain/subscribe.py | 12 +++++-- app/command.py | 11 +++++++ app/db/sites.py | 12 +++++++ app/modules/slack/slack.py | 2 +- app/modules/telegram/telegram.py | 4 +-- 6 files changed, 90 insertions(+), 5 deletions(-) create mode 100644 app/chain/site_manage.py diff --git a/app/chain/site_manage.py b/app/chain/site_manage.py new file mode 100644 index 00000000..86028364 --- /dev/null +++ b/app/chain/site_manage.py @@ -0,0 +1,54 @@ +from app.chain import ChainBase +from app.db.sites import Sites + + +class SiteManageChain(ChainBase): + """ + 站点远程管理处理链 + """ + + _sites: Sites = None + + def __init__(self): + super().__init__() + self._sites = Sites() + + def process(self): + """ + 查询所有站点,发送消息 + """ + site_list = self._sites.list() + if not site_list: + self.post_message(title="没有维护任何站点信息!") + title = f"共有 {len(site_list)} 个站点,回复 `/site_disable` `[id]` 禁用站点:" + messages = [] + for site in site_list: + if site.render: + render_str = " [仿真]" + else: + render_str = "" + if site.is_active: + messages.append(f"{site.id}. {site.name}({site.url}){render_str}") + else: + messages.append(f"{site.id}. ~~{site.name}({site.url}){render_str}~~") + # 发送列表 + self.post_message(title=title, text="\n".join(messages)) + + def disable(self, arg_str): + """ + 禁用站点 + """ + if not arg_str: + return + arg_str = arg_str.strip() + if not arg_str.isdigit(): + return + site_id = int(arg_str) + site = self._sites.get(site_id) + if not site: + self.post_message(title=f"站点编号 {site_id} 不存在!") + return + # 删除站点 + self._sites.delete(site_id) + # 重新发送消息 + self.process() diff --git a/app/chain/subscribe.py b/app/chain/subscribe.py index fc1dff18..5d46c373 100644 --- a/app/chain/subscribe.py +++ b/app/chain/subscribe.py @@ -64,6 +64,7 @@ class SubscribeChain(ChainBase): if mediainfo.type == MediaType.TV: if not season: season = 1 + # 总集数 if not kwargs.get('total_episode'): if not mediainfo.seasons: # 补充媒体信息 @@ -82,6 +83,11 @@ class SubscribeChain(ChainBase): kwargs.update({ 'total_episode': total_episode }) + # 缺失集 + if not kwargs.get('lack_episode'): + kwargs.update({ + 'lack_episode': kwargs.get('total_episode') + }) # 添加订阅 sid, err_msg = self.subscribes.add(mediainfo, season=season, **kwargs) if not sid: @@ -297,13 +303,15 @@ class SubscribeChain(ChainBase): if not subscribes: self.post_message(title='没有任何订阅!') return - title = f"共有 {len(subscribes)} 个订阅,回复```/subscribe_delete [id]```删除订阅:" + title = f"共有 {len(subscribes)} 个订阅,回复 `/subscribe_delete` `[id]` 删除订阅:" messages = [] for subscribe in subscribes: if subscribe.type == MediaType.MOVIE.value: messages.append(f"{subscribe.id}. {subscribe.name}({subscribe.year})") else: - messages.append(f"{subscribe.id}. {subscribe.name}({subscribe.year})第{subscribe.season}季") + messages.append(f"{subscribe.id}. {subscribe.name}({subscribe.year})第{subscribe.season}季 " + f"[{subscribe.total_episode - (subscribe.lack_episode or subscribe.total_episode)}" + f"/{subscribe.total_episode}]") # 发送列表 self.post_message(title=title, text='\n'.join(messages)) diff --git a/app/command.py b/app/command.py index 02d5d834..b5ae9c82 100644 --- a/app/command.py +++ b/app/command.py @@ -5,6 +5,7 @@ from typing import Any from app.chain import ChainBase from app.chain.cookiecloud import CookieCloudChain from app.chain.douban_sync import DoubanSyncChain +from app.chain.site_manage import SiteManageChain from app.chain.subscribe import SubscribeChain from app.chain.transfer import TransferChain from app.core.event import eventmanager, EventManager @@ -77,6 +78,16 @@ class Command(metaclass=Singleton): "func": TransferChain().process, "description": "下载文件整理", "data": {} + }, + "/sites": { + "func": SiteManageChain().process, + "description": "查询站点", + "data": {} + }, + "/site_disable": { + "func": SiteManageChain().disable, + "description": "禁用站点", + "data": {} } } plugin_commands = self.pluginmanager.get_plugin_commands() diff --git a/app/db/sites.py b/app/db/sites.py index 67a4f114..d71654a8 100644 --- a/app/db/sites.py +++ b/app/db/sites.py @@ -25,6 +25,12 @@ class Sites: return True, "新增站点成功" return False, "站点已存在" + def get(self, sid: int): + """ + 查询单个站点 + """ + return Site.get(self._db, sid) + def list(self) -> List[Site]: """ 获取站点列表 @@ -37,6 +43,12 @@ class Sites: """ return Site.get_actives(self._db) + def delete(self, sid: int): + """ + 删除站点 + """ + return Site.delete(self._db, sid) + def get_by_domain(self, domain: str) -> Site: """ 按域名获取站点 diff --git a/app/modules/slack/slack.py b/app/modules/slack/slack.py index 59e1ce2b..0f7c1274 100644 --- a/app/modules/slack/slack.py +++ b/app/modules/slack/slack.py @@ -248,7 +248,7 @@ class Slack: "type": "section", "text": { "type": "mrkdwn", - "text": f"*{title}*" + "text": f"**{title}**" } } blocks = [title_section, { diff --git a/app/modules/telegram/telegram.py b/app/modules/telegram/telegram.py index 0033c1c7..41a2441c 100644 --- a/app/modules/telegram/telegram.py +++ b/app/modules/telegram/telegram.py @@ -79,9 +79,9 @@ class Telegram(metaclass=Singleton): try: if text: - caption = f"*{title}*\n{text}" + caption = f"**{title}**\n{text}" else: - caption = f"*{title}*" + caption = f"**{title}**" if userid: chat_id = userid