From 2b4384b64d00d934a4bfedcd3f4dfcf7598f5e2a Mon Sep 17 00:00:00 2001 From: Neko Aria <990879119@qq.com> Date: Thu, 23 Mar 2023 00:42:36 +0800 Subject: [PATCH] v2.6.16 (#409) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: 引入格式化工具配置和代码检查工具配置 * fix: 修正 `nonebot_plugin_guild_patch` 的导入时机 * refactor(routes): 使用自动扫描的方式自动导入路由规则 * fix: 修正一些代码检查问题 * chore(release): v2.6.16 --- .github/renovate.json | 3 ++- .pre-commit-config.yaml | 13 +++++++++++ pyproject.toml | 14 ++++++++++- src/plugins/ELF_RSS2/__init__.py | 2 +- src/plugins/ELF_RSS2/command/add_dy.py | 7 +++--- src/plugins/ELF_RSS2/command/change_dy.py | 8 +++---- src/plugins/ELF_RSS2/command/del_dy.py | 8 +++---- src/plugins/ELF_RSS2/command/rsshub_add.py | 6 ++--- src/plugins/ELF_RSS2/command/show_all.py | 8 +++---- src/plugins/ELF_RSS2/command/show_dy.py | 8 +++---- src/plugins/ELF_RSS2/parsing/__init__.py | 2 +- src/plugins/ELF_RSS2/parsing/handle_images.py | 4 ++-- .../ELF_RSS2/parsing/routes/__init__.py | 23 ++++++++++--------- src/plugins/ELF_RSS2/rss_parsing.py | 6 ++++- 14 files changed, 72 insertions(+), 40 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.github/renovate.json b/.github/renovate.json index 15318137..b680f6bf 100644 --- a/.github/renovate.json +++ b/.github/renovate.json @@ -6,9 +6,10 @@ "dependencyDashboard": false, "rangeStrategy": "bump", "enabledManagers": [ + "github-actions", "pip_requirements", "poetry", - "github-actions" + "pre-commit" ], "packageRules": [ { diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..a65d1ccc --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,13 @@ +minimum_pre_commit_version: "3.2.0" +files: ^.*\.py$ +repos: + - repo: https://github.com/charliermarsh/ruff-pre-commit + rev: 'v0.0.257' + hooks: + - id: ruff + args: + - --fix + - repo: https://github.com/psf/black + rev: 23.1.0 + hooks: + - id: black \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index bc5b57c7..f2c7e695 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "ELF_RSS" -version = "2.6.15" +version = "2.6.16" description = "QQ机器人 RSS订阅 插件,订阅源建议选择 RSSHub" authors = ["Quan666 "] license = "GPL-3.0-only" @@ -42,12 +42,24 @@ nb-cli = "^1.0.5" [tool.mypy] python_version = "3.8" +plugins = [ + "pydantic.mypy" +] ignore_missing_imports = true implicit_reexport = true pretty = true show_error_codes = true strict = true +[tool.ruff] +select = ["F", "E", "W", "I"] +target-version = "py38" +line-length = 120 + +[tool.ruff.per-file-ignores] +"__init__.py" = ["F401"] +"*.py" = ["E402", "F811"] + [build-system] requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" diff --git a/src/plugins/ELF_RSS2/__init__.py b/src/plugins/ELF_RSS2/__init__.py index 78a9fcfd..738d4918 100644 --- a/src/plugins/ELF_RSS2/__init__.py +++ b/src/plugins/ELF_RSS2/__init__.py @@ -14,7 +14,7 @@ require("nonebot_plugin_apscheduler") from nonebot_plugin_apscheduler import scheduler # noqa -VERSION = "2.6.15" +VERSION = "2.6.16" __plugin_meta__ = PluginMetadata( name="ELF_RSS", diff --git a/src/plugins/ELF_RSS2/command/add_dy.py b/src/plugins/ELF_RSS2/command/add_dy.py index 49e357c2..41221319 100644 --- a/src/plugins/ELF_RSS2/command/add_dy.py +++ b/src/plugins/ELF_RSS2/command/add_dy.py @@ -13,13 +13,14 @@ from nonebot.permission import SUPERUSER from nonebot.rule import to_me +require("nonebot_plugin_guild_patch") # noqa +from nonebot_plugin_guild_patch import GuildMessageEvent # noqa +from nonebot_plugin_guild_patch.permission import GUILD_ADMIN, GUILD_OWNER # noqa + from .. import my_trigger as tr from ..permission import GUILD_SUPERUSER from ..rss_class import Rss -require("nonebot_plugin_guild_patch") -from nonebot_plugin_guild_patch import GuildMessageEvent # noqa -from nonebot_plugin_guild_patch.permission import GUILD_ADMIN, GUILD_OWNER # noqa RSS_ADD = on_command( "add", diff --git a/src/plugins/ELF_RSS2/command/change_dy.py b/src/plugins/ELF_RSS2/command/change_dy.py index 9f307939..a1c12782 100644 --- a/src/plugins/ELF_RSS2/command/change_dy.py +++ b/src/plugins/ELF_RSS2/command/change_dy.py @@ -12,16 +12,16 @@ from nonebot.permission import SUPERUSER from nonebot.rule import to_me +require("nonebot_plugin_guild_patch") # noqa +from nonebot_plugin_guild_patch import GuildMessageEvent # noqa +from nonebot_plugin_guild_patch.permission import GUILD_ADMIN, GUILD_OWNER # noqa + from .. import my_trigger as tr from ..config import DATA_PATH from ..permission import GUILD_SUPERUSER from ..rss_class import Rss from ..utils import regex_validate -require("nonebot_plugin_guild_patch") -from nonebot_plugin_guild_patch import GuildMessageEvent # noqa -from nonebot_plugin_guild_patch.permission import GUILD_ADMIN, GUILD_OWNER # noqa - RSS_CHANGE = on_command( "change", aliases={"修改订阅", "modify"}, diff --git a/src/plugins/ELF_RSS2/command/del_dy.py b/src/plugins/ELF_RSS2/command/del_dy.py index b628eb0e..9be17ada 100644 --- a/src/plugins/ELF_RSS2/command/del_dy.py +++ b/src/plugins/ELF_RSS2/command/del_dy.py @@ -6,14 +6,14 @@ from nonebot.permission import SUPERUSER from nonebot.rule import to_me +require("nonebot_plugin_guild_patch") # noqa +from nonebot_plugin_guild_patch import GuildMessageEvent # noqa +from nonebot_plugin_guild_patch.permission import GUILD_ADMIN, GUILD_OWNER # noqa + from .. import my_trigger as tr from ..permission import GUILD_SUPERUSER from ..rss_class import Rss -require("nonebot_plugin_guild_patch") -from nonebot_plugin_guild_patch import GuildMessageEvent # noqa -from nonebot_plugin_guild_patch.permission import GUILD_ADMIN, GUILD_OWNER # noqa - RSS_DELETE = on_command( "deldy", aliases={"drop", "unsub", "删除订阅"}, diff --git a/src/plugins/ELF_RSS2/command/rsshub_add.py b/src/plugins/ELF_RSS2/command/rsshub_add.py index 2c43841e..5db5b414 100644 --- a/src/plugins/ELF_RSS2/command/rsshub_add.py +++ b/src/plugins/ELF_RSS2/command/rsshub_add.py @@ -11,14 +11,14 @@ from nonebot.typing import T_State from yarl import URL +require("nonebot_plugin_guild_patch") # noqa +from nonebot_plugin_guild_patch.permission import GUILD_ADMIN, GUILD_OWNER # noqa + from ..config import config from ..permission import GUILD_SUPERUSER from ..rss_class import Rss from .add_dy import add_feed -require("nonebot_plugin_guild_patch") -from nonebot_plugin_guild_patch.permission import GUILD_ADMIN, GUILD_OWNER # noqa - rsshub_routes: Dict[str, Any] = {} diff --git a/src/plugins/ELF_RSS2/command/show_all.py b/src/plugins/ELF_RSS2/command/show_all.py index a02c536d..1e90ac17 100644 --- a/src/plugins/ELF_RSS2/command/show_all.py +++ b/src/plugins/ELF_RSS2/command/show_all.py @@ -13,14 +13,14 @@ from nonebot.permission import SUPERUSER from nonebot.rule import to_me +require("nonebot_plugin_guild_patch") # noqa +from nonebot_plugin_guild_patch import GuildMessageEvent # noqa +from nonebot_plugin_guild_patch.permission import GUILD_ADMIN, GUILD_OWNER # noqa + from ..permission import GUILD_SUPERUSER from ..rss_class import Rss from .show_dy import handle_rss_list -require("nonebot_plugin_guild_patch") -from nonebot_plugin_guild_patch import GuildMessageEvent # noqa -from nonebot_plugin_guild_patch.permission import GUILD_ADMIN, GUILD_OWNER # noqa - RSS_SHOW_ALL = on_command( "show_all", aliases={"showall", "select_all", "selectall", "所有订阅"}, diff --git a/src/plugins/ELF_RSS2/command/show_dy.py b/src/plugins/ELF_RSS2/command/show_dy.py index 37da84bf..7abf92d7 100644 --- a/src/plugins/ELF_RSS2/command/show_dy.py +++ b/src/plugins/ELF_RSS2/command/show_dy.py @@ -7,13 +7,13 @@ from nonebot.permission import SUPERUSER from nonebot.rule import to_me -from ..permission import GUILD_SUPERUSER -from ..rss_class import Rss - -require("nonebot_plugin_guild_patch") +require("nonebot_plugin_guild_patch") # noqa from nonebot_plugin_guild_patch import GuildMessageEvent # noqa from nonebot_plugin_guild_patch.permission import GUILD_ADMIN, GUILD_OWNER # noqa +from ..permission import GUILD_SUPERUSER +from ..rss_class import Rss + RSS_SHOW = on_command( "show", aliases={"查看订阅"}, diff --git a/src/plugins/ELF_RSS2/parsing/__init__.py b/src/plugins/ELF_RSS2/parsing/__init__.py index bb46f398..84e1017c 100644 --- a/src/plugins/ELF_RSS2/parsing/__init__.py +++ b/src/plugins/ELF_RSS2/parsing/__init__.py @@ -22,7 +22,7 @@ from .handle_images import handle_img from .handle_translation import handle_translation from .parsing_rss import ParsingBase -from .routes import * +from .routes import ALL_MODULES from .send_message import handle_send_msgs from .utils import get_proxy, get_summary diff --git a/src/plugins/ELF_RSS2/parsing/handle_images.py b/src/plugins/ELF_RSS2/parsing/handle_images.py index 4c1dadc4..76362e39 100644 --- a/src/plugins/ELF_RSS2/parsing/handle_images.py +++ b/src/plugins/ELF_RSS2/parsing/handle_images.py @@ -276,8 +276,8 @@ def file_name_format(file_url: URL, rss: Rss) -> Tuple[Path, str]: """ 可以根据用户设置的规则来格式化文件名 """ - format_rule = config.img_format - down_path = config.img_down_path + format_rule = config.img_format or "" + down_path = config.img_down_path or "" rules = { # 替换格式化字符串 "{subs}": rss.name, "{name}": file_url.name diff --git a/src/plugins/ELF_RSS2/parsing/routes/__init__.py b/src/plugins/ELF_RSS2/parsing/routes/__init__.py index 2c8cb670..e8fa1468 100644 --- a/src/plugins/ELF_RSS2/parsing/routes/__init__.py +++ b/src/plugins/ELF_RSS2/parsing/routes/__init__.py @@ -1,11 +1,12 @@ -from . import ( - bilibili, - danbooru, - nga, - pixiv, - south_plus, - twitter, - weibo, - yande_re, - youtube, -) +from typing import List + + +def __list_all_modules() -> List[str]: + from pathlib import Path + + module_paths = list(Path(__file__).parent.glob("*.py")) + return [module.name[:-3] for module in module_paths if module.name != "__init__.py"] + + +ALL_MODULES = sorted(__list_all_modules()) +__all__ = ALL_MODULES + ["ALL_MODULES"] diff --git a/src/plugins/ELF_RSS2/rss_parsing.py b/src/plugins/ELF_RSS2/rss_parsing.py index b675bef2..4a832940 100644 --- a/src/plugins/ELF_RSS2/rss_parsing.py +++ b/src/plugins/ELF_RSS2/rss_parsing.py @@ -29,7 +29,11 @@ "Accept": "application/xhtml+xml,application/xml,*/*", "Accept-Language": "en-US,en;q=0.9", "Cache-Control": "max-age=0", - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36", + "User-Agent": ( + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " + "AppleWebKit/537.36 (KHTML, like Gecko) " + "Chrome/111.0.0.0 Safari/537.36" + ), "Connection": "keep-alive", "Content-Type": "application/xml; charset=utf-8", }