Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pikpak): 修复导入错误 #487

Merged
merged 5 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ELF_RSS"
version = "2.6.21"
version = "2.6.22"
description = "QQ机器人 RSS订阅 插件,订阅源建议选择 RSSHub"
authors = ["Quan666 <[email protected]>"]
license = "GPL-3.0-only"
Expand Down Expand Up @@ -30,7 +30,7 @@ nonebot-plugin-guild-patch = "^0.2.3"
nonebot2 = {extras = ["fastapi"], version = "^2.1.1"}
pikpakapi = "^0.1.3"
Pillow = "^10.1.0"
pydantic = "^1.10.13"
pydantic = ">=1.10.0,<3.0.0,!=2.5.0,!=2.5.1"
pyquery = "^2.0.0"
python-qbittorrent = "^0.4.3"
tenacity = "^8.2.3"
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ nonebot-plugin-guild-patch~=0.2.3
nonebot2[fastapi]~=2.1.1
pikpakapi~=0.1.3
Pillow~=10.1.0
pydantic~=1.10.13
pydantic>=1.10.0,<3.0.0,!=2.5.0,!=2.5.1
pyquery~=2.0.0
python-qbittorrent~=0.4.3
tenacity~=8.2.3
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/ELF_RSS2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from .rss_class import Rss
from .utils import send_message_to_admin

VERSION = "2.6.21"
VERSION = "2.6.22"

__plugin_meta__ = PluginMetadata(
name="ELF_RSS",
Expand All @@ -34,7 +34,9 @@ def check_first_connect(_: LifecycleMetaEvent) -> bool:


start_metaevent = on_metaevent(rule=check_first_connect, temp=True)
FIRST_BOOT_MESSAGE = "首次启动,目前没有订阅,请添加!\n另外,请检查配置文件的内容(详见部署教程)!"
FIRST_BOOT_MESSAGE = (
"首次启动,目前没有订阅,请添加!\n另外,请检查配置文件的内容(详见部署教程)!"
)
BOOT_SUCCESS_MESSAGE = "ELF_RSS 订阅器启动成功!"


Expand Down
24 changes: 18 additions & 6 deletions src/plugins/ELF_RSS2/command/change_dy.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ async def filter_rss_by_permissions(
) -> List[Rss]:
if group_id:
if re.search(" (qq|qun|channel)=", change_info):
await RSS_CHANGE.finish("❌ 禁止在群组中修改订阅账号!如要取消订阅请使用 deldy 命令!")
await RSS_CHANGE.finish(
"❌ 禁止在群组中修改订阅账号!如要取消订阅请使用 deldy 命令!"
)
rss_list = [
rss
for rss in rss_list
Expand All @@ -222,7 +224,9 @@ async def filter_rss_by_permissions(

if guild_channel_id:
if re.search(" (qq|qun|channel)=", change_info):
await RSS_CHANGE.finish("❌ 禁止在子频道中修改订阅账号!如要取消订阅请使用 deldy 命令!")
await RSS_CHANGE.finish(
"❌ 禁止在子频道中修改订阅账号!如要取消订阅请使用 deldy 命令!"
)
rss_list = [
rss
for rss in rss_list
Expand All @@ -232,7 +236,9 @@ async def filter_rss_by_permissions(
]

if not rss_list:
await RSS_CHANGE.finish("❌ 请检查是否存在以下问题:\n1.要修改的订阅名不存在对应的记录\n2.当前群组或频道无权操作")
await RSS_CHANGE.finish(
"❌ 请检查是否存在以下问题:\n1.要修改的订阅名不存在对应的记录\n2.当前群组或频道无权操作"
)

return rss_list

Expand Down Expand Up @@ -285,16 +291,22 @@ async def validate_rss_change(key_to_change: str, value_to_change: str) -> None:
if key_to_change == "mode" and (
set(value_to_change.split(",")) - mode_property_set or value_to_change == "or"
):
await RSS_CHANGE.finish(f"❌ 去重模式参数错误!\n{key_to_change}={value_to_change}")
await RSS_CHANGE.finish(
f"❌ 去重模式参数错误!\n{key_to_change}={value_to_change}"
)
elif key_to_change in {
"downkey",
"wkey",
"blackkey",
"bkey",
} and not regex_validate(value_to_change.lstrip("+-")):
await RSS_CHANGE.finish(f"❌ 正则表达式错误!\n{key_to_change}={value_to_change}")
await RSS_CHANGE.finish(
f"❌ 正则表达式错误!\n{key_to_change}={value_to_change}"
)
elif key_to_change == "ppk" and not regex_validate(value_to_change):
await RSS_CHANGE.finish(f"❌ 正则表达式错误!\n{key_to_change}={value_to_change}")
await RSS_CHANGE.finish(
f"❌ 正则表达式错误!\n{key_to_change}={value_to_change}"
)


async def batch_change_rss(
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/ELF_RSS2/command/del_dy.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ async def handle_rss_delete(
result = []
if delete_successes:
if guild_channel_id:
result.append(f'👏 当前子频道成功取消订阅: {"、".join(delete_successes)} !')
result.append(
f'👏 当前子频道成功取消订阅: {"、".join(delete_successes)} !'
)
elif group_id:
result.append(f'👏 当前群组成功取消订阅: {"、".join(delete_successes)} !')
else:
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/ELF_RSS2/command/rsshub_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ async def handle_rsshub_routes(
async with aiohttp.ClientSession() as session:
resp = await session.get(rsshub_url.with_path("api/routes"), proxy=proxy)
if resp.status != 200:
await RSSHUB_ADD.finish("获取路由数据失败,请检查 RSSHub 的地址配置及网络连接")
await RSSHUB_ADD.finish(
"获取路由数据失败,请检查 RSSHub 的地址配置及网络连接"
)
rsshub_routes = await resp.json()

if route not in rsshub_routes["data"]:
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/ELF_RSS2/command/show_dy.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@

def handle_rss_list(rss_list: List[Rss]) -> str:
rss_info_list = [
f"(已停止){i.name}:{i.url}" if i.stop else f"{i.name}:{i.url}" for i in rss_list
f"(已停止){i.name}:{i.url}" if i.stop else f"{i.name}:{i.url}"
for i in rss_list
]
return "\n\n".join(rss_info_list)

Expand Down
12 changes: 9 additions & 3 deletions src/plugins/ELF_RSS2/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ class Config:
limit: int = 200
max_length: int = 1024 # 正文长度限制,防止消息太长刷屏,以及消息过长发送失败的情况
enable_boot_message: bool = True # 是否启用启动时的提示消息推送
debug: bool = False # 是否开启 debug 模式,开启后会打印更多的日志信息,同时检查更新时不会使用缓存,便于调试
debug: bool = (
False # 是否开启 debug 模式,开启后会打印更多的日志信息,同时检查更新时不会使用缓存,便于调试
)

zip_size: int = 2 * 1024
gif_zip_size: int = 6 * 1024
Expand All @@ -43,7 +45,9 @@ class Config:
qb_username: Optional[str] = None # qbittorrent 用户名
qb_password: Optional[str] = None # qbittorrent 密码
qb_web_url: Optional[str] = None # qbittorrent 的 web 地址
qb_down_path: Optional[str] = None # qb 的文件下载地址,这个地址必须是 go-cqhttp 能访问到的
qb_down_path: Optional[str] = (
None # qb 的文件下载地址,这个地址必须是 go-cqhttp 能访问到的
)
down_status_msg_group: Optional[List[int]] = None # 下载进度消息提示群组
down_status_msg_date: int = 10 # 下载进度检查及提示间隔时间,单位秒

Expand All @@ -52,7 +56,9 @@ class Config:
# pikpak 离线保存的目录, 默认是根目录,示例: ELF_RSS/Downloads ,目录不存在会自动创建, 不能/结尾
pikpak_download_path: str = ""

telegram_admin_ids: List[int] = [] # Telegram 管理员 ID 列表,用于接收离线通知和管理机器人
telegram_admin_ids: List[int] = (
[]
) # Telegram 管理员 ID 列表,用于接收离线通知和管理机器人
telegram_bot_token: Optional[str] = None # Telegram 机器人的 token


Expand Down
6 changes: 3 additions & 3 deletions src/plugins/ELF_RSS2/parsing/handle_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,9 @@ def file_name_format(file_url: URL, rss: Rss) -> Tuple[Path, str]:
down_path = config.img_down_path or ""
rules = { # 替换格式化字符串
"{subs}": rss.name,
"{name}": file_url.name
if "{ext}" not in format_rule
else Path(file_url.name).stem,
"{name}": (
file_url.name if "{ext}" not in format_rule else Path(file_url.name).stem
),
"{ext}": file_url.suffix if "{ext}" in format_rule else "",
}
for k, v in rules.items():
Expand Down
16 changes: 9 additions & 7 deletions src/plugins/ELF_RSS2/pikpak_offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

from nonebot.log import logger
from pikpakapi import PikPakApi
from pikpakapi.PikpakException import PikpakAccessTokenExpireException, PikpakException
from pikpakapi.PikpakException import PikpakException

from .config import config

pikpak_client = PikPakApi(
username=config.pikpak_username,
password=config.pikpak_password,
)
pikpak_client: Optional[PikPakApi] = None
if config.pikpak_username and config.pikpak_password:
pikpak_client = PikPakApi(
username=config.pikpak_username,
password=config.pikpak_password,
)


async def refresh_access_token() -> None:
Expand All @@ -19,7 +21,7 @@ async def refresh_access_token() -> None:
"""
try:
await pikpak_client.refresh_access_token()
except (PikpakException, PikpakAccessTokenExpireException) as e:
except PikpakException as e:
logger.warning(f"refresh_access_token {e}")
await pikpak_client.login()

Expand Down Expand Up @@ -102,7 +104,7 @@ async def pikpak_offline_download(
if path_ids and len(path_ids) > 0:
parent_id = path_ids[-1].get("id")
return await pikpak_client.offline_download(url, parent_id=parent_id, name=name) # type: ignore
except (PikpakAccessTokenExpireException, PikpakException) as e:
except PikpakException as e:
logger.warning(e)
await refresh_access_token()
return await pikpak_offline_download(
Expand Down
11 changes: 9 additions & 2 deletions src/plugins/ELF_RSS2/qbittorrent_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ async def upload_files_to_groups(
name=tmp["name"],
)
except ActionFailed:
msg = f"{name}\nHash:{hash_str}\n上传到群:{group_id}失败!请手动上传!"
msg = (
f"{name}\nHash:{hash_str}\n上传到群:{group_id}失败!请手动上传!"
)
await send_msg(bot, msg, [group_id])
logger.exception(msg)
except (NetworkError, TimeoutError) as e:
Expand Down Expand Up @@ -246,7 +248,12 @@ async def rss_trigger(bot: Bot, hash_str: str, group_ids: List[str], name: str)
scheduler.add_job(
func=check_down_status, # 要添加任务的函数,不要带参数
trigger=trigger, # 触发器
args=(bot, hash_str, group_ids, name), # 函数的参数列表,注意:只有一个值时,不能省略末尾的逗号
args=(
bot,
hash_str,
group_ids,
name,
), # 函数的参数列表,注意:只有一个值时,不能省略末尾的逗号
id=hash_str,
misfire_grace_time=60, # 允许的误差时间,建议不要省略
job_defaults=job_defaults,
Expand Down
10 changes: 8 additions & 2 deletions src/plugins/ELF_RSS2/rss_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def __init__(self, data: Optional[Dict[str, Any]] = None):
self.pikpak_path_key: str = (
"" # PikPak 离线下载路径匹配正则表达式,用于自动归档文件 例如 r"(?:\[.*?\][\s\S])([\s\S]*)[\s\S]-"
)
self.send_forward_msg: bool = False # 当一次更新多条消息时,是否尝试发送合并消息
self.send_forward_msg: bool = (
False # 当一次更新多条消息时,是否尝试发送合并消息
)
if data:
self.__dict__.update(data)

Expand Down Expand Up @@ -248,7 +250,11 @@ def _generate_feature_string(feature: str, value: Any) -> str:
_generate_feature_string("黑名单关键词", self.black_keyword),
_generate_feature_string("cookies", self.cookies),
"种子自动下载功能已启用" if self.down_torrent else "",
"" if self.is_open_upload_group else f"是否上传到群:{self.is_open_upload_group}",
(
""
if self.is_open_upload_group
else f"是否上传到群:{self.is_open_upload_group}"
),
mode_msg,
_generate_feature_string("图片数量限制", self.max_image_number),
_generate_feature_string("正文待移除内容", self.content_to_remove),
Expand Down
4 changes: 1 addition & 3 deletions src/plugins/ELF_RSS2/rss_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,7 @@ async def auto_stop_and_notify_admin(rss: Rss, bot: Bot) -> None:
if not any([rss.user_id, rss.group_id, rss.guild_channel_id]):
msg = f"{rss.name}[{rss.get_url()}]无人订阅!已自动停止更新!"
elif rss.error_count >= 100:
msg = (
f"{rss.name}[{rss.get_url()}]已经连续抓取失败超过 100 次!已自动停止更新!请检查订阅地址{cookies_str}!"
)
msg = f"{rss.name}[{rss.get_url()}]已经连续抓取失败超过 100 次!已自动停止更新!请检查订阅地址{cookies_str}!"
else:
msg = f"{rss.name}[{rss.get_url()}]第一次抓取失败!已自动停止更新!请检查订阅地址{cookies_str}!"
await send_message_to_admin(msg, bot)
Expand Down
8 changes: 6 additions & 2 deletions src/plugins/ELF_RSS2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ async def filter_valid_user_id_list(bot: Bot, user_id_list: List[str]) -> List[s
if invalid_user_id_list := [
user_id for user_id in user_id_list if user_id not in valid_user_id_list
]:
logger.warning(f"QQ号[{','.join(invalid_user_id_list)}]不是Bot[{bot.self_id}]的好友")
logger.warning(
f"QQ号[{','.join(invalid_user_id_list)}]不是Bot[{bot.self_id}]的好友"
)
return valid_user_id_list


Expand All @@ -180,7 +182,9 @@ async def filter_valid_group_id_list(bot: Bot, group_id_list: List[str]) -> List
if invalid_group_id_list := [
group_id for group_id in group_id_list if group_id not in valid_group_id_list
]:
logger.warning(f"Bot[{bot.self_id}]未加入群组[{','.join(invalid_group_id_list)}]")
logger.warning(
f"Bot[{bot.self_id}]未加入群组[{','.join(invalid_group_id_list)}]"
)
return valid_group_id_list


Expand Down