From 540877427776236bb42e8458d30c397a800fa20a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 5 Feb 2024 20:35:14 +0000 Subject: [PATCH] :rotating_light: auto fix by pre-commit hooks --- sora/log.py | 4 +--- sora/permission.py | 1 + sora/plugins/ban/__init__.py | 5 ++++- sora/plugins/bot_admin/__init__.py | 12 ++++++++--- sora/plugins/hooks/user_exist.py | 1 + sora/plugins/sora_bind/__init__.py | 27 ++++++++++++++++++------ sora/plugins/sora_manager/__init__.py | 10 +++++---- sora/plugins/sora_manager/data_source.py | 4 +++- sora/plugins/sora_sign/__init__.py | 18 ++++++++++------ sora/utils/requests.py | 8 +++++-- sora/utils/update.py | 8 +++++-- 11 files changed, 70 insertions(+), 28 deletions(-) diff --git a/sora/log.py b/sora/log.py index 1c9dd4e..7979ef2 100644 --- a/sora/log.py +++ b/sora/log.py @@ -25,9 +25,7 @@ def info( result_str = ( f"{escape_tag(result)}" if result_type - else f"{escape_tag(result)}" - if result - else "" + else f"{escape_tag(result)}" if result else "" ) nb_logger.opt(colors=True).info( f"[{command}]{info}{param_str}{result_str}" diff --git a/sora/permission.py b/sora/permission.py index e5bb3e0..29bd5f6 100644 --- a/sora/permission.py +++ b/sora/permission.py @@ -26,6 +26,7 @@ ``` """ + from nonebot.internal.adapter.event import Event from nonebot.internal.permission import Permission as Permission diff --git a/sora/plugins/ban/__init__.py b/sora/plugins/ban/__init__.py index a7a6120..6ecd527 100644 --- a/sora/plugins/ban/__init__.py +++ b/sora/plugins/ban/__init__.py @@ -76,7 +76,10 @@ async def add( else: minutes_result = 0 hours_result = hours.result - logger.info("封禁", f"封禁目标:{target_id},时长:{hours_result}小时{minutes_result}分钟") + logger.info( + "封禁", + f"封禁目标:{target_id},时长:{hours_result}小时{minutes_result}分钟", + ) await BanUser.ban( target_id, duration=convert_to_seconds(hours_result, minutes_result) ) diff --git a/sora/plugins/bot_admin/__init__.py b/sora/plugins/bot_admin/__init__.py index a7e91cb..64d61d8 100644 --- a/sora/plugins/bot_admin/__init__.py +++ b/sora/plugins/bot_admin/__init__.py @@ -118,7 +118,9 @@ async def add( elif helper_who.result == 0: ... else: - await MessageFactory(f"用户 {helper_who.result} 不存在").send(at_sender=True) + await MessageFactory(f"用户 {helper_who.result} 不存在").send( + at_sender=True + ) await bot_admin.finish() @@ -152,7 +154,9 @@ async def remove( elif helper_who.result == 0: ... else: - await MessageFactory(f"用户 {helper_who.result} 不存在").send(at_sender=True) + await MessageFactory(f"用户 {helper_who.result} 不存在").send( + at_sender=True + ) await bot_admin.finish() @@ -163,4 +167,6 @@ async def atuhorize_admin(): global authorize authorize = random_text(20) logger.info("Admin", f"已自动生成授权token:{authorize}") - logger.info("Admin", f"在任意平台发送 /admin -i {authorize} 即可获取 Bot管理员 权限") + logger.info( + "Admin", f"在任意平台发送 /admin -i {authorize} 即可获取 Bot管理员 权限" + ) diff --git a/sora/plugins/hooks/user_exist.py b/sora/plugins/hooks/user_exist.py index d66d253..c3d7d42 100644 --- a/sora/plugins/hooks/user_exist.py +++ b/sora/plugins/hooks/user_exist.py @@ -3,6 +3,7 @@ 用来在处理事件前先判断用户是否存在 如果不存在则自动为其注册账号 """ + import os import shutil diff --git a/sora/plugins/sora_bind/__init__.py b/sora/plugins/sora_bind/__init__.py index 92714d8..7192202 100644 --- a/sora/plugins/sora_bind/__init__.py +++ b/sora/plugins/sora_bind/__init__.py @@ -49,7 +49,12 @@ "绑定", Args["input_token?", str], Option("-t|--token", Args["token?", str], help_text="生成token"), - Option("-l|--list", Args["who?", At], alias={"列表", "信息"}, help_text="查询绑定信息"), + Option( + "-l|--list", + Args["who?", At], + alias={"列表", "信息"}, + help_text="查询绑定信息", + ), Option("-r|--rebind", alias={"取消"}, help_text="取消绑定"), meta=CommandMeta( description="绑定", @@ -90,7 +95,9 @@ async def bind_( else: await MessageFactory("绑定失败,密钥错误!").send(at_sender=True) else: - await MessageFactory("格式错误。输入 /help 绑定 查看其详细用法").send(at_sender=True) + await MessageFactory("格式错误。输入 /help 绑定 查看其详细用法").send( + at_sender=True + ) token_manager.remove_token(validation_result.user_id) # type: ignore await bind.finish() @@ -105,14 +112,20 @@ async def token_( if token.result == "random": random_token = random_text(15, prefix="Sora/") token_manager.add_token(user_id=user.user_id, token=random_token) - await MessageFactory(f"已为您生成一次性token:{random_token}").send(at_sender=True) + await MessageFactory(f"已为您生成一次性token:{random_token}").send( + at_sender=True + ) else: token_manager.add_token(user_id=user.user_id, token=token.result) - await MessageFactory(f"一次性token设置成功:{token.result}").send(at_sender=True) + await MessageFactory(f"一次性token设置成功:{token.result}").send( + at_sender=True + ) else: random_token = random_text(15, prefix="Sora/") token_manager.add_token(user_id=user.user_id, token=random_token) - await MessageFactory(f"已为您生成一次性token:{random_token}\n").send(at_sender=True) + await MessageFactory(f"已为您生成一次性token:{random_token}\n").send( + at_sender=True + ) await bind.finish() @@ -129,7 +142,9 @@ async def bind_list_( df = pd.DataFrame(bindInfo) await MessageFactory(df.to_string(index=False)).send(at_sender=True) else: - await MessageFactory("该用户已设置 “不允许查看绑定资料”").send(at_sender=True) + await MessageFactory("该用户已设置 “不允许查看绑定资料”").send( + at_sender=True + ) await bind.finish() bindInfo = await UserBind.get_bind_info(event.get_user_id()) diff --git a/sora/plugins/sora_manager/__init__.py b/sora/plugins/sora_manager/__init__.py index 0e911ee..b39da9a 100644 --- a/sora/plugins/sora_manager/__init__.py +++ b/sora/plugins/sora_manager/__init__.py @@ -105,9 +105,9 @@ async def _(): l_v, l_v_t = await CheckUpdate.show_latest_version() if l_v and l_v_t: if l_v != __version__: - await MessageFactory(f"新版本已发布, 请更新\n最新版本: {l_v} 更新时间: {l_v_t}").send( - at_sender=True - ) + await MessageFactory( + f"新版本已发布, 请更新\n最新版本: {l_v} 更新时间: {l_v_t}" + ).send(at_sender=True) else: await MessageFactory("当前已是最新版本").send(at_sender=True) await check_update_cmd.finish() @@ -135,7 +135,9 @@ async def _(state: T_State, cmd: Match[str] = AlconnaMatch("cmd")): state["cmd"] = cmd -@run_cmd.got("cmd", prompt="你输入你要运行的命令", parameterless=[HandleCancellation("已取消")]) +@run_cmd.got( + "cmd", prompt="你输入你要运行的命令", parameterless=[HandleCancellation("已取消")] +) async def _(cmd: str = ArgPlainText("cmd")): await MessageFactory(f"开始执行{cmd}...").send(at_sender=True) p = await asyncio.subprocess.create_subprocess_shell( diff --git a/sora/plugins/sora_manager/data_source.py b/sora/plugins/sora_manager/data_source.py index ce2e45e..b08273b 100644 --- a/sora/plugins/sora_manager/data_source.py +++ b/sora/plugins/sora_manager/data_source.py @@ -27,7 +27,9 @@ async def remind(bot: V11Bot | GuildBot | TGBot): "python3 bot.py" ) os.system("chmod +x ./restart.sh") - logger.info("配置", "已自动生成 restart.sh 重启脚本,请检查脚本是否与本地指令符合..") + logger.info( + "配置", "已自动生成 restart.sh 重启脚本,请检查脚本是否与本地指令符合.." + ) is_restart_file = Path() / "is_restart" if is_restart_file.exists(): if isinstance(bot, V11Bot): diff --git a/sora/plugins/sora_sign/__init__.py b/sora/plugins/sora_sign/__init__.py index a1ea7a8..f1248c3 100644 --- a/sora/plugins/sora_sign/__init__.py +++ b/sora/plugins/sora_sign/__init__.py @@ -53,7 +53,9 @@ sign = on_alconna( Alconna( "签到", - Option("info", Args["target?", At | int], alias={"信息"}, help_text="获取签到信息"), + Option( + "info", Args["target?", At | int], alias={"信息"}, help_text="获取签到信息" + ), Option("rank", alias={"排行", "排行榜"}, help_text="当日签到排行榜"), Option("rank2", alias={"总排行", "排行榜"}, help_text="签到总排行"), meta=CommandMeta( @@ -91,7 +93,9 @@ async def sign_(userInfo: UserInfo): user_id = userInfo.user_id if user_id is None: - await MessageFactory("该账号暂未注册林汐账户,请先发送 [/注册] ").send(at_sender=True) + await MessageFactory("该账号暂未注册林汐账户,请先发送 [/注册] ").send( + at_sender=True + ) await sign.finish() user_sign = await UserSign.get_or_none(user_id=user_id).values( "total_days", "continuous_days", "last_day" @@ -156,7 +160,9 @@ async def sign_(userInfo: UserInfo): async def info_(userInfo: UserInfo): user_id = userInfo.user_id if user_id is None: - await MessageFactory("该账号未注册,请先发送 [/注册] 注册林汐账户").send(at_sender=True) + await MessageFactory("该账号未注册,请先发送 [/注册] 注册林汐账户").send( + at_sender=True + ) await info.finish() user_avatar = get_user_avatar(user_id) @@ -201,9 +207,9 @@ async def sign_info( total_days, continuous_days = await UserSign.get_user_sign_info(target_id) - await MessageFactory(f"{call}当前连续签到 {continuous_days} 天,累计 {total_days} 天").send( - at_sender=True - ) + await MessageFactory( + f"{call}当前连续签到 {continuous_days} 天,累计 {total_days} 天" + ).send(at_sender=True) await sign.finish() diff --git a/sora/utils/requests.py b/sora/utils/requests.py index 1528a23..45c6567 100644 --- a/sora/utils/requests.py +++ b/sora/utils/requests.py @@ -169,7 +169,9 @@ async def download_file( ).content async with aiofiles.open(path, "wb") as wf: await wf.write(content) - logger.success("请求", f"下载 {url} 成功!Path:{path.absolute()}") + logger.success( + "请求", f"下载 {url} 成功!Path:{path.absolute()}" + ) return True except (TimeoutError, ConnectTimeout): pass @@ -221,7 +223,9 @@ async def download_file( else: logger.error("请求", f"下载 {url} 下载超时!Path:{path.absolute()}") except Exception as e: - logger.error("请求", f"下载 {url} 未知错误 {type(e)}:{e} | Path:{path.absolute()}") + logger.error( + "请求", f"下载 {url} 未知错误 {type(e)}:{e} | Path:{path.absolute()}" + ) return False @classmethod diff --git a/sora/utils/update.py b/sora/utils/update.py index a34f196..41d24f9 100644 --- a/sora/utils/update.py +++ b/sora/utils/update.py @@ -38,7 +38,9 @@ def update(): pyproject_new_content = pyproject_raw_content.replace( raw_plugins_load.group(), "plugins = []" ) - logger.info("更新", f"检测到已安装插件:{raw_plugins_load.group()},暂时重置") + logger.info( + "更新", f"检测到已安装插件:{raw_plugins_load.group()},暂时重置" + ) else: pyproject_new_content = pyproject_raw_content pyproject_file.write_text(pyproject_new_content, encoding="utf-8") @@ -64,7 +66,9 @@ def update(): "plugins = []", raw_plugins_load.group() ) pyproject_file.write_text(pyproject_new_content, encoding="utf-8") - logger.info("更新", f"更新结束,还原插件:{raw_plugins_load.group()}") + logger.info( + "更新", f"更新结束,还原插件:{raw_plugins_load.group()}" + ) return msg else: msg = f"更新失败,错误信息:{e.stderr},请尝试手动进行更新"