Skip to content

Commit

Permalink
🚨 auto fix by pre-commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Nov 4, 2024
1 parent a06a2ff commit 243caff
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 16 deletions.
20 changes: 12 additions & 8 deletions nonebot_plugin_fortune/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
},
)

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(
Expand Down Expand Up @@ -91,9 +93,9 @@ async def _(event: GroupMessageEvent, args: Annotated[Message, CommandArg()]):
await general_divine.finish("今日运势生成出错……")

if not is_first:
msg = MessageSegment.text("你今天抽过签了,再给你看一次哦🤗\n") + MessageSegment.image(
image_file
)
msg = MessageSegment.text(
"你今天抽过签了,再给你看一次哦🤗\n"
) + MessageSegment.image(image_file)
else:
logger.info(f"User {uid} | Group {gid} 占卜了今日运势")
msg = MessageSegment.text("✨今日运势✨\n") + MessageSegment.image(image_file)
Expand Down Expand Up @@ -174,16 +176,18 @@ async def _(event: GroupMessageEvent, limit: Annotated[str, Depends(get_user_arg
else:
spec_path = fortune_manager.specific_check(limit)
if not spec_path:
await limit_setting.finish("还不可以指定这种签哦,请确认该签底对应主题开启或图片路径存在~")
await limit_setting.finish(
"还不可以指定这种签哦,请确认该签底对应主题开启或图片路径存在~"
)
else:
is_first, image_file = fortune_manager.divine(gid, uid, None, spec_path)
if image_file is None:
await limit_setting.finish("今日运势生成出错……")

if not is_first:
msg = MessageSegment.text("你今天抽过签了,再给你看一次哦🤗\n") + MessageSegment.image(
image_file
)
msg = MessageSegment.text(
"你今天抽过签了,再给你看一次哦🤗\n"
) + MessageSegment.image(image_file)
else:
logger.info(f"User {uid} | Group {gid} 占卜了今日运势")
msg = MessageSegment.text("✨今日运势✨\n") + MessageSegment.image(image_file)
Expand Down
29 changes: 22 additions & 7 deletions nonebot_plugin_fortune/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@
"einstein": ["爱因斯坦携爱敬上", "爱因斯坦", "einstein", "Einstein"],
"genshin": ["原神", "Genshin Impact", "genshin", "Genshin", "op", "原批"],
"granblue_fantasy": ["碧蓝幻想", "Granblue Fantasy", "granblue fantasy", "幻想"],
"hololive": ["Hololive", "hololive", "Vtb", "vtb", "管人", "Holo", "holo", "管人痴"],
"hololive": [
"Hololive",
"hololive",
"Vtb",
"vtb",
"管人",
"Holo",
"holo",
"管人痴",
],
"hoshizora": ["星空列车与白的旅行", "星空列车"],
"liqingge": ["李清歌", "清歌"],
"onmyoji": ["阴阳师", "yys", "Yys", "痒痒鼠"],
Expand Down Expand Up @@ -156,9 +165,9 @@ async def fortune_check() -> None:
2. Transfer the key "is_divined" to "last_sign_date"
"""
with open(fortune_data_path, "r", encoding="utf-8") as f:
_data: Dict[
str, Dict[str, Dict[str, Union[str, bool, int, date]]]
] = json.load(f)
_data: Dict[str, Dict[str, Dict[str, Union[str, bool, int, date]]]] = (
json.load(f)
)

for gid in _data:
if _data[gid]:
Expand Down Expand Up @@ -203,15 +212,19 @@ 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:
# If failed or fortune_setting_path doesn't exist, initialize group_rules.json instead
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():
Expand All @@ -223,7 +236,9 @@ async def fortune_check() -> None:
# 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

Expand Down
4 changes: 3 additions & 1 deletion nonebot_plugin_fortune/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ async def download_resource(
Try to download resources, json but not images.
For fonts & copywriting, download and save into files when missing. Otherwise, raise ResourceError.
"""
base_url: str = "https://raw.fgit.ml/MinatoAquaCrews/nonebot_plugin_fortune/master/nonebot_plugin_fortune/resource"
base_url: str = (
"https://raw.fgit.ml/MinatoAquaCrews/nonebot_plugin_fortune/master/nonebot_plugin_fortune/resource"
)

if isinstance(_type, str):
url: str = base_url + "/" + _type + "/" + name
Expand Down

0 comments on commit 243caff

Please sign in to comment.