From 81153eb3f0ef8dba89137af646438f6b7fd754ad Mon Sep 17 00:00:00 2001 From: KafCoppelia <740677208@qq.com> Date: Mon, 12 Jun 2023 09:40:26 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20fix:=20=E4=BF=AE=E5=A4=8D=20?= =?UTF-8?q?pre-commit-hook=20=E5=AF=BC=E8=87=B4=20`import`=20=E9=A1=BA?= =?UTF-8?q?=E5=BA=8F=E6=94=B9=E5=8F=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pre-commit-config.yaml | 7 ++++--- README.md | 4 ++-- nonebot_plugin_fortune/__init__.py | 4 ++-- pyproject.toml | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 44903b5..73a6389 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,10 +12,10 @@ repos: - id: isort stages: [commit] - - repo: https://github.com/pre-commit/mirrors-autopep8 - rev: v2.0.2 + - repo: https://github.com/psf/black + rev: 23.3.0 hooks: - - id: autopep8 + - id: black stages: [commit] - repo: https://github.com/pre-commit/mirrors-prettier @@ -34,3 +34,4 @@ repos: - id: check-added-large-files - id: mixed-line-ending - id: check-json + - id: check-toml diff --git a/README.md b/README.md index 929be28..050e90d 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ _🙏 今日运势 🙏_ - + @@ -35,7 +35,7 @@ _🙏 今日运势 🙏_ ## 版本 -[v0.4.11](https://github.com/MinatoAquaCrews/nonebot_plugin_fortune/releases/tag/v0.4.11) +[v0.4.11.post1](https://github.com/MinatoAquaCrews/nonebot_plugin_fortune/releases/tag/v0.4.11.post1) ⚠️ 适配nonebot2-2.0.0rc4+ diff --git a/nonebot_plugin_fortune/__init__.py b/nonebot_plugin_fortune/__init__.py index faff9da..aa588e8 100644 --- a/nonebot_plugin_fortune/__init__.py +++ b/nonebot_plugin_fortune/__init__.py @@ -1,4 +1,3 @@ -from nonebot_plugin_apscheduler import scheduler from typing import Annotated from nonebot import on_command, on_fullmatch, on_regex, require @@ -15,8 +14,9 @@ from .data_source import FortuneManager, fortune_manager require("nonebot_plugin_apscheduler") +from nonebot_plugin_apscheduler import scheduler # isort:skip -__fortune_version__ = "v0.4.11" +__fortune_version__ = "v0.4.11.post1" __fortune_usages__ = f""" [今日运势/抽签/运势] 一般抽签 [xx抽签] 指定主题抽签 diff --git a/pyproject.toml b/pyproject.toml index dd90687..a9ca5aa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "nonebot_plugin_fortune" -version = "0.4.11" +version = "0.4.11.post1" description = "Fortune divination!" authors = ["KafCoppelia "] license = "MIT" From 46b48ea0fbc438ef2fe296bdda7b7469888d611e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 12 Jun 2023 01:41:48 +0000 Subject: [PATCH 2/2] :rotating_light: auto fix by pre-commit hooks --- nonebot_plugin_fortune/__init__.py | 32 ++++++++++++++------------ nonebot_plugin_fortune/config.py | 33 ++++++++++----------------- nonebot_plugin_fortune/data_source.py | 9 ++++---- nonebot_plugin_fortune/download.py | 3 +-- nonebot_plugin_fortune/utils.py | 8 +++---- 5 files changed, 38 insertions(+), 47 deletions(-) diff --git a/nonebot_plugin_fortune/__init__.py b/nonebot_plugin_fortune/__init__.py index aa588e8..d91258c 100644 --- a/nonebot_plugin_fortune/__init__.py +++ b/nonebot_plugin_fortune/__init__.py @@ -1,9 +1,14 @@ from typing import Annotated from nonebot import on_command, on_fullmatch, on_regex, require -from nonebot.adapters.onebot.v11 import (GROUP, GROUP_ADMIN, GROUP_OWNER, - GroupMessageEvent, Message, - MessageSegment) +from nonebot.adapters.onebot.v11 import ( + GROUP, + GROUP_ADMIN, + GROUP_OWNER, + GroupMessageEvent, + Message, + MessageSegment, +) from nonebot.log import logger from nonebot.matcher import Matcher from nonebot.params import CommandArg, Depends, RegexStr @@ -14,7 +19,7 @@ from .data_source import FortuneManager, fortune_manager require("nonebot_plugin_apscheduler") -from nonebot_plugin_apscheduler import scheduler # isort:skip +from nonebot_plugin_apscheduler import scheduler # isort:skip __fortune_version__ = "v0.4.11.post1" __fortune_usages__ = f""" @@ -36,8 +41,7 @@ }, ) -general_divine = on_command( - "今日运势", aliases={"抽签", "运势"}, permission=GROUP, priority=8) +general_divine = on_command("今日运势", aliases={"抽签", "运势"}, permission=GROUP, priority=8) specific_divine = on_regex(r"^[^/]\S+抽签$", permission=GROUP, priority=8) limit_setting = on_regex(r"^指定(.*?)签$", permission=GROUP, priority=8) change_theme = on_regex( @@ -89,8 +93,7 @@ async def _(event: GroupMessageEvent, args: Annotated[Message, CommandArg()]): ) else: logger.info(f"User {uid} | Group {gid} 占卜了今日运势") - msg = MessageSegment.text("✨今日运势✨\n") + \ - MessageSegment.image(image_file) + msg = MessageSegment.text("✨今日运势✨\n") + MessageSegment.image(image_file) await general_divine.finish(msg, at_sender=True) @@ -111,8 +114,7 @@ async def _( gid: str = str(event.group_id) uid: str = str(event.user_id) - is_first, image_file = fortune_manager.divine( - gid, uid, theme, None) + is_first, image_file = fortune_manager.divine(gid, uid, theme, None) if image_file is None: await specific_divine.finish("今日运势生成出错……") @@ -140,7 +142,9 @@ async def get_user_arg(matcher: Matcher, args: Annotated[str, RegexStr()]) -> st @change_theme.handle() -async def _(event: GroupMessageEvent, user_theme: Annotated[str, Depends(get_user_arg)]): +async def _( + event: GroupMessageEvent, user_theme: Annotated[str, Depends(get_user_arg)] +): gid: str = str(event.group_id) for theme in FortuneThemesDict: @@ -169,8 +173,7 @@ async def _(event: GroupMessageEvent, limit: Annotated[str, Depends(get_user_arg if not spec_path: await limit_setting.finish("还不可以指定这种签哦,请确认该签底对应主题开启或图片路径存在~") else: - is_first, image_file = fortune_manager.divine( - gid, uid, None, spec_path) + is_first, image_file = fortune_manager.divine(gid, uid, None, spec_path) if image_file is None: await limit_setting.finish("今日运势生成出错……") @@ -180,8 +183,7 @@ async def _(event: GroupMessageEvent, limit: Annotated[str, Depends(get_user_arg ) else: logger.info(f"User {uid} | Group {gid} 占卜了今日运势") - msg = MessageSegment.text("✨今日运势✨\n") + \ - MessageSegment.image(image_file) + msg = MessageSegment.text("✨今日运势✨\n") + MessageSegment.image(image_file) await limit_setting.finish(msg, at_sender=True) diff --git a/nonebot_plugin_fortune/config.py b/nonebot_plugin_fortune/config.py index 15f2593..7f95894 100644 --- a/nonebot_plugin_fortune/config.py +++ b/nonebot_plugin_fortune/config.py @@ -98,8 +98,7 @@ def default(self, obj) -> Union[str, Any]: driver = get_driver() fortune_config: PluginConfig = PluginConfig.parse_obj(driver.config.dict()) -themes_flag_config: ThemesFlagConfig = ThemesFlagConfig.parse_obj( - driver.config.dict()) +themes_flag_config: ThemesFlagConfig = ThemesFlagConfig.parse_obj(driver.config.dict()) @driver.on_startup @@ -129,8 +128,7 @@ async def fortune_check() -> None: ret = await download_resource(copywriting_path, "copywriting.json", "fortune") if not ret and not copywriting_path.exists(): - raise ResourceError( - "Resource copywriting.json is missing! Please check!") + raise ResourceError("Resource copywriting.json is missing! Please check!") """ Check rules and data files @@ -141,8 +139,7 @@ async def fortune_check() -> None: specific_rules_path: Path = fortune_config.fortune_path / "specific_rules.json" if not fortune_data_path.exists(): - logger.warning( - "Resource fortune_data.json is missing, initialized one...") + logger.warning("Resource fortune_data.json is missing, initialized one...") with fortune_data_path.open("w", encoding="utf-8") as f: json.dump(dict(), f, ensure_ascii=False, indent=4) @@ -181,18 +178,17 @@ async def fortune_check() -> None: try: is_divined: bool = _data[gid][uid].pop( - "is_divined") # type: ignore + "is_divined" + ) # type: ignore if is_divined: - _data[gid][uid].update( - {"last_sign_date": date.today()}) + _data[gid][uid].update({"last_sign_date": date.today()}) else: _data[gid][uid].update({"last_sign_date": 0}) except KeyError: pass with open(fortune_data_path, "w", encoding="utf-8") as f: - json.dump(_data, f, ensure_ascii=False, - indent=4, cls=DateTimeEncoder) + json.dump(_data, f, ensure_ascii=False, indent=4, cls=DateTimeEncoder) _flag: bool = False if not group_rules_path.exists(): @@ -201,8 +197,7 @@ async def fortune_check() -> None: # Try to transfer from the old setting json ret = group_rules_transfer(fortune_setting_path, group_rules_path) if ret: - logger.info( - "旧版 fortune_setting.json 文件中群聊抽签主题设置已更新至 group_rules.json") + logger.info("旧版 fortune_setting.json 文件中群聊抽签主题设置已更新至 group_rules.json") _flag = True if not _flag: @@ -210,22 +205,19 @@ async def fortune_check() -> None: with group_rules_path.open("w", encoding="utf-8") as f: json.dump(dict(), f, ensure_ascii=False, indent=4) - logger.info( - "旧版 fortune_setting.json 文件中群聊抽签主题设置不存在,初始化 group_rules.json") + logger.info("旧版 fortune_setting.json 文件中群聊抽签主题设置不存在,初始化 group_rules.json") _flag = False if not specific_rules_path.exists(): # In version 0.4.9 and 0.4.10, data transfering will be done automatically if specific_rules.json doesn't exist if fortune_setting_path.exists(): # Try to transfer from the old setting json - ret = specific_rules_transfer( - fortune_setting_path, specific_rules_path) + ret = specific_rules_transfer(fortune_setting_path, specific_rules_path) if ret: # Delete the old fortune_setting json if the transfer is OK fortune_setting_path.unlink() - logger.info( - "旧版 fortune_setting.json 文件中签底指定规则已更新至 specific_rules.json") + logger.info("旧版 fortune_setting.json 文件中签底指定规则已更新至 specific_rules.json") logger.warning("指定签底抽签功能将在 v0.5.0 弃用") _flag = True @@ -272,8 +264,7 @@ def specific_rules_transfer( with open(fortune_setting_dir, "r", encoding="utf-8") as f: _setting: Dict[str, Dict[str, Union[str, List[str]]]] = json.load(f) - specific_rules = _setting.get( - "specific_rule", None) # Old key is specific_rule + specific_rules = _setting.get("specific_rule", None) # Old key is specific_rule with open(specific_rules_dir, "w", encoding="utf-8") as f: if not specific_rules: diff --git a/nonebot_plugin_fortune/data_source.py b/nonebot_plugin_fortune/data_source.py index e0a2a7a..6406dd7 100644 --- a/nonebot_plugin_fortune/data_source.py +++ b/nonebot_plugin_fortune/data_source.py @@ -10,8 +10,7 @@ class FortuneManager: def __init__(self): - self._user_data: Dict[str, Dict[str, - Dict[str, Union[str, int, date]]]] = dict() + self._user_data: Dict[str, Dict[str, Dict[str, Union[str, int, date]]]] = dict() self._group_rules: Dict[str, str] = dict() self._specific_rules: Dict[str, List[str]] = dict() self._user_data_file: Path = fortune_config.fortune_path / "fortune_data.json" @@ -32,7 +31,8 @@ def _multi_divine_check(self, gid: str, uid: str, nowtime: date) -> bool: last_sign_date: datetime = datetime.strptime( # type: ignore - self._user_data[gid][uid]["last_sign_date"], "%Y-%m-%d" + self._user_data[gid][uid]["last_sign_date"], + "%Y-%m-%d", ) return last_sign_date.date() == nowtime @@ -84,8 +84,7 @@ def divine( self._end_data_handle(gid, uid, now_time) return True, img_path else: - img_path: Path = fortune_config.fortune_path / \ - "out" / f"{gid}_{uid}.png" + img_path: Path = fortune_config.fortune_path / "out" / f"{gid}_{uid}.png" return False, img_path @staticmethod diff --git a/nonebot_plugin_fortune/download.py b/nonebot_plugin_fortune/download.py index a08fe4c..c8b57e2 100644 --- a/nonebot_plugin_fortune/download.py +++ b/nonebot_plugin_fortune/download.py @@ -27,8 +27,7 @@ async def download_url(url: str) -> Optional[Dict[str, Any]]: return resp.json() except Exception: - logger.warning( - f"Error occurred when downloading {url}, retry: {i+1}/3") + logger.warning(f"Error occurred when downloading {url}, retry: {i+1}/3") logger.warning("Abort downloading") return None diff --git a/nonebot_plugin_fortune/utils.py b/nonebot_plugin_fortune/utils.py index c493f10..1111958 100644 --- a/nonebot_plugin_fortune/utils.py +++ b/nonebot_plugin_fortune/utils.py @@ -135,21 +135,21 @@ def decrement(text: str) -> Tuple[int, List[str]]: fillIn = space * int(9 - length / 2) return col_num, [ text[: int(length / 2)] + fillIn, - fillIn + text[int(length / 2):], + fillIn + text[int(length / 2) :], ] else: # odd number fillIn = space * int(9 - (length + 1) / 2) return col_num, [ text[: int((length + 1) / 2)] + fillIn, - fillIn + space + text[int((length + 1) / 2):], + fillIn + space + text[int((length + 1) / 2) :], ] for i in range(col_num): if i == col_num - 1 or col_num == 1: - result.append(text[i * cardinality:]) + result.append(text[i * cardinality :]) else: - result.append(text[i * cardinality: (i + 1) * cardinality]) + result.append(text[i * cardinality : (i + 1) * cardinality]) return col_num, result