refactor code

This commit is contained in:
hibiki
2021-07-30 21:21:51 +08:00
parent 2ad891aa1e
commit cc24822dca
165 changed files with 7815 additions and 8174 deletions
+17 -16
View File
@@ -9,11 +9,11 @@ from utils.utils import scheduler, get_bot, UserExistLimiter
from configs.config import UPDATE_GOCQ_GROUP
from pathlib import Path
__plugin_name__ = '更新gocq'
__plugin_name__ = "更新gocq"
__plugin_usage__ = '用法:发送’更新gocq‘,指定群 自动检测最新版gocq下载并上传'
__plugin_usage__ = "用法:发送’更新gocq‘,指定群 自动检测最新版gocq下载并上传"
path = str((Path() / "resources" / "gocqhttp_file").absolute()) + '/'
path = str((Path() / "resources" / "gocqhttp_file").absolute()) + "/"
lasted_gocqhttp = on_command("更新gocq", permission=GROUP, priority=5, block=True)
@@ -25,26 +25,26 @@ _ulmt = UserExistLimiter()
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
# try:
if event.group_id in UPDATE_GOCQ_GROUP:
await lasted_gocqhttp.send('检测中...')
await lasted_gocqhttp.send("检测中...")
info = await download_gocq_lasted(path)
if info == 'gocqhttp没有更新!':
await lasted_gocqhttp.finish('gocqhttp没有更新!')
if info == "gocqhttp没有更新!":
await lasted_gocqhttp.finish("gocqhttp没有更新!")
if _ulmt.check(event.group_id):
await lasted_gocqhttp.finish('gocqhttp正在更新,请勿重复使用该命令', at_sender=True)
await lasted_gocqhttp.finish("gocqhttp正在更新,请勿重复使用该命令", at_sender=True)
_ulmt.set_True(event.group_id)
try:
for file in os.listdir(path):
await upload_gocq_lasted(path, file, event.group_id)
logger.info(f'更新了cqhttp...{file}')
await lasted_gocqhttp.send(f'gocqhttp更新了,已上传成功!\n更新内容:\n{info}')
logger.info(f"更新了cqhttp...{file}")
await lasted_gocqhttp.send(f"gocqhttp更新了,已上传成功!\n更新内容:\n{info}")
except Exception as e:
logger.error(f'更新gocq错误 e:{e}')
logger.error(f"更新gocq错误 e:{e}")
_ulmt.set_False(event.group_id)
# 更新gocq
@scheduler.scheduled_job(
'cron',
"cron",
hour=3,
minute=1,
)
@@ -53,13 +53,14 @@ async def _():
bot = get_bot()
try:
info = await download_gocq_lasted(path)
if info == 'gocqhttp没有更新!':
logger.info('gocqhttp没有更新!')
if info == "gocqhttp没有更新!":
logger.info("gocqhttp没有更新!")
return
for group in UPDATE_GOCQ_GROUP:
for file in os.listdir(path):
await upload_gocq_lasted(path, file, group)
await bot.send_group_msg(group_id=group, message=f"gocqhttp更新了,已上传成功!\n更新内容:\n{info}")
await bot.send_group_msg(
group_id=group, message=f"gocqhttp更新了,已上传成功!\n更新内容:\n{info}"
)
except Exception as e:
logger.error(f'自动更新gocq出错 e:{e}')
logger.error(f"自动更新gocq出错 e:{e}")