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 Feb 5, 2024
1 parent e5fb6df commit 5408774
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 28 deletions.
4 changes: 1 addition & 3 deletions sora/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ def info(
result_str = (
f"<g>{escape_tag(result)}</g>"
if result_type
else f"<r>{escape_tag(result)}</r>"
if result
else ""
else f"<r>{escape_tag(result)}</r>" if result else ""
)
nb_logger.opt(colors=True).info(
f"<u><y>[{command}]</y></u>{info}{param_str}{result_str}"
Expand Down
1 change: 1 addition & 0 deletions sora/permission.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
```
"""

from nonebot.internal.adapter.event import Event
from nonebot.internal.permission import Permission as Permission

Expand Down
5 changes: 4 additions & 1 deletion sora/plugins/ban/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand Down
12 changes: 9 additions & 3 deletions sora/plugins/bot_admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand All @@ -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管理员 权限"
)
1 change: 1 addition & 0 deletions sora/plugins/hooks/user_exist.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
用来在处理事件前先判断用户是否存在
如果不存在则自动为其注册账号
"""

import os
import shutil

Expand Down
27 changes: 21 additions & 6 deletions sora/plugins/sora_bind/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="绑定",
Expand Down Expand Up @@ -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()
Expand All @@ -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()


Expand All @@ -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())
Expand Down
10 changes: 6 additions & 4 deletions sora/plugins/sora_manager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion sora/plugins/sora_manager/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
18 changes: 12 additions & 6 deletions sora/plugins/sora_sign/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()


Expand Down
8 changes: 6 additions & 2 deletions sora/utils/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions sora/utils/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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},请尝试手动进行更新"
Expand Down

0 comments on commit 5408774

Please sign in to comment.