fix commands
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import base64
|
||||
from typing import Tuple, Optional
|
||||
from typing import Tuple, Optional, Union
|
||||
from urllib.parse import urljoin
|
||||
|
||||
from lxml import etree
|
||||
@ -30,6 +30,18 @@ class CookieCloudChain(ChainBase):
|
||||
password=settings.COOKIECLOUD_PASSWORD
|
||||
)
|
||||
|
||||
def remote_sync(self, userid: Union[int, str]):
|
||||
"""
|
||||
远程触发同步站点,发送消息
|
||||
"""
|
||||
self.post_message(title="开始同步CookieCloud站点 ...", userid=userid)
|
||||
# 开始同步
|
||||
success, msg = self.process()
|
||||
if success:
|
||||
self.post_message(title=f"同步站点成功,{msg}", userid=userid)
|
||||
else:
|
||||
self.post_message(title=f"同步站点失败:{msg}", userid=userid)
|
||||
|
||||
def process(self) -> Tuple[bool, str]:
|
||||
"""
|
||||
通过CookieCloud同步站点Cookie
|
||||
|
@ -1,5 +1,5 @@
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
from typing import Optional, Union
|
||||
|
||||
from app.chain import ChainBase
|
||||
from app.chain.download import DownloadChain
|
||||
@ -28,6 +28,14 @@ class DoubanChain(ChainBase):
|
||||
self.searchchain = SearchChain()
|
||||
self.subscribechain = SubscribeChain()
|
||||
|
||||
def remote_sync(self, userid: Union[int, str]):
|
||||
"""
|
||||
同步豆瓣想看数据,发送消息
|
||||
"""
|
||||
self.post_message(title="开始同步豆瓣想看 ...", userid=userid)
|
||||
self.sync()
|
||||
self.post_message(title="同步豆瓣想看数据完成!", userid=userid)
|
||||
|
||||
def sync(self):
|
||||
"""
|
||||
通过用户RSS同步豆瓣想看数据
|
||||
|
@ -509,7 +509,7 @@ class DownloadChain(ChainBase):
|
||||
# 全部存在
|
||||
return True, no_exists
|
||||
|
||||
def get_downloading(self, userid: Union[str, int] = None):
|
||||
def remote_downloading(self, userid: Union[str, int] = None):
|
||||
"""
|
||||
查询正在下载的任务,并发送消息
|
||||
"""
|
||||
|
@ -63,7 +63,6 @@ class MessageChain(ChainBase):
|
||||
"user": userid
|
||||
}
|
||||
)
|
||||
self.post_message(title=f"正在运行,请稍候 ...", userid=userid)
|
||||
|
||||
elif text.isdigit():
|
||||
# 缓存
|
||||
|
@ -1,7 +1,8 @@
|
||||
from typing import Union
|
||||
from typing import Union, Tuple
|
||||
|
||||
from app.chain import ChainBase
|
||||
from app.core.config import settings
|
||||
from app.db.models.site import Site
|
||||
from app.db.site_oper import SiteOper
|
||||
from app.helper.cookie import CookieHelper
|
||||
from app.log import logger
|
||||
@ -20,7 +21,7 @@ class SiteChain(ChainBase):
|
||||
self._siteoper = SiteOper()
|
||||
self._cookiehelper = CookieHelper()
|
||||
|
||||
def list(self, userid: Union[str, int] = None):
|
||||
def remote_list(self, userid: Union[str, int] = None):
|
||||
"""
|
||||
查询所有站点,发送消息
|
||||
"""
|
||||
@ -44,7 +45,7 @@ class SiteChain(ChainBase):
|
||||
# 发送列表
|
||||
self.post_message(title=title, text="\n".join(messages), userid=userid)
|
||||
|
||||
def disable(self, arg_str, userid: Union[str, int] = None):
|
||||
def remote_disable(self, arg_str, userid: Union[str, int] = None):
|
||||
"""
|
||||
禁用站点
|
||||
"""
|
||||
@ -63,9 +64,9 @@ class SiteChain(ChainBase):
|
||||
"is_active": False
|
||||
})
|
||||
# 重新发送消息
|
||||
self.list()
|
||||
self.remote_list()
|
||||
|
||||
def enable(self, arg_str, userid: Union[str, int] = None):
|
||||
def remote_enable(self, arg_str, userid: Union[str, int] = None):
|
||||
"""
|
||||
启用站点
|
||||
"""
|
||||
@ -84,9 +85,36 @@ class SiteChain(ChainBase):
|
||||
"is_active": True
|
||||
})
|
||||
# 重新发送消息
|
||||
self.list()
|
||||
self.remote_list()
|
||||
|
||||
def get_cookie(self, arg_str: str, userid: Union[str, int] = None):
|
||||
def update_cookie(self, site_info: Site,
|
||||
username: str, password: str) -> Tuple[bool, str]:
|
||||
"""
|
||||
根据用户名密码更新站点Cookie
|
||||
:param site_info: 站点信息
|
||||
:param username: 用户名
|
||||
:param password: 密码
|
||||
:return: (是否成功, 错误信息)
|
||||
"""
|
||||
# 更新站点Cookie
|
||||
result = self._cookiehelper.get_site_cookie_ua(
|
||||
url=site_info.url,
|
||||
username=username,
|
||||
password=password,
|
||||
proxies=settings.PROXY_HOST if site_info.proxy else None
|
||||
)
|
||||
if result:
|
||||
cookie, ua, msg = result
|
||||
if not cookie:
|
||||
return False, msg
|
||||
self._siteoper.update(site_info.id, {
|
||||
"cookie": cookie,
|
||||
"ua": ua
|
||||
})
|
||||
return True, msg
|
||||
return False, "未知错误"
|
||||
|
||||
def remote_cookie(self, arg_str: str, userid: Union[str, int] = None):
|
||||
"""
|
||||
使用用户名密码更新站点Cookie
|
||||
"""
|
||||
@ -111,28 +139,20 @@ class SiteChain(ChainBase):
|
||||
if not site_info:
|
||||
self.post_message(title=f"站点编号 {site_id} 不存在!", userid=userid)
|
||||
return
|
||||
self.post_message(title=f"开始更新【{site_info.name}】Cookie&UA ...", userid=userid)
|
||||
# 用户名
|
||||
username = args[1]
|
||||
# 密码
|
||||
password = args[2]
|
||||
# 更新站点Cookie
|
||||
result = self._cookiehelper.get_site_cookie_ua(
|
||||
url=site_info.url,
|
||||
username=username,
|
||||
password=password,
|
||||
proxies=settings.PROXY_HOST if site_info.proxy else None
|
||||
)
|
||||
if result:
|
||||
cookie, ua, msg = result
|
||||
if not cookie:
|
||||
logger.error(msg)
|
||||
self.post_message(title=f"【{site_info.name}】 Cookie&UA更新失败!",
|
||||
text=f"错误原因:{msg}",
|
||||
userid=userid)
|
||||
return
|
||||
self._siteoper.update(site_id, {
|
||||
"cookie": cookie,
|
||||
"ua": ua
|
||||
})
|
||||
# 更新Cookie
|
||||
status, msg = self.update_cookie(site_info=site_info,
|
||||
username=username,
|
||||
password=password)
|
||||
if not status:
|
||||
logger.error(msg)
|
||||
self.post_message(title=f"【{site_info.name}】 Cookie&UA更新失败!",
|
||||
text=f"错误原因:{msg}",
|
||||
userid=userid)
|
||||
else:
|
||||
self.post_message(title=f"【{site_info.name}】 Cookie&UA更新成功",
|
||||
userid=userid)
|
||||
|
@ -108,6 +108,37 @@ class SubscribeChain(ChainBase):
|
||||
# 返回结果
|
||||
return sid
|
||||
|
||||
def remote_refresh(self, userid: Union[str, int] = None):
|
||||
"""
|
||||
远程刷新订阅,发送消息
|
||||
"""
|
||||
self.post_message(title=f"开始刷新订阅 ...", userid=userid)
|
||||
self.refresh()
|
||||
self.post_message(title=f"订阅刷新完成!", userid=userid)
|
||||
|
||||
def remote_search(self, arg_str: str, userid: Union[str, int] = None):
|
||||
"""
|
||||
远程搜索订阅,发送消息
|
||||
"""
|
||||
if arg_str and not str(arg_str).isdigit():
|
||||
self.post_message(title="请输入正确的命令格式:/subscribe_search [id],"
|
||||
"[id]为订阅编号,不输入订阅编号时搜索所有订阅", userid=userid)
|
||||
return
|
||||
if arg_str:
|
||||
sid = int(arg_str)
|
||||
subscribe = self.subscribehelper.get(sid)
|
||||
if not subscribe:
|
||||
self.post_message(title=f"订阅编号 {sid} 不存在!", userid=userid)
|
||||
return
|
||||
self.post_message(title=f"开始搜索 {subscribe.name} ...", userid=userid)
|
||||
# 搜索订阅
|
||||
self.search(sid=int(arg_str))
|
||||
self.post_message(title=f"{subscribe.name} 搜索完成!", userid=userid)
|
||||
else:
|
||||
self.post_message(title=f"开始搜索所有订阅 ...", userid=userid)
|
||||
self.search(state='R')
|
||||
self.post_message(title=f"订阅搜索完成!", userid=userid)
|
||||
|
||||
def search(self, sid: int = None, state: str = 'N'):
|
||||
"""
|
||||
订阅搜索
|
||||
@ -325,7 +356,7 @@ class SubscribeChain(ChainBase):
|
||||
"lack_episode": len(left_episodes)
|
||||
})
|
||||
|
||||
def list(self, userid: Union[str, int] = None):
|
||||
def remote_list(self, userid: Union[str, int] = None):
|
||||
"""
|
||||
查询订阅并发送消息
|
||||
"""
|
||||
@ -334,7 +365,9 @@ class SubscribeChain(ChainBase):
|
||||
self.post_message(title='没有任何订阅!', userid=userid)
|
||||
return
|
||||
title = f"共有 {len(subscribes)} 个订阅,回复对应指令操作: " \
|
||||
f"\n- 删除订阅:/subscribe_delete [id]"
|
||||
f"\n- 删除订阅:/subscribe_delete [id]" \
|
||||
f"\n- 搜索订阅:/subscribe_search [id]" \
|
||||
f"\n- 刷新订阅:/subscribe_refresh"
|
||||
messages = []
|
||||
for subscribe in subscribes:
|
||||
if subscribe.type == MediaType.MOVIE.value:
|
||||
@ -349,7 +382,7 @@ class SubscribeChain(ChainBase):
|
||||
# 发送列表
|
||||
self.post_message(title=title, text='\n'.join(messages), userid=userid)
|
||||
|
||||
def delete(self, arg_str: str, userid: Union[str, int] = None):
|
||||
def remote_delete(self, arg_str: str, userid: Union[str, int] = None):
|
||||
"""
|
||||
删除订阅
|
||||
"""
|
||||
@ -366,7 +399,7 @@ class SubscribeChain(ChainBase):
|
||||
# 删除订阅
|
||||
self.subscribehelper.delete(subscribe_id)
|
||||
# 重新发送消息
|
||||
self.list()
|
||||
self.remote_list()
|
||||
|
||||
@staticmethod
|
||||
def __get_subscribe_no_exits(no_exists: Dict[int, Dict[int, NotExistMediaInfo]],
|
||||
|
Reference in New Issue
Block a user